]> Raphaël G. Git Repositories - treebundle/commitdiff
Add album reference
authorRaphaël Gertz <git@rapsys.eu>
Sat, 2 Nov 2024 04:00:39 +0000 (05:00 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Sat, 2 Nov 2024 04:00:39 +0000 (05:00 +0100)
Entity/Album.php [new file with mode: 0644]
config/doctrine/Album.orm.yml [new file with mode: 0644]

diff --git a/Entity/Album.php b/Entity/Album.php
new file mode 100644 (file)
index 0000000..0cf9b33
--- /dev/null
@@ -0,0 +1,220 @@
+<?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;
+
+/**
+ * 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 (file)
index 0000000..5f29f72
--- /dev/null
@@ -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']