Browse Source

minor fixes

Olivier Massot 3 years ago
parent
commit
89d417da15

+ 1 - 0
config/bundles.php

@@ -20,4 +20,5 @@ return [
     Symfony\Bundle\DebugBundle\DebugBundle::class => ['docker' => true],
     Symfony\Bundle\MercureBundle\MercureBundle::class => ['all' => true],
     DH\AuditorBundle\DHAuditorBundle::class => ['all' => true],
+    Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
 ];

+ 0 - 0
sql/schema-extension/001-view_portail_events.sql


+ 1 - 2
src/ApiResources/Public/FederationStructure.php

@@ -6,7 +6,6 @@ namespace App\ApiResources\Public;
 use ApiPlatform\Core\Annotation\ApiProperty;
 use ApiPlatform\Core\Annotation\ApiResource;
 use App\ApiResources\ApiResourcesInterface;
-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
@@ -15,7 +14,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
     collectionOperations: [
         'get' => [
             'method' => 'GET',
-            'path' => '/public/federation_structures' // + '?parent={\d+}'
+            'path' => '/public/federation_structures' // required query : '?parent={\d+}'
         ]
     ],
     itemOperations: [

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

@@ -0,0 +1,44 @@
+<?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));
+    }
+}

+ 432 - 0
src/Entity/Public/PublicEvent.php

