From e58e630f9b0727c2e317a9d817c1b204c832656b Mon Sep 17 00:00:00 2001 From: isUnknown Date: Tue, 10 Sep 2024 13:47:04 +0200 Subject: [PATCH] fix --- site/blueprints/pages/event.yml | 29 +++++++++++++---------------- site/config/routes/month-dates.php | 2 +- site/controllers/program.php | 2 +- site/plugins/helpers/index.php | 21 ++++++++++----------- site/templates/event.php | 4 ++-- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/site/blueprints/pages/event.yml b/site/blueprints/pages/event.yml index 8d23783..f25717e 100644 --- a/site/blueprints/pages/event.yml +++ b/site/blueprints/pages/event.yml @@ -52,18 +52,6 @@ tabs: icon: clock width: 1/2 placeholder: 1h20 - when: - isMapadoEvent: false - remoteDuration: - label: Durée - type: text - icon: clock - width: 1/2 - placeholder: 1h20 - disabled: true - help: Nécessite **qu'une séance au moins ait une heure de fin** sur Mapado. - when: - isMapadoEvent: true - width: 1/2 fields: public: @@ -84,9 +72,11 @@ tabs: type: structure columns: date: - width: 1/2 + width: 1/3 time: - width: 1/2 + width: 1/3 + timeComplement: + width: 1/3 when: isMapadoEvent: false fields: @@ -94,11 +84,18 @@ tabs: type: date icon: calendar display: DD/MM/YYYY - width: 1/2 + width: 1/3 time: label: Horaire de début type: text - width: 1/2 + help: | + Format : 20h00 ou 20h (pas 20:00) + width: 1/3 + timeComplement: + label: Complément + help: Affiché après l'horaire + type: text + width: 1/3 remoteSessions: label: Séances type: structure diff --git a/site/config/routes/month-dates.php b/site/config/routes/month-dates.php index 7bea590..42fbc69 100644 --- a/site/config/routes/month-dates.php +++ b/site/config/routes/month-dates.php @@ -45,7 +45,7 @@ return [ $dates[$day]['sessions'][] = array_merge($eventInfos, [ "color" => $event->color()->value(), "day" => $day, - "time" => $session->time()->value(), + "time" => $session->timeComplement()->isEmpty() == 'true' ? $session->time()->value() : $session->time()->value() . ' ' . $session->timeComplement()->value(), "place" => $event->place()->value(), "duration" => $event->duration()->value(), "eventUrl" => $event->url(), diff --git a/site/controllers/program.php b/site/controllers/program.php index c1fad68..15b9827 100644 --- a/site/controllers/program.php +++ b/site/controllers/program.php @@ -34,7 +34,7 @@ function createArraySession($event, $session) { $arraySession['place'] = $event->place(); $arraySession['public'] = $event->public(); $arraySession['event-url'] = $event->url(); - $arraySession['duration'] = $isMapadoEvent ? $event->remoteDuration() : $event->duration(); + $arraySession['duration'] = $event->duration(); $arraySession['ticketingUrl'] = $isMapadoEvent ? $session->ticketingUrl() : false; $arraySession['bookableStock'] = $isMapadoEvent ? $session->bookableStock()->value() : 'free'; $arraySession['totalStock'] = $isMapadoEvent ? (int) $event->totalStock()->value() : 'free'; diff --git a/site/plugins/helpers/index.php b/site/plugins/helpers/index.php index ec46509..a508c39 100644 --- a/site/plugins/helpers/index.php +++ b/site/plugins/helpers/index.php @@ -146,10 +146,6 @@ function saveMapadoEvent($mapadoEvent, $page) { $eventDateId = $eventDateId[count($eventDateId) - 1]; $ticketingUrl = option('ticketingUrl') . '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), @@ -161,7 +157,6 @@ function saveMapadoEvent($mapadoEvent, $page) { $dataToSave = [ "mapadoSlug" => $mapadoEvent->slug, - "remoteDuration" => $duration, "remoteSessions" => $sessionsToSave, "eventDateId" => $eventDateId, "totalStock" => $totalStock @@ -173,18 +168,22 @@ function saveMapadoEvent($mapadoEvent, $page) { } function getEndTime($session) { - $formattedTime = strlen($session['time']) < 4 ? $session['time'] . '00' : $session['time']; + $formattedTime = preg_replace('/[^0-9]/', '', $session['time']); + $formattedTime = strlen($formattedTime) < 4 ? str_pad($formattedTime, 4, '0', STR_PAD_RIGHT) : $formattedTime; + $time1 = DateTime::createFromFormat('Hi', $formattedTime); if ($time1 === false) { - throw new Exception('format d\'heure invalide : ' . $session['time']); + throw new Exception('format d\'heure invalide : ' . $session['time']); } - - $formattedDuration = strlen($session['duration']) < 4 ? $session['duration'] . '00' : $session['duration']; + + $formattedDuration = preg_replace('/[^0-9]/', '', $session['duration']); + $formattedDuration = strlen($formattedDuration) < 4 ? str_pad($formattedDuration, 4, '0', STR_PAD_RIGHT) : $formattedDuration; + $time2 = DateTime::createFromFormat('Hi', $formattedDuration); if ($time2 === false) { - throw new Exception('format de durée invalide : ' . $session['duration']); + throw new Exception('format de durée invalide : ' . $session['duration']); } - + $time1->add(new DateInterval('PT' . $time2->format('H') . 'H' . $time2->format('i') . 'M')); return $time1->format('H:i'); diff --git a/site/templates/event.php b/site/templates/event.php index 2f8401e..bccf92c 100644 --- a/site/templates/event.php +++ b/site/templates/event.php @@ -2,7 +2,7 @@
@@ -48,7 +48,7 @@ ?>

-

time() ?>

+

timeComplement()->isEmpty() == 'true', $session->time(), $session->time() . ' ' . $session->timeComplement()) ?>

place() ?>

bookingUrl()->isEmpty()): ?> Entrée libre