Prechádzať zdrojové kódy

create the FederationStructure entity

Olivier Massot 3 rokov pred
rodič
commit
ef9d240234

+ 0 - 0
sql/schema-extensions/001-view_portail_events.sql → sql/schema-extensions/001-view_public_events.sql


+ 34 - 0
sql/schema-extensions/002-view_federation_structures.sql

@@ -0,0 +1,34 @@
+CREATE OR REPLACE VIEW view_federation_structures
+AS
+    SELECT o.id, o.name, o.logo_id as logoId, o.description, o.image_id as imageId, o.principalType, p.otherWebsite as website, a.latitude, a.longitude,
+           CONCAT('[', GROUP_CONCAT(COLUMN_JSON(COLUMN_CREATE(
+                   'type', oa.type, 'latitude', a.latitude, 'longitude', a.longitude,
+                   'streetAddress', TRIM(BOTH '\n' FROM CONCAT_WS('\n', a.streetAddress, a.streetAddressSecond, a.streetAddressThird)),
+                   'postalCode', a.postalCode, 'addressCity', a.addressCity, 'country', c.name))), ']') as addresses,
+           cp.telphone as phone, cp.mobilPhone as mobilePhone, cp.email, o.facebook, o.twitter, o.instagram, o.youtube,
+           (SELECT CONCAT(GROUP_CONCAT(DISTINCT CONCAT(tp.name)))
+            FROM organization_type_of_practices AS otp
+                     LEFT JOIN TypeOfPractice AS tp ON(tp.id = otp.typeofpractice_id)
+            WHERE otp.organization_id = o.id) AS practices,
+           oar.articles,
+           n1.parent_id as n1Id, net1.name as n1Name, n2.parent_id as n2Id, n3.parent_id as n3Id, n4.parent_id as n4Id, n5.parent_id as n5Id,
+           CONCAT_WS(',', n1.parent_id, n2.parent_id, n3.parent_id, n4.parent_id, n5.parent_id) as parents
+    FROM opentalent.Organization o
+             INNER JOIN opentalent.Parameters p on o.parameters_id = p.id
+             LEFT JOIN opentalent.OrganizationAddressPostal oa on oa.organization_id = o.id
+             LEFT JOIN opentalent.AddressPostal a on oa.addressPostal_id = a.id
+             LEFT JOIN opentalent.Country c ON (c.id = a.addressCountry_id)
+             LEFT JOIN opentalent.organization_contactpoint ocp ON ocp.organization_id = o.id
+             INNER JOIN (SELECT * FROM opentalent.ContactPoint WHERE `contactType`='PRINCIPAL') cp ON cp.id = ocp.contactPoint_id
+             LEFT JOIN (
+                SELECT oar_.organization_id, CONCAT('[', GROUP_CONCAT(COLUMN_JSON(COLUMN_CREATE('id', oar_.id, 'title', oar_.title, 'date', DATE_FORMAT(oar_.date, '%Y-%m-%dT%TZ'), 'link', oar_.link))), ']') as articles
+                FROM (SELECT * FROM OrganizationArticle WHERE link is not null and link != '' ORDER BY date DESC) as oar_
+                group by organization_id
+             ) oar ON oar.organization_id = o.id
+             INNER JOIN (SELECT DISTINCT organization_id, parent_id FROM NetworkOrganization WHERE parent_id NOT IN (32366, 13) AND (endDate IS NULL OR endDate = '0000-00-00')) n1 on n1.organization_id = o.id
+             INNER JOIN Organization net1 ON net1.id = n1.parent_id
+             LEFT JOIN (SELECT DISTINCT organization_id, parent_id FROM NetworkOrganization WHERE parent_id NOT IN (32366, 13) AND (endDate IS NULL OR endDate = '0000-00-00')) n2 on n2.organization_id = n1.parent_id
+             LEFT JOIN (SELECT DISTINCT organization_id, parent_id FROM NetworkOrganization WHERE parent_id NOT IN (32366, 13) AND (endDate IS NULL OR endDate = '0000-00-00')) n3 on n3.organization_id = n2.parent_id
+             LEFT JOIN (SELECT DISTINCT organization_id, parent_id FROM NetworkOrganization WHERE parent_id NOT IN (32366, 13) AND (endDate IS NULL OR endDate = '0000-00-00')) n4 on n4.organization_id = n3.parent_id
+             LEFT JOIN (SELECT DISTINCT organization_id, parent_id FROM NetworkOrganization WHERE parent_id NOT IN (32366, 13) AND (endDate IS NULL OR endDate = '0000-00-00')) n5 on n5.organization_id = n4.parent_id
+    GROUP BY o.id;

+ 0 - 44
src/DataProvider/Public/FederationStructureDataProvider.php

