|
|
@@ -1,8 +1,103 @@
|
|
|
<?php
|
|
|
+declare(strict_types=1);
|
|
|
|
|
|
namespace App\Repository\Booking;
|
|
|
|
|
|
-class EventRepository
|
|
|
+use App\Entity\Public\PublicEvent;
|
|
|
+use App\Entity\Booking\Event;
|
|
|
+use App\Enum\Public\PublicEventOriginEnum;
|
|
|
+use App\Service\Utils\ArrayUtils;
|
|
|
+use App\Service\Utils\DatesUtils;
|
|
|
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
+use Doctrine\Persistence\ManagerRegistry;
|
|
|
+
|
|
|
+class EventRepository extends ServiceEntityRepository
|
|
|
{
|
|
|
+ public function __construct(ManagerRegistry $registry, private EntityManagerInterface $em)
|
|
|
+ {
|
|
|
+ parent::__construct($registry, Event::class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Route optimisée pour retourner les données de d'un évènement publique, sous forme d'Api resources
|
|
|
+ * de type PublicEvent.
|
|
|
+ *
|
|
|
+ * Cette route est utilisée par l'iframe de recherche des évènements
|
|
|
+ * @see https://gitlab.2iopenservice.com/opentalent/frames
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * @throws \Doctrine\DBAL\DBALException
|
|
|
+ * @throws \Doctrine\DBAL\Driver\Exception
|
|
|
+ * @throws \Doctrine\DBAL\Exception
|
|
|
+ */
|
|
|
+ public function getAllEvents(): array
|
|
|
+ {
|
|
|
+ $sql = " SELECT
|
|
|
+ b.id as id, b.organization_id AS organizationId, b.name, b.description, b.url, b.datetimeStart, b.datetimeEnd,
|
|
|
+ p.name AS placeName, p.description AS placeDescription, p.floorSize AS placeFloorSize, p.capacity AS placeCapacity,
|
|
|
+ ap.addressCity AS city, ap.postalCode,
|
|
|
+ TRIM(BOTH ' ' FROM CONCAT( if(ap.streetAddress is null,'',ap.streetAddress), ' ', if(ap.streetAddressSecond is null,'',ap.streetAddressSecond), ' ', if(ap.streetAddressThird is null,'',ap.streetAddressThird))) AS streetAddress,
|
|
|
+ ap.longitude, ap.latitude,
|
|
|
+ r.name AS roomName, r.description AS roomDescription, r.localisation AS roomLocalisation, r.capacity AS roomCapacity, r.floorSize AS roomFloorSize, b.image_id AS imageId,
|
|
|
+ (SELECT CONCAT('[',GROUP_CONCAT(CONCAT(f.code)),']')
|
|
|
+ FROM event_categories AS ec
|
|
|
+ LEFT JOIN Categories AS cs ON(cs.id = ec.categories_id)
|
|
|
+ LEFT JOIN Familly AS f ON(f.id = cs.familly_id)
|
|
|
+ WHERE ec.event_id = b.id
|
|
|
+ ) AS categories, '" . PublicEventOriginEnum::OPENTALENT()->getValue() . "' as origin
|
|
|
+ FROM Booking AS b
|
|
|
+ INNER JOIN Organization o ON o.id = b.organization_id
|
|
|
+ INNER JOIN Parameters par ON par.id = o.parameters_id
|
|
|
+ LEFT JOIN Place AS p ON (p.id = b.place_id)
|
|
|
+ LEFT JOIN AddressPostal AS ap ON (ap.id = p.addressPostal_id)
|
|
|
+ LEFT JOIN Room AS r ON (r.id = b.room_id)
|
|
|
+ WHERE b.discr = 'event' AND b.datetimeEnd >= NOW() AND b.visibility = 'PUBLIC_VISIBILITY' AND b.isCanceled = 0
|
|
|
+ UNION
|
|
|
+ SELECT
|
|
|
+ auto_increment_value(null) as id, null AS organizationId, aw.name, aw.description, NULL AS url, aw.datetimeStart, aw.datetimeEnd,
|
|
|
+ aw.place AS placeName, NULL AS placeDescription, NULL AS placeFloorSize, NULL AS placeCapacity,
|
|
|
+ aw.city, aw.postalCode, aw.streetAddress, aw.longitude, aw.latitude,
|
|
|
+ NULL AS roomName, NULL AS roomDescription, NULL AS roomLocalisation, NULL AS roomCapacity, NULL AS roomFloorSize,
|
|
|
+ aw.largeimage AS imageId, aw.categories AS categories, '" . PublicEventOriginEnum::AWIN()->getValue() . "' as origin
|
|
|
+ FROM AwinProduct as aw
|
|
|
+ WHERE
|
|
|
+ aw.datetimeEnd >= NOW() AND aw.datetimeStart IS NOT NULL;
|
|
|
+ ";
|
|
|
+
|
|
|
+ $stmt = $this->em->getConnection()->prepare($sql);
|
|
|
+ $rows = $stmt->executeQuery()->fetchAllAssociative();
|
|
|
+
|
|
|
+ return array_map('self::buildPublicEvent', $rows);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Build a PublicEvent with the data provided by getAllEvents() and ...
|
|
|
+ */
|
|
|
+ private static function buildPublicEvent(array $data): PublicEvent
|
|
|
+ {
|
|
|
+ return (new PublicEvent)
|
|
|
+ ->setId((int)$data['id'])
|
|
|
+ ->setOrganizationId(ArrayUtils::getAndCast($data, 'organizationId', 'int'))
|
|
|
+ ->setName($data['name'])
|
|
|
+ ->setDescription($data['description'])
|
|
|
+ ->setUrl($data['url'])
|
|
|
+ ->setDatetimeStart(DatesUtils::new($data['datetimeStart']))
|
|
|
+ ->setDatetimeEnd(DatesUtils::new($data['datetimeEnd']))
|
|
|
+ ->setCity($data['city'])
|
|
|
+ ->setPostalCode($data['postalCode'])
|
|
|
+ ->setStreetAddress($data['streetAddress'])
|
|
|
+ ->setLongitude(ArrayUtils::getAndCast($data, 'longitude', 'float'))
|
|
|
+ ->setLatitude(ArrayUtils::getAndCast($data, 'latitude', 'float'))
|
|
|
+ ->setRoomName($data['roomName'])
|
|
|
+ ->setRoomDescription($data['roomDescription'])
|
|
|
+ ->setRoomLocalisation($data['roomLocalisation'])
|
|
|
+ ->setRoomCapacity($data['roomCapacity'])
|
|
|
+ ->setRoomFloorSize($data['roomFloorSize'])
|
|
|
+ ->setImageId(ArrayUtils::getAndCast($data, 'imageId', 'int'))
|
|
|
+ ->setCategories($data['categories'])
|
|
|
+ ->setOrigin($data['origin']);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|