]> Raphaël G. Git Repositories - treebundle/commitdiff
Rename asset into element
authorRaphaël Gertz <git@rapsys.eu>
Tue, 5 Nov 2024 00:24:33 +0000 (01:24 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Tue, 5 Nov 2024 00:24:33 +0000 (01:24 +0100)
Entity/Album.php
Entity/Element.php [moved from Entity/Asset.php with 80% similarity]
Entity/User.php
Repository.php
Repository/AlbumRepository.php
config/doctrine/Album.orm.yml
config/doctrine/Element.orm.yml [moved from config/doctrine/Asset.orm.yml with 78% similarity]
config/doctrine/User.orm.yml
config/routes/rapsystree.yaml
templates/index.html.twig

index 9177b1022d3b600054b14e40ab7659a6611acec3..0a812f88e799bd7f3c80ea4a799daf1bb58238cd 100644 (file)
@@ -37,7 +37,7 @@ class Album {
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
-       private Collection $assets;
+       private Collection $elements;
 
        /**
         * Constructor
@@ -51,7 +51,7 @@ class Album {
                $this->updated = new \DateTime('now');
 
                //Set collections
-               $this->assets = new ArrayCollection();
+               $this->elements = new ArrayCollection();
        }
 
        /**
@@ -152,36 +152,36 @@ class Album {
        }
 
        /**
-        * Add asset
+        * Add element
         *
-        * @param Asset $asset
+        * @param Element $element
         *
         * @return User
         */
-       public function addAsset(Asset $asset): User {
-               $this->assets[] = $asset;
+       public function addElement(Element $element): User {
+               $this->elements[] = $element;
 
                return $this;
        }
 
        /**
-        * Remove asset
+        * Remove element
         *
-        * @param Asset $asset
+        * @param Element $element
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function removeAsset(Asset $asset): Collection {
-               return $this->assets->removeElement($asset);
+       public function removeElement(Element $element): Collection {
+               return $this->elements->removeElement($element);
        }
 
        /**
-        * Get assets
+        * Get elements
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function getAssets(): Collection {
-               return $this->assets;
+       public function getElements(): Collection {
+               return $this->elements;
        }
 
        /**
similarity index 80%
rename from Entity/Asset.php
rename to Entity/Element.php
index 666277d7bdf89a3fa264e7e82b263b96b0724e7e..464c5378fbf3a7775d852082b9d8b4e16e7a9aee 100644 (file)
@@ -16,9 +16,9 @@ use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Event\PreUpdateEventArgs;
 
 /**
- * Asset
+ * Element
  */
-class Asset {
+class Element {
        /**
         * @var ?int
         */
@@ -37,7 +37,7 @@ class Asset {
        /**
         * Constructor
         *
-        * @param ?string $path The asset path
+        * @param ?string $path The element path
         */
        public function __construct(private Album $album, private User $user, private ?string $path = null) {
                $this->created = new \DateTime('now');
@@ -58,9 +58,9 @@ class Asset {
         *
         * @param \Rapsys\TreeBundle\Entity\Album $album
         *
-        * @return Asset
+        * @return Element
         */
-       public function setAlbum(Album $album): Asset {
+       public function setAlbum(Album $album): Element {
                $this->album = $album;
 
                return $this;
@@ -80,9 +80,9 @@ class Asset {
         *
         * @param \Rapsys\TreeBundle\Entity\User $user
         *
-        * @return Asset
+        * @return Element
         */
-       public function setUser(User $user): Asset {
+       public function setUser(User $user): Element {
                $this->user = $user;
 
                return $this;
@@ -102,9 +102,9 @@ class Asset {
         *
         * @param ?string $path
         *
-        * @return Asset
+        * @return Element
         */
-       public function setPath(?string $path): Asset {
+       public function setPath(?string $path): Element {
                $this->path = $path;
 
                return $this;
@@ -124,9 +124,9 @@ class Asset {
         *
         * @param \DateTime $created
         *
-        * @return Asset
+        * @return Element
         */
-       public function setCreated(\DateTime $created): Asset {
+       public function setCreated(\DateTime $created): Element {
                $this->created = $created;
 
                return $this;
@@ -146,9 +146,9 @@ class Asset {
         *
         * @param \DateTime $updated
         *
-        * @return Asset
+        * @return Element
         */
-       public function setUpdated(\DateTime $updated): Asset {
+       public function setUpdated(\DateTime $updated): Element {
                $this->updated = $updated;
 
                return $this;
@@ -166,9 +166,9 @@ class Asset {
        /**
         * {@inheritdoc}
         */
-       public function preUpdate(PreUpdateEventArgs $eventArgs): ?Asset {
+       public function preUpdate(PreUpdateEventArgs $eventArgs): ?Element {
                //Check that we have an snippet instance
-               if (($entity = $eventArgs->getEntity()) instanceof Asset) {
+               if (($entity = $eventArgs->getEntity()) instanceof Element) {
                        //Set updated value
                        return $entity->setUpdated(new \DateTime('now'));
                }
index cabdde55320c292c5e5e5208b7009133891110a2..4c4ea57833c00edffe196e00116f0e332f0c869b 100644 (file)
@@ -23,7 +23,7 @@ class User extends BaseUser {
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
-       private Collection $assets;
+       private Collection $elements;
 
        /**
         * Constructor
@@ -45,39 +45,39 @@ class User extends BaseUser {
                //Set defaults
 
                //Set collections
-               $this->assets = new ArrayCollection();
+               $this->elements = new ArrayCollection();
        }
 
        /**
-        * Add asset
+        * Add element
         *
-        * @param Asset $asset
+        * @param Element $element
         *
         * @return User
         */
-       public function addAsset(Asset $asset): User {
-               $this->assets[] = $asset;
+       public function addElement(Element $element): User {
+               $this->elements[] = $element;
 
                return $this;
        }
 
        /**
-        * Remove asset
+        * Remove element
         *
-        * @param Asset $asset
+        * @param Element $element
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function removeAsset(Asset $asset): Collection {
-               return $this->assets->removeElement($asset);
+       public function removeElement(Element $element): Collection {
+               return $this->elements->removeElement($element);
        }
 
        /**
-        * Get assets
+        * Get elements
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function getAssets(): Collection {
-               return $this->assets;
+       public function getElements(): Collection {
+               return $this->elements;
        }
 }
index b60959fd108e2d3a5ecf2e9def3079b76b85d546..6caf70d32fa34b3f5764ddb4827d203992fc92da 100644 (file)
@@ -69,8 +69,8 @@ class Repository extends EntityRepository {
                $tables = [
                        'Rapsys\TreeBundle\Entity\UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp),
                        'Rapsys\TreeBundle\Entity\Album' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Album'), $dp),
-                       'Rapsys\TreeBundle\Entity\Asset' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Asset'), $dp),
                        'Rapsys\TreeBundle\Entity\Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Civility'), $dp),
+                       'Rapsys\TreeBundle\Entity\Element' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Element'), $dp),
                        'Rapsys\TreeBundle\Entity\Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Group'), $dp),
                        'Rapsys\TreeBundle\Entity\User' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp),
                        //Set locale
index c1901d92f89b76a3808128b127368dd2143d656c..e56ae8a1e269683abd69b6ce9a0f67c919e9e226 100644 (file)
@@ -42,7 +42,7 @@ SQL;
                //Set the request
                $req = <<<SQL
 SELECT COUNT(DISTINCT a.album_id) AS count
-FROM Rapsys\TreeBundle\Entity\Asset AS a
+FROM Rapsys\TreeBundle\Entity\Element AS a
 WHERE $userSql
 SQL;
 
@@ -76,14 +76,14 @@ SQL;
        public function findAllAsArray(?int $id, int $page, int $count): array {
                //Set user sql
                $userSql = <<<SQL
-s.user_id = :id
+e.user_id = :id
 SQL;
 
                //With null id
                if ($id === null) {
                        //Set user sql
                        $userSql = <<<SQL
-s.user_id IS NULL
+e.user_id IS NULL
 SQL;
                }
 
@@ -92,14 +92,14 @@ SQL;
 SELECT
        a.id,
        a.path,
-       GROUP_CONCAT(s.id ORDER BY s.id SEPARATOR "\\n") AS s_ids,
-       GROUP_CONCAT(IFNULL(s.path, '/') ORDER BY s.id SEPARATOR "\\n") AS s_paths,
+       GROUP_CONCAT(e.id ORDER BY e.id SEPARATOR "\\n") AS s_ids,
+       GROUP_CONCAT(IFNULL(e.path, '/') ORDER BY e.id SEPARATOR "\\n") AS s_paths,
        a.slug,
-       GREATEST(a.created, s.created) AS created,
-       GREATEST(a.updated, s.updated) AS updated,
-       GREATEST(a.created, s.created, a.updated, s.updated) AS modified
+       GREATEST(a.created, e.created) AS created,
+       GREATEST(a.updated, e.updated) AS updated,
+       GREATEST(a.created, e.created, a.updated, e.updated) AS modified
 FROM Rapsys\TreeBundle\Entity\Album AS a
-JOIN Rapsys\TreeBundle\Entity\Asset AS s ON (s.album_id = a.id AND {$userSql})
+JOIN Rapsys\TreeBundle\Entity\Element AS e ON (e.album_id = a.id AND {$userSql})
 GROUP BY a.id
 ORDER BY updated, created DESC, a.id
 LIMIT :offset, :count
@@ -146,20 +146,20 @@ SQL;
                                'updated' => $data['updated'],
                                'modified' => $data['modified'],
                                'link' => $this->router->generate('rapsystree_album', ['id' => $id, 'slug' => $slug, 'path' => '/']),
-                               'assets' => []
+                               'elements' => []
                        ];
 
-                       //Explode asset ids
+                       //Explode element ids
                        $data['s_ids'] = explode("\n", $data['s_ids']);
 
-                       //Explode asset paths
+                       //Explode element paths
                        $data['s_paths'] = explode("\n", $data['s_paths']);
 
                        foreach($data['s_ids'] as $s => $id) {
-                               $return[$data['id']]['assets'][$id] = [
+                               $return[$data['id']]['elements'][$id] = [
                                        'id' => $id,
                                        'path' => $path = $data['s_paths'][$s],
-                                       'link' => $this->router->generate('rapsystree_asset', ['id' => $id, 'path' => $path]),
+                                       'link' => $this->router->generate('rapsystree_element', ['id' => $id, 'path' => $path]),
                                ];
                        }
                }
index 05cbd62e3beca7f098e30531aef3eda00b726456..54659b02645c10b7905a2237fb7818149e82a500 100644 (file)
@@ -25,8 +25,8 @@ Rapsys\TreeBundle\Entity\Album:
         updated:
             type: datetime
     oneToMany:
-        assets:
-            targetEntity: Rapsys\TreeBundle\Entity\Asset
+        elements:
+            targetEntity: Rapsys\TreeBundle\Entity\Element
             mappedBy: album
     lifecycleCallbacks:
         preUpdate: ['preUpdate']
similarity index 78%
rename from config/doctrine/Asset.orm.yml
rename to config/doctrine/Element.orm.yml
index 0147e90289cd8904bb5a9536fbc1f488fa2c2163..bfd9d7ba6844132023326557cec72b43a7b82221 100644 (file)
@@ -1,7 +1,7 @@
-Rapsys\TreeBundle\Entity\Asset:
+Rapsys\TreeBundle\Entity\Element:
     type: entity
-    #repositoryClass: Rapsys\TreeBundle\Repository\AssetRepository
-    table: assets
+    #repositoryClass: Rapsys\TreeBundle\Repository\ElementRepository
+    table: elements
     id:
         id:
             type: integer
@@ -21,10 +21,10 @@ Rapsys\TreeBundle\Entity\Asset:
     manyToOne:
         album:
             targetEntity: Rapsys\TreeBundle\Entity\Album
-            inversedBy: assets
+            inversedBy: elements
         user:
             targetEntity: Rapsys\TreeBundle\Entity\User
-            inversedBy: assets
+            inversedBy: elements
     uniqueConstraints:
         album_user_path:
             columns: [ album_id, user_id, path ]
index d57abeb61d1992884976796c71a602e81e762213..af4250f7a9b6d9213d74cab0c473ea3ad2f4115e 100644 (file)
@@ -13,8 +13,8 @@ Rapsys\TreeBundle\Entity\User:
 #            unique: true
 #            nullable: true
     oneToMany:
-        assets:
-            targetEntity: Rapsys\TreeBundle\Entity\Asset
+        elements:
+            targetEntity: Rapsys\TreeBundle\Entity\Element
             mappedBy: user
 #    manyToMany:
 #        groups:
index 03d85ead5eb67f690db7062e9ab6c3fe65720b95..d52b99863f94a1afa4e951b89f15bea36f456270 100644 (file)
@@ -28,19 +28,6 @@ rapsystree_album:
         slug: '[\w-]+'
     methods: GET|POST
 
-rapsystree_asset:
-    path:
-        en_gb: '/en/asset/{id}{path}'
-        fr_fr: '/actif/{id}{path}'
-    controller: Rapsys\TreeBundle\Controller\TreeController::asset
-    defaults:
-        id: ~
-        path: ~
-    requirements:
-        id: '\d+'
-        path: '/.*'
-    methods: GET|POST
-
 rapsystree_contact:
     path:
         en_gb: '/en/contact'
@@ -75,6 +62,19 @@ rapsysuser_edit:
         hash: '[a-zA-Z0-9=_-]+'
     methods: GET|POST
 
+rapsystree_element:
+    path:
+        en_gb: '/en/element/{id}{path}'
+        fr_fr: '/element/{id}{path}'
+    controller: Rapsys\TreeBundle\Controller\TreeController::element
+    defaults:
+        id: ~
+        path: ~
+    requirements:
+        id: '\d+'
+        path: '/.*'
+    methods: GET|POST
+
 rapsysuser_index:
     path:
         en_gb: '/en/user'
index 0c95ed56b026b0f3e3564d940c809df4385984d1..68daf1b02b92467d420ffbe57bca6961470ba1a6 100644 (file)
@@ -4,13 +4,13 @@
                {% for id, album in albums %}
                        <article>
                                <header>
-                                       <h2><a href="{{ album.link }}">{{ album.slug }}</a></h2>
+                                       <h2><a href="{{ album.link }}">{{ album.slug|capitalize }}</a></h2>
                                </header>
-                               {% if album.assets is defined and album.assets %}
-                                       {% for id, asset in album.assets %}
+                               {% if album.elements is defined and album.elements %}
+                                       {% for id, element in album.elements %}
                                                <section>
                                                        <header>
-                                                               <h3><a href="{{ asset.link }}">{{ asset.path }}</a></h3>
+                                                               <h3><a href="{{ element.link }}">{{ element.path }}</a></h3>
                                                        </header>
                                                        <p>
                                                                TODO: miniature if target is a file or image list when directory ?