Pārlūkot izejas kodu

minor fixes on ResourceTrees

Olivier Massot 2 mēneši atpakaļ
vecāks
revīzija
d289437ac0

+ 1 - 1
config/opentalent/products.yaml

@@ -12,6 +12,7 @@ parameters:
           - Upload
           - Upload
           - Download
           - Download
           - GpsCoordinate
           - GpsCoordinate
+          - TypeOfPracticeTree
       Freemium:
       Freemium:
         resources:
         resources:
           - FreemiumOrganization
           - FreemiumOrganization
@@ -36,7 +37,6 @@ parameters:
           - SubdomainAvailability
           - SubdomainAvailability
           - UserSearchItem
           - UserSearchItem
           - DolibarrDocDownload
           - DolibarrDocDownload
-          - TypeOfPracticeTree
         roles:
         roles:
           - ROLE_IMPORT
           - ROLE_IMPORT
           - ROLE_TAGG
           - ROLE_TAGG

+ 18 - 0
src/ApiResources/Tree/TypeOfPracticeTree.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 
 namespace App\ApiResources\Tree;
 namespace App\ApiResources\Tree;
 
 
+use ApiPlatform\Metadata\ApiProperty;
 use ApiPlatform\Metadata\ApiResource;
 use ApiPlatform\Metadata\ApiResource;
 use ApiPlatform\Metadata\Get;
 use ApiPlatform\Metadata\Get;
 use App\Service\Utils\Tree\BaseResourceTree;
 use App\Service\Utils\Tree\BaseResourceTree;
@@ -20,4 +21,21 @@ use App\State\Provider\Tree\TypeOfPracticeTreeProvider;
 )]
 )]
 class TypeOfPracticeTree extends BaseResourceTree implements ResourceTreeInterface
 class TypeOfPracticeTree extends BaseResourceTree implements ResourceTreeInterface
 {
 {
+    /**
+     * Id 'bidon' ajouté par défaut pour permettre la construction
+     * de l'IRI par api platform.
+     */
+    #[ApiProperty(identifier: true)]
+    private int $id = 1;
+
+    public function getId(): int
+    {
+        return $this->id;
+    }
+
+    public function setId(int $id): self
+    {
+        $this->id = $id;
+        return $this;
+    }
 }
 }

+ 39 - 0
src/Service/ApiResourceBuilder/ResourceTree/EventCategoryTreeBuilder.php

@@ -0,0 +1,39 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Service\ApiResourceBuilder\ResourceTree;
+
+use App\ApiResources\Tree\TypeOfPracticeTree;
+use App\Entity\Organization\TypeOfPractice;
+use App\Service\Utils\Tree\ResourceTreeBuilder;
+use Doctrine\ORM\EntityManagerInterface;
+
+
+/**
+ *
+ */
+class EventCategoryTreeBuilder
+{
+    public function __construct(
+        private readonly EntityManagerInterface $entityManager,
+    ) {
+    }
+
+    public function make(): TypeOfPracticeTree
+    {
+        $typeOfPracticesRepository = $this->entityManager->getRepository(TypeOfPractice::class);
+
+        $typeOfPractices = $typeOfPracticesRepository->findAll();
+
+        $tree = ResourceTreeBuilder::makeTree(
+            $typeOfPractices,
+            'category',
+            'name'
+        );
+
+        $treeResource = new TypeOfPracticeTree();
+        $treeResource->setContent($tree);
+
+        return $treeResource;
+    }
+}