@@ -1,44 +0,0 @@
-<?php
-
-namespace App\DataProvider\Public;
-
-use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
-use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
-use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
-use App\ApiResources\Public\FederationStructure;
-use App\Repository\Organization\OrganizationRepository;
-use Doctrine\Common\Collections\ArrayCollection;
-use Symfony\Component\HttpFoundation\RequestStack;
-
-
-class FederationStructureDataProvider implements ItemDataProviderInterface, CollectionDataProviderInterface, RestrictedDataProviderInterface
-{
-    public function __construct(
-        private RequestStack $requestStack,
-        private OrganizationRepository $organizationRepository
-    ) {}
-
-    public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
-    {
-        return FederationStructure::class === $resourceClass;
-    }
-
-    public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?FederationStructure
-    {
-        return $this->organizationRepository->getFederationStructureByOrganizationId($id);
-    }
-
-    public function getCollection(string $resourceClass, string $operationName = null): ArrayCollection
-    {
-        $request = $this->requestStack->getCurrentRequest();
-        if ($request === null) {
-            throw new \RuntimeException('Undefined request');
-        }
-        $parentId = $request->query->get('parent');
-        if (empty($parentId) || !is_numeric($parentId)) {
-            throw new \RuntimeException('Bad or missing parent value');
-        }
-
-        return new ArrayCollection($this->organizationRepository->getChildrenStructuresByFederationId($parentId));
-    }
-}

+ 96 - 37
src/ApiResources/Public/FederationStructure.php → src/Entity/Public/FederationStructure.php

@@ -1,84 +1,143 @@
 <?php
 declare(strict_types=1);
 
-namespace App\ApiResources\Public;
+namespace App\Entity\Public;
 
-use ApiPlatform\Core\Annotation\ApiProperty;
 use ApiPlatform\Core\Annotation\ApiResource;
-use App\ApiResources\ApiResourcesInterface;
+use App\Repository\Public\FederationStructureRepository;
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Serializer\Annotation\Groups;
 
 /**
  * Structure telle qu'elle est représentée sur l'iframe de recherche des structures d'une fédération
+ *
+ * Fichier source de la view : ./sql/schema-extensions/002-view_federation_structures.sql
  */
+#[ORM\Entity(repositoryClass: FederationStructureRepository::class, readOnly: true)]
+#[ORM\Table(name: "view_federation_structures")]
 #[ApiResource(
     collectionOperations: [
         'get' => [
             'method' => 'GET',
-            'path' => '/public/federation_structures' // required query : '?parent={\d+}'
+            'path' => '/public/federation_structures', // required query : '?parent={\d+}'
+            'normalization_context' => ['groups' => ['federation_structure_collection_get']],
         ]
     ],
     itemOperations: [
         'get' => [
             'method' => 'GET',
             'path' => '/public/federation_structures/{id}',
-            'requirements' => ['id' => '\d+']
+            'requirements' => ['id' => '\d+'],
+            'normalization_context' => ['groups' => ['federation_structure_item_get']]
         ]
     ]
 )]
