* * 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 $resources; /** * Constructor * * @param string $path The album path * @param string $slug The album slug * @param string $title The album title */ public function __construct(private string $path, private string $slug, private string $title) { //Set defaults $this->created = new \DateTime('now'); $this->updated = new \DateTime('now'); //Set collections $this->resources = 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 title * * @param string $title * * @return Album */ public function setTitle(string $title): Album { $this->title = $title; return $this; } /** * Get title * * @return string */ public function getTitle(): string { return $this->title; } /** * 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 resource * * @param Resource $resource * * @return User */ public function addResource(Resource $resource): User { $this->resources[] = $resource; return $this; } /** * Remove resource * * @param Resource $resource * * @return \Doctrine\Common\Collections\Collection */ public function removeResource(Resource $resource): Collection { return $this->resources->removeElement($resource); } /** * Get resources * * @return \Doctrine\Common\Collections\Collection */ public function getResources(): Collection { return $this->resources; } /** * {@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')); } } }