X-Git-Url: https://git.rapsys.eu/treebundle/blobdiff_plain/85da4296f5f945c4db6d552048ed7423eadb6f02..bc23d7a89281c97e385b252c02de5f117f72b5a3:/Entity/Resource.php diff --git a/Entity/Resource.php b/Entity/Resource.php new file mode 100644 index 0000000..8c10d23 --- /dev/null +++ b/Entity/Resource.php @@ -0,0 +1,154 @@ + + * + * 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; + +/** + * Resource + */ +class Resource { + /** + * @var int + */ + private ?int $id; + + /** + * @var \DateTime + */ + private \DateTime $created; + + /** + * @var \DateTime + */ + private \DateTime $updated; + + /** + * Constructor + * + * @param string $path The resource path + */ + public function __construct(private User $user, private string $path) { + $this->created = new \DateTime('now'); + $this->updated = new \DateTime('now'); + } + + /** + * Get id + * + * @return ?int + */ + public function getId(): ?int { + return $this->id; + } + + /** + * Set user + * + * @param \Rapsys\BlogBundle\Entity\User $user + * + * @return Resource + */ + public function setUser(User $user): Resource { + $this->user = $user; + + return $this; + } + + /** + * Get user + * + * @return \Rapsys\BlogBundle\Entity\User + */ + public function getUser(): User { + return $this->user; + } + + /** + * Set path + * + * @param string $path + * + * @return Resource + */ + public function setPath(string $path): Resource { + $this->path = $path; + + return $this; + } + + /** + * Get path + * + * @return string + */ + public function getPath(): string { + return $this->path; + } + + /** + * Set created + * + * @param \DateTime $created + * + * @return Resource + */ + public function setCreated(\DateTime $created): Resource { + $this->created = $created; + + return $this; + } + + /** + * Get created + * + * @return \DateTime + */ + public function getCreated(): \DateTime { + return $this->created; + } + + /** + * Set updated + * + * @param \DateTime $updated + * + * @return Resource + */ + public function setUpdated(\DateTime $updated): Resource { + $this->updated = $updated; + + return $this; + } + + /** + * Get updated + * + * @return \DateTime + */ + public function getUpdated(): \DateTime { + return $this->updated; + } + + /** + * {@inheritdoc} + */ + public function preUpdate(PreUpdateEventArgs $eventArgs): ?Resource { + //Check that we have an snippet instance + if (($entity = $eventArgs->getEntity()) instanceof Resource) { + //Set updated value + return $entity->setUpdated(new \DateTime('now')); + } + } +}