* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Rapsys\TreeBundle\Entity; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\PreUpdateEventArgs; /** * Album */ class Album { /** * @var int */ private ?int $id; /** * @var \DateTime */ private \DateTime $created; /** * @var \DateTime */ private \DateTime $updated; /** * @var \Doctrine\Common\Collections\Collection */ private Collection $assets; /** * Constructor * * @param string $path The album path * @param string $slug The album slug */ public function __construct(private string $path, private string $slug) { //Set defaults $this->created = new \DateTime('now'); $this->updated = new \DateTime('now'); //Set collections $this->assets = new ArrayCollection(); } /** * Get id * * @return ?int */ public function getId(): ?int { return $this->id; } /** * Set path * * @param string $path * * @return Album */ public function setPath(string $path): Album { $this->path = $path; return $this; } /** * Get path * * @return string */ public function getPath(): string { return $this->path; } /** * Set slug * * @param string $slug * * @return Album */ public function setSlug(string $slug): Album { $this->slug = $slug; return $this; } /** * Get slug * * @return string */ public function getSlug(): string { return $this->slug; } /** * Set created * * @param \DateTime $created * * @return Album */ public function setCreated(\DateTime $created): Album { $this->created = $created; return $this; } /** * Get created * * @return \DateTime */ public function getCreated(): \DateTime { return $this->created; } /** * Set updated * * @param \DateTime $updated * * @return Album */ public function setUpdated(\DateTime $updated): Album { $this->updated = $updated; return $this; } /** * Get updated * * @return \DateTime */ public function getUpdated(): \DateTime { return $this->updated; } /** * Add asset * * @param Asset $asset * * @return User */ public function addAsset(Asset $asset): User { $this->assets[] = $asset; return $this; } /** * Remove asset * * @param Asset $asset * * @return \Doctrine\Common\Collections\Collection */ public function removeAsset(Asset $asset): Collection { return $this->assets->removeElement($asset); } /** * Get assets * * @return \Doctrine\Common\Collections\Collection */ public function getAssets(): Collection { return $this->assets; } /** * {@inheritdoc} */ public function preUpdate(PreUpdateEventArgs $eventArgs): ?Album { //Check that we have an snippet instance if (($entity = $eventArgs->getEntity()) instanceof Album) { //Set updated value return $entity->setUpdated(new \DateTime('now')); } } }