Pārlūkot izejas kodu

ne pas afficher les genre mariage et examen pour l'agenda

opentalent 1 gadu atpakaļ
vecāks
revīzija
33a213e71e

+ 2 - 0
sql/schema-extensions/001-view_public_events.sql

@@ -8,6 +8,7 @@ AS
         b.url, 
         b.url, 
         b.datetimeStart, 
         b.datetimeStart, 
         b.datetimeEnd, 
         b.datetimeEnd, 
+        b.gender_id as gender,
         COALESCE(b.priceMini, 0) AS priceMini, 
         COALESCE(b.priceMini, 0) AS priceMini, 
         COALESCE(b.priceMaxi, 0) AS priceMaxi, 
         COALESCE(b.priceMaxi, 0) AS priceMaxi, 
         null as categoryCode,
         null as categoryCode,
@@ -54,6 +55,7 @@ UNION
         aw.deepLink AS url, 
         aw.deepLink AS url, 
         aw.datetimeStart, 
         aw.datetimeStart, 
         aw.datetimeEnd, 
         aw.datetimeEnd, 
+        NULL as gender,
         aw.priceMini, 
         aw.priceMini, 
         aw.priceMaxi, 
         aw.priceMaxi, 
         aw.subCategory AS categoryCode,
         aw.subCategory AS categoryCode,

+ 30 - 9
src/Entity/Public/PublicEvent.php

@@ -4,19 +4,20 @@ declare(strict_types=1);
 
 
 namespace App\Entity\Public;
 namespace App\Entity\Public;
 
 
-use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
-use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
-use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
-use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
-use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
+use ApiPlatform\Metadata\Get;
+use Doctrine\ORM\Mapping as ORM;
 use ApiPlatform\Metadata\ApiFilter;
 use ApiPlatform\Metadata\ApiFilter;
 use ApiPlatform\Metadata\ApiResource;
 use ApiPlatform\Metadata\ApiResource;
-use ApiPlatform\Metadata\Get;
 use ApiPlatform\Metadata\GetCollection;
 use ApiPlatform\Metadata\GetCollection;
-use App\Filter\ApiPlatform\Utils\ArrayFieldFilter;
+use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
+use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
+use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
 use App\Filter\ApiPlatform\Utils\DistanceFilter;
 use App\Filter\ApiPlatform\Utils\DistanceFilter;
 use App\Repository\Public\PublicEventRepository;
 use App\Repository\Public\PublicEventRepository;
-use Doctrine\ORM\Mapping as ORM;
+use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
+use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
+use App\Filter\ApiPlatform\Utils\ArrayFieldFilter;
+use App\Filter\ApiPlatform\PublicEvent\ExcludeGenderFilter;
 
 
 /**
 /**
  * Évènements publics tels que publiés sur l'agenda du site opentalent ou les sites des structures.
  * Évènements publics tels que publiés sur l'agenda du site opentalent ou les sites des structures.
@@ -42,7 +43,8 @@ use Doctrine\ORM\Mapping as ORM;
 #[ApiFilter(filterClass: DistanceFilter::class)]
 #[ApiFilter(filterClass: DistanceFilter::class)]
 #[ApiFilter(filterClass: OrderFilter::class, properties: ['datetimeStart', 'datetimeEnd'], arguments: ['orderParameterName' => 'order'])]
 #[ApiFilter(filterClass: OrderFilter::class, properties: ['datetimeStart', 'datetimeEnd'], arguments: ['orderParameterName' => 'order'])]
 #[ApiFilter(filterClass: RangeFilter::class, properties: ['priceMini', 'priceMaxi'])]
 #[ApiFilter(filterClass: RangeFilter::class, properties: ['priceMini', 'priceMaxi'])]
-#[ApiFilter(filterClass: ArrayFieldFilter::class, properties: ['categories'])]
+#[ApiFilter(filterClass: ArrayFieldFilter::class, properties: ['categories', 'gender'])]
+#[ApiFilter(ExcludeGenderFilter::class)]
 class PublicEvent
 class PublicEvent
 {
 {
     #[ORM\Id]
     #[ORM\Id]
@@ -107,6 +109,10 @@ class PublicEvent
     #[ORM\Column(type: 'simple_array')]
     #[ORM\Column(type: 'simple_array')]
     private ?array $categories;
     private ?array $categories;
 
 
+    /** @var list<string>|null */
+    #[ORM\Column(type: 'simple_array')]
+    private ?array $gender;
+
     #[ORM\Column]
     #[ORM\Column]
     private string $origin = 'opentalent';
     private string $origin = 'opentalent';
 
 