-class FederationStructure implements ApiResourcesInterface
+class FederationStructure
 {
-    #[ApiProperty(identifier: true)]
+    #[ORM\Id]
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
     private int $id;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
     private ?string $name;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
     private ?int $logoId;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
     private ?string $description;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_item_get"])]
     private ?int $imageId;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
     private ?string $principalType;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
     private ?string $website;
 
-    private string $addresses;
+    #[ORM\Column(type: 'json')]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
+    private array $addresses;
 
-    private ?string $telphone;
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
+    private ?string $phone;
 
-    private ?string $mobilPhone;
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
+    private ?string $mobilePhone;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
     private ?string $email;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
     private ?string $facebook;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
     private ?string $twitter;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
     private ?string $instagram;
 
+    #[ORM\Column]
+    #[Groups(["federation_structure_item_get"])]
     private ?string $youtube;
 
+    #[ORM\Column(type: 'json')]
+    #[Groups(["federation_structure_item_get"])]
     private ?array $articles;
 
-    private ?string $practices;
+    #[ORM\Column(type: 'simple_array')]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
+    private ?array $practices;
 
+    #[ORM\Column(type: 'float')]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
     private ?float $latitude;
 
+    #[ORM\Column(type: 'float')]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
     private ?float $longitude;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_item_get"])]
     private ?int $n1Id;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_item_get"])]
     private ?string $n1Name;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_collection_get"])]
     private ?int $n2Id;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_collection_get"])]
     private ?int $n3Id;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_collection_get"])]
     private ?int $n4Id;
 
+    #[ORM\Column(type: 'integer')]
+    #[Groups(["federation_structure_collection_get"])]
     private ?int $n5Id;
 
-    private ?string $parents;
+    #[ORM\Column(type: 'simple_array')]
+    #[Groups(["federation_structure_item_get", "federation_structure_collection_get"])]
+    private array $parents;
 
     /**
      * @return int
@@ -210,18 +269,18 @@ class FederationStructure implements ApiResourcesInterface
     }
 
     /**
-     * @return string|null
+     * @return array
      */
-    public function getAddresses(): ?string
+    public function getAddresses(): array
     {
         return $this->addresses;
     }
 
     /**
-     * @param string|null $addresses
+     * @param array $addresses
      * @return FederationStructure
      */
-    public function setAddresses(?string $addresses): self
+    public function setAddresses(array $addresses): self
     {
         $this->addresses = $addresses;
         return $this;
@@ -230,36 +289,36 @@ class FederationStructure implements ApiResourcesInterface
     /**
      * @return string|null
      */
-    public function getTelphone(): ?string
+    public function getPhone(): ?string
     {
-        return $this->telphone;
+        return $this->phone;
     }
 
     /**
-     * @param string|null $telphone
+     * @param string|null $phone
+     * @return FederationStructure
      */
-    public function setTelphone(?string $telphone): self
+    public function setPhone(?string $phone): self
     {
-        $this->telphone = $telphone;
-
+        $this->phone = $phone;
         return $this;
     }
 
     /**
      * @return string|null
      */
-    public function getMobilPhone(): ?string
+    public function getMobilePhone(): ?string
     {
-        return $this->mobilPhone;
+        return $this->mobilePhone;
     }
 
     /**
-     * @param string|null $mobilPhone
+     * @param string|null $mobilePhone
+     * @return FederationStructure
      */
-    public function setMobilPhone(?string $mobilPhone): self
+    public function setMobilePhone(?string $mobilePhone): self
     {
-        $this->mobilPhone = $mobilPhone;
-
+        $this->mobilePhone = $mobilePhone;
         return $this;
     }
 
@@ -364,27 +423,27 @@ class FederationStructure implements ApiResourcesInterface
 
     /**
      * @param array|null $articles
+     * @return FederationStructure
      */
     public function setArticles(?array $articles): self
     {
         $this->articles = $articles;
-
         return $this;
     }
 
     /**
-     * @return string|null
+     * @return array|null
      */
-    public function getPractices(): ?string
+    public function getPractices(): ?array
     {
         return $this->practices;
     }
 
     /**
-     * @param string|null $practices
+     * @param array|null $practices
      * @return FederationStructure
      */
-    public function setPractices(?string $practices): self
+    public function setPractices(?array $practices): self
     {
         $this->practices = $practices;
         return $this;
@@ -535,18 +594,18 @@ class FederationStructure implements ApiResourcesInterface
     }
 
     /**
-     * @return string|null
+     * @return array
      */
-    public function getParents(): ?string
+    public function getParents(): array
     {
         return $this->parents;
     }
 
     /**
-     * @param string|null $parents
+     * @param array $parents
      * @return FederationStructure
      */
-    public function setParents(?string $parents): self
+    public function setParents(array $parents): self
     {
         $this->parents = $parents;
         return $this;

+ 6 - 2
src/Entity/Public/PublicEvent.php

@@ -8,10 +8,14 @@ use ApiPlatform\Core\Annotation\ApiResource;
 use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
 use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\NumericFilter;
 use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
-use App\ApiResources\ApiResourcesInterface;
 use App\Repository\Public\PublicEventRepository;
 use Doctrine\ORM\Mapping as ORM;
 
+/**
+ * Évènements publics tels que publiés sur l'agenda du site opentalent ou les sites des structures
+ *
+ * Fichier source de la view : ./sql/schema-extensions/001-view_public_events.sql
+ */
 #[ORM\Entity(repositoryClass: PublicEventRepository::class, readOnly: true)]
 #[ORM\Table(name: "view_public_events")]
 #[ApiResource(
@@ -31,7 +35,7 @@ use Doctrine\ORM\Mapping as ORM;
 #[ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'city' => 'exact'])]
 #[ApiFilter(NumericFilter::class, properties: ['organizationId'])]
 #[ApiFilter(DateFilter::class, properties: ['datetimeStart', 'datetimeEnd'])]
-class PublicEvent implements ApiResourcesInterface
+class PublicEvent
 {
     #[ORM\Id]
     #[ORM\Column]

+ 22 - 0
src/Repository/Public/FederationStructureRepository.php

@@ -0,0 +1,22 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Repository\Public;
+
+use App\Entity\Public\FederationStructure;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Persistence\ManagerRegistry;
+
+/**
+ * @method FederationStructure|null find($id, $lockMode = null, $lockVersion = null)
+ * @method FederationStructure|null findOneBy(array $criteria, array $orderBy = null)
+ * @method FederationStructure[]    findAll()
+ * @method FederationStructure[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
+final class FederationStructureRepository extends ServiceEntityRepository
+{
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, FederationStructure::class);
+    }
+}