src/AtechNet/CoreBundle/Entity/Album.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping\Entity;
  5. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  6. use Doctrine\ORM\Mapping\OneToMany;
  7. use Doctrine\ORM\Mapping\OrderBy;
  8. use Doctrine\ORM\Mapping\Table as Table;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * Album
  12.  *
  13.  * @Table(name="albums")
  14.  * @Entity(repositoryClass="App\AtechNet\CoreBundle\Repository\AlbumRepository")
  15.  * @HasLifecycleCallbacks
  16.  */
  17. class Album extends AbstractEntity
  18. {
  19.     /**
  20.      * @var ArrayCollection
  21.      *
  22.      * @Assert\Valid
  23.      *
  24.      * @OneToMany(targetEntity="Photo", mappedBy="album", cascade={"persist", "remove"})
  25.      * @OrderBy({"sortIndex" = "ASC"})
  26.      *
  27.      **/
  28.     private $photos;
  29.     public function __construct()
  30.     {
  31.         parent::__construct();
  32.         $this->photos = new ArrayCollection();
  33.     }
  34.     /**
  35.      * Add Photo
  36.      *
  37.      * @param Photo $photo
  38.      * @return Album
  39.      */
  40.     public function addPhoto($photo)
  41.     {
  42.         if (!$this->photos->contains($photo)) {
  43.             $this->photos->add($photo);
  44.             $photo->setAlbum($this);
  45.         }
  46.         return $this;
  47.     }
  48.     /**
  49.      * Remove Photo
  50.      *
  51.      * @param Photo $photo
  52.      * @return Album
  53.      */
  54.     public function removePhoto($photo)
  55.     {
  56.         $this->photos->removeElement($photo);
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return ArrayCollection
  61.      */
  62.     public function getPhotos()
  63.     {
  64.         return $this->photos;
  65.     }
  66.     /**
  67.      * @param Number $index
  68.      * @return ArrayCollection
  69.      */
  70.     public function getNthPhoto($index = 0)
  71.     {
  72.         return $this->photos[$index];
  73.     }
  74. }