]> Raphaël G. Git Repositories - treebundle/blobdiff - Entity/Element.php
Rename asset into element
[treebundle] / Entity / Element.php
diff --git a/Entity/Element.php b/Entity/Element.php
new file mode 100644 (file)
index 0000000..464c537
--- /dev/null
@@ -0,0 +1,176 @@
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys TreeBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * 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;
+
+/**
+ * Element
+ */
+class Element {
+       /**
+        * @var ?int
+        */
+       private ?int $id;
+
+       /**
+        * @var \DateTime
+        */
+       private \DateTime $created;
+
+       /**
+        * @var \DateTime
+        */
+       private \DateTime $updated;
+
+       /**
+        * Constructor
+        *
+        * @param ?string $path The element path
+        */
+       public function __construct(private Album $album, private User $user, private ?string $path = null) {
+               $this->created = new \DateTime('now');
+               $this->updated = new \DateTime('now');
+       }
+
+       /**
+        * Get id
+        *
+        * @return ?int
+        */
+       public function getId(): ?int {
+               return $this->id;
+       }
+
+       /**
+        * Set album
+        *
+        * @param \Rapsys\TreeBundle\Entity\Album $album
+        *
+        * @return Element
+        */
+       public function setAlbum(Album $album): Element {
+               $this->album = $album;
+
+               return $this;
+       }
+
+       /**
+        * Get album
+        *
+        * @return \Rapsys\TreeBundle\Entity\Album
+        */
+       public function getAlbum(): Album {
+               return $this->album;
+       }
+
+       /**
+        * Set user
+        *
+        * @param \Rapsys\TreeBundle\Entity\User $user
+        *
+        * @return Element
+        */
+       public function setUser(User $user): Element {
+               $this->user = $user;
+
+               return $this;
+       }
+
+       /**
+        * Get user
+        *
+        * @return \Rapsys\TreeBundle\Entity\User
+        */
+       public function getUser(): User {
+               return $this->user;
+       }
+
+       /**
+        * Set path
+        *
+        * @param ?string $path
+        *
+        * @return Element
+        */
+       public function setPath(?string $path): Element {
+               $this->path = $path;
+
+               return $this;
+       }
+
+       /**
+        * Get path
+        *
+        * @return ?string
+        */
+       public function getPath(): ?string {
+               return $this->path;
+       }
+
+       /**
+        * Set created
+        *
+        * @param \DateTime $created
+        *
+        * @return Element
+        */
+       public function setCreated(\DateTime $created): Element {
+               $this->created = $created;
+
+               return $this;
+       }
+
+       /**
+        * Get created
+        *
+        * @return \DateTime
+        */
+       public function getCreated(): \DateTime {
+               return $this->created;
+       }
+
+       /**
+        * Set updated
+        *
+        * @param \DateTime $updated
+        *
+        * @return Element
+        */
+       public function setUpdated(\DateTime $updated): Element {
+               $this->updated = $updated;
+
+               return $this;
+       }
+
+       /**
+        * Get updated
+        *
+        * @return \DateTime
+        */
+       public function getUpdated(): \DateTime {
+               return $this->updated;
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs): ?Element {
+               //Check that we have an snippet instance
+               if (($entity = $eventArgs->getEntity()) instanceof Element) {
+                       //Set updated value
+                       return $entity->setUpdated(new \DateTime('now'));
+               }
+       }
+}