X-Git-Url: https://git.rapsys.eu/treebundle/blobdiff_plain/399693f8abe63c3a13d403105bbed688a9274d3d..ae572224add15c0e615fa068ed80cc679bb95182:/Entity/Asset.php?ds=sidebyside diff --git a/Entity/Asset.php b/Entity/Asset.php new file mode 100644 index 0000000..666277d --- /dev/null +++ b/Entity/Asset.php @@ -0,0 +1,176 @@ + + * + * 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; + +/** + * Asset + */ +class Asset { + /** + * @var ?int + */ + private ?int $id; + + /** + * @var \DateTime + */ + private \DateTime $created; + + /** + * @var \DateTime + */ + private \DateTime $updated; + + /** + * Constructor + * + * @param ?string $path The asset 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 Asset + */ + public function setAlbum(Album $album): Asset { + $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 Asset + */ + public function setUser(User $user): Asset { + $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 Asset + */ + public function setPath(?string $path): Asset { + $this->path = $path; + + return $this; + } + + /** + * Get path + * + * @return ?string + */ + public function getPath(): ?string { + return $this->path; + } + + /** + * Set created + * + * @param \DateTime $created + * + * @return Asset + */ + public function setCreated(\DateTime $created): Asset { + $this->created = $created; + + return $this; + } + + /** + * Get created + * + * @return \DateTime + */ + public function getCreated(): \DateTime { + return $this->created; + } + + /** + * Set updated + * + * @param \DateTime $updated + * + * @return Asset + */ + public function setUpdated(\DateTime $updated): Asset { + $this->updated = $updated; + + return $this; + } + + /** + * Get updated + * + * @return \DateTime + */ + public function getUpdated(): \DateTime { + return $this->updated; + } + + /** + * {@inheritdoc} + */ + public function preUpdate(PreUpdateEventArgs $eventArgs): ?Asset { + //Check that we have an snippet instance + if (($entity = $eventArgs->getEntity()) instanceof Asset) { + //Set updated value + return $entity->setUpdated(new \DateTime('now')); + } + } +}