@@ -123,6 +129,8 @@ class PublicEvent
     #[ORM\Column]
     #[ORM\Column]
     private ?string $categoryCode;
     private ?string $categoryCode;
 
 
+
+
     public function getUuid(): string
     public function getUuid(): string
     {
     {
         return $this->uuid;
         return $this->uuid;
@@ -369,6 +377,17 @@ class PublicEvent
         return $this;
         return $this;
     }
     }
 
 
+    public function getGender(): ?array
+    {
+        return $this->gender;
+    }
+
+    public function setGender(?array $gender): PublicEvent
+    {
+        $this->gender = $gender;
+        return $this;
+    }
+
     public function getOrigin(): string
     public function getOrigin(): string
     {
     {
         return $this->origin;
         return $this->origin;
@@ -428,4 +447,6 @@ class PublicEvent
 
 
         return $this;
         return $this;
     }
     }
+    
+ 
 }
 }

+ 67 - 0
src/Filter/ApiPlatform/PublicEvent/ExcludeGenderFilter.php

@@ -0,0 +1,67 @@
+<?php
+namespace App\Filter\ApiPlatform\PublicEvent;
+
+use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
+use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
+use ApiPlatform\Metadata\Operation;
+use Doctrine\ORM\QueryBuilder;
+
+/**
+ * Provides a filter for excluding specific gender IDs from the query results.
+ * This filter checks for a query parameter 'excludeGenderFilter' and if set to true,
+ * excludes gender IDs associated with specific categories such as 'marriage' and 'exams'.
+ *
+ * To activate this filter, include the query parameter 'excludeGenderFilter=true' in the URL.
+ * For example:
+ * https://local.ap2i.opentalent.fr/api/public/events?excludeGenderFilter=true
+ * 
+ * This will exclude entities where the gender field contains the IDs 29 (marriage) or 18 (exams) for agenda events.
+ */
+class ExcludeGenderFilter extends AbstractFilter
+{
+    /**
+     * Modifies the query to exclude specific gender IDs if the 'excludeGenderFilter' parameter is set to true.
+     * 
+     * @param string $property The name of the property being filtered.
+     * @param mixed $value The value of the filter being applied.
+     * @param QueryBuilder $queryBuilder The Doctrine query builder.
+     * @param QueryNameGeneratorInterface $queryNameGenerator A utility to generate query parameter names.
+     * @param string $resourceClass The resource class.
+     * @param ?Operation $operation The operation being performed, if any.
+     * @param array $context Additional context for the filter.
+     */
+    protected function filterProperty(
+        string $property,
+        mixed $value,
+        QueryBuilder $queryBuilder,
+        QueryNameGeneratorInterface $queryNameGenerator,
+        string $resourceClass,
+        ?Operation $operation = null,
+        array $context = []
+    ): void {
+        if ($property === 'excludeGenderFilter' && $value === 'true') {
+            $parameterName = $queryNameGenerator->generateParameterName('gender');
+            $filteredValues = [29, 18]; 
+            $queryBuilder->andWhere($queryBuilder->expr()->notIn('o.gender', ':'.$parameterName))
+                         ->setParameter($parameterName, $filteredValues);
+        }
+    }
+
+    /**
+     * Provides a description for the API documentation.
+     * 
+     * @param string $resourceClass The resource class for which the filter is being described.
+     * @return array Returns the description of the filter to be included in the API documentation.
+     */
+    public function getDescription(string $resourceClass): array
+    {
+        return [
+            'excludeGenderFilter' => [
+                'property' => null, 
+                'type' => 'boolean',
+                'required' => false,
+                'description' => 'Activates filtering to exclude specific gender IDs'
+            ]
+        ];
+    }
+}