1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys TreeBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\TreeBundle\Entity
;
14 use Doctrine\Common\Collections\Collection
;
15 use Doctrine\Common\Collections\ArrayCollection
;
16 use Doctrine\ORM\Event\PreUpdateEventArgs
;
30 private \DateTime
$created;
35 private \DateTime
$updated;
38 * @var \Doctrine\Common\Collections\Collection
40 private Collection
$elements;
45 * @param string $path The album path
46 * @param string $slug The album slug
48 public function __construct(private string $path, private string $slug) {
50 $this->created
= new \
DateTime('now');
51 $this->updated
= new \
DateTime('now');
54 $this->elements
= new ArrayCollection();
62 public function getId(): ?int {
73 public function setPath(string $path): Album
{
84 public function getPath(): string {
95 public function setSlug(string $slug): Album
{
106 public function getSlug(): string {
113 * @param \DateTime $created
117 public function setCreated(\DateTime
$created): Album
{
118 $this->created
= $created;
128 public function getCreated(): \DateTime
{
129 return $this->created
;
135 * @param \DateTime $updated
139 public function setUpdated(\DateTime
$updated): Album
{
140 $this->updated
= $updated;
150 public function getUpdated(): \DateTime
{
151 return $this->updated
;
157 * @param Element $element
161 public function addElement(Element
$element): User
{
162 $this->elements
[] = $element;
170 * @param Element $element
172 * @return \Doctrine\Common\Collections\Collection
174 public function removeElement(Element
$element): Collection
{
175 return $this->elements
->removeElement($element);
181 * @return \Doctrine\Common\Collections\Collection
183 public function getElements(): Collection
{
184 return $this->elements
;
190 public function preUpdate(PreUpdateEventArgs
$eventArgs): ?Album
{
191 //Check that we have an snippet instance
192 if (($entity = $eventArgs->getEntity()) instanceof Album
) {
194 return $entity->setUpdated(new \
DateTime('now'));