From 0315ccbb69b5a24a5a073f7b3da82a062e62825c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sat, 2 Nov 2024 05:00:39 +0100 Subject: [PATCH 1/1] Add album reference --- Entity/Album.php | 220 ++++++++++++++++++++++++++++++++++ config/doctrine/Album.orm.yml | 35 ++++++ 2 files changed, 255 insertions(+) create mode 100644 Entity/Album.php create mode 100644 config/doctrine/Album.orm.yml diff --git a/Entity/Album.php b/Entity/Album.php new file mode 100644 index 0000000..0cf9b33 --- /dev/null +++ b/Entity/Album.php @@ -0,0 +1,220 @@ + + * + * 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')); + } + } +} diff --git a/config/doctrine/Album.orm.yml b/config/doctrine/Album.orm.yml new file mode 100644 index 0000000..5f29f72 --- /dev/null +++ b/config/doctrine/Album.orm.yml @@ -0,0 +1,35 @@ +Rapsys\TreeBundle\Entity\Album: + type: entity + #repositoryClass: Rapsys\TreeBundle\Repository\AlbumRepository + table: albums + id: + id: + type: integer + generator: + strategy: AUTO + options: + unsigned: true + fields: + path: + type: string + length: 4096 + nullable: true + title: + type: string + length: 64 + nullable: true + slug: + type: string + length: 64 + unique: true + nullable: true + created: + type: datetime + updated: + type: datetime + oneToMany: + resources: + targetEntity: Rapsys\TreeBundle\Entity\Resource + mappedBy: album + lifecycleCallbacks: + preUpdate: ['preUpdate'] -- 2.41.1