From c1a94e832f6405d30e802dab74bf93f5d47db517 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Tue, 30 Jul 2024 19:03:01 +0200 Subject: [PATCH] event - update mapado infos on update --- assets/css/src/events-grid.css | 4 +- assets/css/src/generic.css | 7 ++- site/blueprints/pages/event.yml | 44 +++++++++++++- site/config/config.php | 3 + site/config/hooks/update-mapado-event.php | 66 +++++++++++++++++++++ site/config/routes/month-dates.php | 9 ++- site/config/routes/update-mapado-event.php | 69 ++++++++++++++++++++++ site/snippets/event-card.php | 3 + site/snippets/events-grid.php | 6 +- site/templates/home.php | 15 ++++- 10 files changed, 215 insertions(+), 11 deletions(-) create mode 100644 site/config/hooks/update-mapado-event.php create mode 100644 site/config/routes/update-mapado-event.php create mode 100644 site/snippets/event-card.php diff --git a/assets/css/src/events-grid.css b/assets/css/src/events-grid.css index 044cf43..8b13789 100644 --- a/assets/css/src/events-grid.css +++ b/assets/css/src/events-grid.css @@ -1,3 +1 @@ -.events-grid { - min-height: 30rem; -} + diff --git a/assets/css/src/generic.css b/assets/css/src/generic.css index df7436b..af70f25 100644 --- a/assets/css/src/generic.css +++ b/assets/css/src/generic.css @@ -1,3 +1,8 @@ body.progress * { cursor: progress !important; -} \ No newline at end of file +} + +.grid { + display: grid; + grid-template-columns: repeat(2, 1fr); +} diff --git a/site/blueprints/pages/event.yml b/site/blueprints/pages/event.yml index 3090bf3..4f2ab55 100644 --- a/site/blueprints/pages/event.yml +++ b/site/blueprints/pages/event.yml @@ -8,10 +8,14 @@ tabs: - width: 1/2 fields: mapadoKeyInfos: - label: Séances et durée récupérées de Mapado + label: Connecté à Mapado type: info + width: 1/2 text: | - [Gérer l'événement Mapado](https://desk.mapado.com/mass-action/ticketing/{{page.mapadoId}}) + [Gérer l'événement Mapado](https://desk.mapado.com/mass-action/ticketing/{{page.mapadoId}}). + + **Infos erronées ?** + Enregistrez (touches ⌘ / ctrl + s) et rechargez la page. when: isMapadoEvent: true duration: @@ -22,6 +26,15 @@ tabs: placeholder: 1h20 when: isMapadoEvent: false + remoteDuration: + label: Durée + type: text + icon: clock + width: 1/2 + placeholder: 1h20 + disabled: true + when: + isMapadoEvent: true - width: 1/2 fields: public: @@ -57,6 +70,33 @@ tabs: label: Horaire de début type: text width: 1/2 + remoteSessions: + label: Séances + type: structure + disabled: true + columns: + date: + width: 1/3 + time: + width: 1/3 + ticketingUrl: + width: 1/3 + when: + isMapadoEvent: true + fields: + date: + type: date + icon: calendar + display: DD/MM/YYYY + width: 1/3 + time: + label: Horaire de début + type: text + width: 1/3 + ticketingUrl: + label: Lien billetterie + type: url + width: 1/3 - width: 1/1 fields: line: diff --git a/site/config/config.php b/site/config/config.php index 1e84170..7155a98 100644 --- a/site/config/config.php +++ b/site/config/config.php @@ -35,5 +35,8 @@ return [ 'routes' => [ require_once(__DIR__ . '/routes/mapado-api.php'), require_once(__DIR__ . '/routes/month-dates.php') + ], + 'hooks' => [ + 'page.update:after' => require_once(__DIR__ . '/hooks/update-mapado-event.php') ] ]; \ No newline at end of file diff --git a/site/config/hooks/update-mapado-event.php b/site/config/hooks/update-mapado-event.php new file mode 100644 index 0000000..405e512 --- /dev/null +++ b/site/config/hooks/update-mapado-event.php @@ -0,0 +1,66 @@ +isMapadoEvent() != 'true') return; + $request = [ + "requestEndPoint" => "ticketings/" . $newPage->mapadoId()->value(), + "requestParams" => [], + "requestFields" => [ + ["name" => "title"], + ["name" => "address"], + ["name" => "slug"], + [ + "name" => "eventDateList", + "subfields" => [ + ["name" => "startDate"], + ["name" => "endDate"], + ["name" => "bookableStock"] + ] + ], + ] + ]; + + $mapadoEvent = fetchMapadoEvent($request); + $duration = null; + $sessionsToSave = []; + + if ($mapadoEvent->{"@type"} === 'hydra:Error') { + + $error = null; + if ($newPage->mapadoId()->isEmpty()) { + $error = 'Entrez l\'identifiant de l\'événement Mapado dans l\'onglet "Réglages".'; + } else { + $error = 'Aucun événement Mapado ne correspond à l\'identifiant ' . $newPage->mapado()->value() . '. En êtes-vous sûr•e ?'; + } + + throw new Exception($error, 1); + } + + + foreach ($mapadoEvent->eventDateList as $session) { + + $sessionMonth = substr($session->startDate, 0, 7); + + $day = intval(substr($session->startDate, 8, 2)); + $startTime = substr($session->startDate, 11, 5); + $eventDateId = explode('/', $session->{'@id'}); + $eventDateId = $eventDateId[count($eventDateId) - 1]; + $ticketingUrl = 'https://cdn-besancon.mapado.com/event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId; + + if (isset($session->endDate) && !$duration) { + $endTime = substr($session->endDate, 11 , 5); + $duration = getTimeDifference($startTime, $endTime); + } + + $sessionsToSave[] = [ + "date" => substr($session->startDate, 0, 10), + "time" => str_replace(':', 'h', $startTime), + 'ticketingUrl' => $ticketingUrl + ]; + } + + $newPage->update([ + "remoteDuration" => $duration, + "remoteSessions" => $sessionsToSave + ]); +}; \ No newline at end of file diff --git a/site/config/routes/month-dates.php b/site/config/routes/month-dates.php index 73847ba..541d790 100644 --- a/site/config/routes/month-dates.php +++ b/site/config/routes/month-dates.php @@ -85,6 +85,7 @@ return [ $startTime = substr($session->startDate, 11, 5); $eventDateId = explode('/', $session->{'@id'}); $eventDateId = $eventDateId[count($eventDateId) - 1]; + $ticketingUrl = 'https://cdn-besancon.mapado.com/event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId; if (isset($session->endDate) && !$duration) { $endTime = substr($session->endDate, 11 , 5); @@ -95,17 +96,19 @@ return [ "day" => $day, "time" => str_replace(':', 'h', $startTime), "duration" => $duration, - "ticketingUrl" => 'https://cdn-besancon.mapado.com/event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId + "ticketingUrl" => $ticketingUrl ]); $sessionsToSave[] = [ "date" => substr($session->startDate, 0, 10), - "time" => str_replace(':', 'h', $startTime) + "time" => str_replace(':', 'h', $startTime), + "ticketingUrl" => $ticketingUrl ]; } } $event->update([ - "sessions" => $sessionsToSave + "remoteDuration" => $duration, + "remoteSessions" => $sessionsToSave ]); } } diff --git a/site/config/routes/update-mapado-event.php b/site/config/routes/update-mapado-event.php new file mode 100644 index 0000000..95f0142 --- /dev/null +++ b/site/config/routes/update-mapado-event.php @@ -0,0 +1,69 @@ + '/update-mapado-event.json', + 'method' => 'POST', + 'action' => function () { + $jsonRequest = file_get_contents("php://input"); + $request = json_decode($jsonRequest, true); + + $id = $request['id']; + + $request = [ + "requestEndPoint" => "ticketings/" . $id, + "requestParams" => [], + "requestFields" => [ + ["name" => "title"], + ["name" => "address"], + ["name" => "slug"], + [ + "name" => "eventDateList", + "subfields" => [ + ["name" => "startDate"], + ["name" => "endDate"], + ["name" => "bookableStock"] + ] + ], + ] + ]; + + $mapadoEvent = fetchMapadoEvent($request); + $duration = null; + $sessionsToSave = []; + + foreach ($mapadoEvent->eventDateList as $session) { + + $sessionMonth = substr($session->startDate, 0, 7); + + if ($sessionMonth === $requestMonth) { + $day = intval(substr($session->startDate, 8, 2)); + $startTime = substr($session->startDate, 11, 5); + $eventDateId = explode('/', $session->{'@id'}); + $eventDateId = $eventDateId[count($eventDateId) - 1]; + + if (isset($session->endDate) && !$duration) { + $endTime = substr($session->endDate, 11 , 5); + $duration = getTimeDifference($startTime, $endTime); + + } + + $dates[$day][] = array_merge($eventInfos, [ + "day" => $day, + "time" => str_replace(':', 'h', $startTime), + "duration" => $duration, + "ticketingUrl" => 'https://cdn-besancon.mapado.com/event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId + ]); + + $sessionsToSave[] = [ + "date" => substr($session->startDate, 0, 10), + "time" => str_replace(':', 'h', $startTime) + ]; + } + } + + $event->update([ + "remoteDuration" => $duration, + "remoteSessions" => $sessionsToSave + ]); + } +]; diff --git a/site/snippets/event-card.php b/site/snippets/event-card.php new file mode 100644 index 0000000..6739a0f --- /dev/null +++ b/site/snippets/event-card.php @@ -0,0 +1,3 @@ +
+ $event->files()->first()]) ?> +
\ No newline at end of file diff --git a/site/snippets/events-grid.php b/site/snippets/events-grid.php index 616740e..575eafd 100644 --- a/site/snippets/events-grid.php +++ b/site/snippets/events-grid.php @@ -1 +1,5 @@ -
\ No newline at end of file +
+ + $event]) ?> + +
\ No newline at end of file diff --git a/site/templates/home.php b/site/templates/home.php index f330a9a..8f36606 100644 --- a/site/templates/home.php +++ b/site/templates/home.php @@ -8,5 +8,18 @@ - +children()->first()->children(); + $orderedEvents = $currentSeason->sortBy(function ($event) { + if ($event->isMapadoEvent() == 'true') { + return $event->remoteSessions()->toStructure()->toArray()[0]['date']; + } else { + return $event->sessions()->toStructure()->toArray()[0]['date']; + } + }, + 'asc' + ); + + snippet('events-grid', ['events' => $orderedEvents->limit(2)]) +?> \ No newline at end of file