<?php
namespace App\AtechNet\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OrderBy;
use Doctrine\ORM\Mapping\Table as Table;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Album
*
* @Table(name="albums")
* @Entity(repositoryClass="App\AtechNet\CoreBundle\Repository\AlbumRepository")
* @HasLifecycleCallbacks
*/
class Album extends AbstractEntity
{
/**
* @var ArrayCollection
*
* @Assert\Valid
*
* @OneToMany(targetEntity="Photo", mappedBy="album", cascade={"persist", "remove"})
* @OrderBy({"sortIndex" = "ASC"})
*
**/
private $photos;
public function __construct()
{
parent::__construct();
$this->photos = new ArrayCollection();
}
/**
* Add Photo
*
* @param Photo $photo
* @return Album
*/
public function addPhoto($photo)
{
if (!$this->photos->contains($photo)) {
$this->photos->add($photo);
$photo->setAlbum($this);
}
return $this;
}
/**
* Remove Photo
*
* @param Photo $photo
* @return Album
*/
public function removePhoto($photo)
{
$this->photos->removeElement($photo);
return $this;
}
/**
* @return ArrayCollection
*/
public function getPhotos()
{
return $this->photos;
}
/**
* @param Number $index
* @return ArrayCollection
*/
public function getNthPhoto($index = 0)
{
return $this->photos[$index];
}
}