@@ -0,0 +1,432 @@
+<?php
+declare(strict_types=1);
+
+namespace App\ApiResources\Public;
+
+use ApiPlatform\Core\Annotation\ApiProperty;
+use ApiPlatform\Core\Annotation\ApiResource;
+use App\ApiResources\ApiResourcesInterface;
+use App\Repository\Public\PublicEventRepository;
+use Doctrine\ORM\Mapping as ORM;
+
+#[ORM\Entity(repositoryClass: PublicEventRepository::class, readOnly: true)]
+#[ORM\Table(name: "view_portail_events")]
+#[ApiResource(
+    collectionOperations: [
+        'get' => [
+            'method' => 'GET',
+            'path' => '/public/events'
+        ]
+    ],
+    itemOperations: [
+        'get' => [
+            'method' => 'GET',
+            'path' => '/public/events/{id}'
+        ]
+    ]
+)]
+class PublicEvent implements ApiResourcesInterface
+{
+    #[ORM\Id]
+    #[ORM\Column]
+    private int $id;
+
+    private ?int $organizationId;
+
+    #[ORM\Column()]
+    private string $name;
+
+    private ?string $description;
+
+    private ?string $url;
+
+    private \DateTime $datetimeStart;
+
+    private \DateTime $datetimeEnd;
+
+    private ?string $city;
+
+    private ?string $postalCode;
+
+    private ?string $streetAddress;
+
+    private ?float $longitude;
+
+    private ?float $latitude;
+
+    private ?string $roomName;
+
+    private ?string $roomDescription;
+
+    private ?string $roomLocalisation;
+
+    private ?string $roomCapacity;
+
+    private ?string $roomFloorSize;
+
+    private ?int $imageId;
+
+    private ?string $categories;
+
+    private string $origin = 'opentalent';
+
+    /**
+     * @return int
+     */
+    public function getId(): int
+    {
+        return $this->id;
+    }
+
+    /**
+     * @param int $id
+     * @return PublicEvent
+     */
+    public function setId(int $id): self
+    {
+        $this->id = $id;
+        return $this;
+    }
+
+    /**
+     * @return int|null
+     */
+    public function getOrganizationId(): ?int
+    {
+        return $this->organizationId;
+    }
+
+    /**
+     * @param int|null $organizationId
+     * @return PublicEvent
+     */
+    public function setOrganizationId(?int $organizationId): self
+    {
+        $this->organizationId = $organizationId;
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getName(): string
+    {
+        return $this->name;
+    }
+
+    /**
+     * @param string $name
+     * @return PublicEvent
+     */
+    public function setName(string $name): self
+    {
+        $this->name = $name;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getDescription(): ?string
+    {
+        return $this->description;
+    }
+
+    /**
+     * @param string|null $description
+     * @return PublicEvent
+     */
+    public function setDescription(?string $description): self
+    {
+        $this->description = $description;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getUrl(): ?string
+    {
+        return $this->url;
+    }
+
+    /**
+     * @param string|null $url
+     * @return PublicEvent
+     */
+    public function setUrl(?string $url): self
+    {
+        $this->url = $url;
+        return $this;
+    }
+
+    /**
+     * @return \DateTime
+     */
+    public function getDatetimeStart(): \DateTime
+    {
+        return $this->datetimeStart;
+    }
+
+    /**
+     * @param \DateTime $datetimeStart
+     * @return PublicEvent
+     */
+    public function setDatetimeStart(\DateTime $datetimeStart): self
+    {
+        $this->datetimeStart = $datetimeStart;
+        return $this;
+    }
+
+    /**
+     * @return \DateTime
+     */
+    public function getDatetimeEnd(): \DateTime
+    {
+        return $this->datetimeEnd;
+    }
+
+    /**
+     * @param \DateTime $datetimeEnd
+     * @return PublicEvent
+     */
+    public function setDatetimeEnd(\DateTime $datetimeEnd): self
+    {
+        $this->datetimeEnd = $datetimeEnd;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getCity(): ?string
+    {
+        return $this->city;
+    }
+
+    /**
+     * @param string|null $city
+     * @return PublicEvent
+     */
+    public function setCity(?string $city): self
+    {
+        $this->city = $city;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getPostalCode(): ?string
+    {
+        return $this->postalCode;
+    }
+
+    /**
+     * @param string|null $postalCode
+     * @return PublicEvent
+     */
+    public function setPostalCode(?string $postalCode): self
+    {
+        $this->postalCode = $postalCode;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getStreetAddress(): ?string
+    {
+        return $this->streetAddress;
+    }
+
+    /**
+     * @param string|null $streetAddress
+     * @return PublicEvent
+     */
+    public function setStreetAddress(?string $streetAddress): self
+    {
+        $this->streetAddress = $streetAddress;
+        return $this;
+    }
+
+    /**
+     * @return float|null
+     */
+    public function getLongitude(): ?float
+    {
+        return $this->longitude;
+    }
+
+    /**
+     * @param float|null $longitude
+     * @return PublicEvent
+     */
+    public function setLongitude(?float $longitude): self
+    {
+        $this->longitude = $longitude;
+        return $this;
+    }
+
+    /**
+     * @return float|null
+     */
+    public function getLatitude(): ?float
+    {
+        return $this->latitude;
+    }
+
+    /**
+     * @param float|null $latitude
+     * @return PublicEvent
+     */
+    public function setLatitude(?float $latitude): self
+    {
+        $this->latitude = $latitude;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getRoomName(): ?string
+    {
+        return $this->roomName;
+    }
+
+    /**
+     * @param string|null $roomName
+     * @return PublicEvent
+     */
+    public function setRoomName(?string $roomName): self
+    {
+        $this->roomName = $roomName;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getRoomDescription(): ?string
+    {
+        return $this->roomDescription;
+    }
+
+    /**
+     * @param string|null $roomDescription
+     * @return PublicEvent
+     */
+    public function setRoomDescription(?string $roomDescription): self
+    {
+        $this->roomDescription = $roomDescription;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getRoomLocalisation(): ?string
+    {
+        return $this->roomLocalisation;
+    }
+
+    /**
+     * @param string|null $roomLocalisation
+     * @return PublicEvent
+     */
+    public function setRoomLocalisation(?string $roomLocalisation): self
+    {
+        $this->roomLocalisation = $roomLocalisation;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getRoomCapacity(): ?string
+    {
+        return $this->roomCapacity;
+    }
+
+    /**
+     * @param string|null $roomCapacity
+     * @return PublicEvent
+     */
+    public function setRoomCapacity(?string $roomCapacity): self
+    {
+        $this->roomCapacity = $roomCapacity;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getRoomFloorSize(): ?string
+    {
+        return $this->roomFloorSize;
+    }
+
+    /**
+     * @param string|null $roomFloorSize
+     * @return PublicEvent
+     */
+    public function setRoomFloorSize(?string $roomFloorSize): self
+    {
+        $this->roomFloorSize = $roomFloorSize;
+        return $this;
+    }
+
+    /**
+     * @return int|null
+     */
+    public function getImageId(): ?int
+    {
+        return $this->imageId;
+    }
+
+    /**
+     * @param int|null $imageId
+     * @return PublicEvent
+     */
+    public function setImageId(?int $imageId): self
+    {
+        $this->imageId = $imageId;
+        return $this;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getCategories(): ?string
+    {
+        return $this->categories;
+    }
+
+    /**
+     * @param string|null $categories
+     * @return PublicEvent
+     */
+    public function setCategories(?string $categories): self
+    {
+        $this->categories = $categories;
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getOrigin(): string
+    {
+        return $this->origin;
+    }
+
+    /**
+     * @param string $origin
+     * @return PublicEvent
+     */
+    public function setOrigin(string $origin): self
+    {
+        $this->origin = $origin;
+        return $this;
+    }
+}

+ 6 - 0
src/Enum/Public/PublicEventOriginEnum.php

@@ -0,0 +1,6 @@
+<?php
+
+class PublicEventOriginEnum
+{
+
+}

+ 8 - 0
src/Repository/Booking/EventRepository.php

@@ -0,0 +1,8 @@
+<?php
+
+namespace App\Repository\Booking;
+
+class EventRepository
+{
+
+}

+ 8 - 7
src/Repository/Organization/OrganizationRepository.php

@@ -5,6 +5,7 @@ namespace App\Repository\Organization;
 
 use App\ApiResources\Public\FederationStructure;
 use App\Entity\Organization\Organization;
+use App\Service\Utils\ArrayUtils;
 use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
 use Doctrine\ORM\EntityManagerInterface;
 use Doctrine\Persistence\ManagerRegistry;
@@ -130,9 +131,9 @@ class OrganizationRepository extends ServiceEntityRepository
         return (new FederationStructure())
             ->setId((int)$data['id'])
             ->setName($data['name'])
-            ->setLogoId(isset($data['logoId']) ? (int)$data['logoId'] : null)
+            ->setLogoId(ArrayUtils::getAndCast($data, 'logoId', 'int'))
             ->setDescription($data['description'] ?? null)
-            ->setImageId(isset($data['imageId']) ? (int)$data['imageId'] : null)
+            ->setImageId(ArrayUtils::getAndCast($data, 'imageId', 'int'))
             ->setPrincipalType($data['principalType'] ?? null)
             ->setWebsite($data['website'])
             ->setAddresses($data['addresses'])
@@ -147,12 +148,12 @@ class OrganizationRepository extends ServiceEntityRepository
             ->setPractices($data['practices'])
             ->setLatitude($data['latitude'] ?? null)
             ->setLongitude($data['longitude'] ?? null)
-            ->setN1Id(isset($data['n1Id']) ? (int)$data['n1Id'] : null)
+            ->setN1Id(ArrayUtils::getAndCast($data, 'n1Id', 'int'))
             ->setN1Name($data['n1Name'] ?? null)
-            ->setN2Id(isset($data['n2id']) ? (int)$data['n2id'] : null)
-            ->setN3Id(isset($data['n3Id']) ? (int)$data['n3Id'] : null)
-            ->setN4Id(isset($data['n4Id']) ? (int)$data['n4Id'] : null)
-            ->setN5Id(isset($data['n5Id']) ? (int)$data['n5Id'] : null)
+            ->setN2Id(ArrayUtils::getAndCast($data, 'n2id', 'int'))
+            ->setN3Id(ArrayUtils::getAndCast($data, 'n3Id', 'int'))
+            ->setN4Id(ArrayUtils::getAndCast($data, 'n4Id', 'int'))
+            ->setN5Id(ArrayUtils::getAndCast($data, 'n5Id', 'int'))
             ->setParents($data['parents'] ?? null);
     }
 }

+ 23 - 0
src/Service/Utils/ArrayUtils.php

@@ -42,4 +42,27 @@ class ArrayUtils
         return $changes;
     }
 
+    /**
+     * If the given $key is set in the array and if the corresponding value is not null,
+     * cast this value and returns it. Else, returns null.
+     *
+     * Ex:
+     *
+     *    $array = ['a' => '123']
+     *
+     *     ArrayUtils::getAndCast($array, 'a', 'int')  // => returns `123` as an integer
+     *     ArrayUtils::getAndCast($array, 'b', 'int')  // => returns `null`
+     *
+     * @param array $array
+     * @param string $key
+     * @param string $type
+     * @return mixed
+     */
+    public static function getAndCast(array $array, mixed $key, string $type): mixed {
+        $value = $array[$key] ?? null;
+        if ($value !== null) {
+            settype($value, $type);
+        }
+        return $value;
+    }
 }