2024-08-28 19:11:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
2024-08-30 14:37:13 +02:00
|
|
|
function sortByMonth($sessions) {
|
|
|
|
|
$months = array(
|
|
|
|
|
'janvier', 'février', 'mars', 'avril', 'mai', 'juin',
|
|
|
|
|
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$orderedSessions = array();
|
|
|
|
|
|
|
|
|
|
foreach ($months as $month) {
|
|
|
|
|
$orderedSessions[$month] = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($sessions as $item) {
|
|
|
|
|
$month = date('F', strtotime($item['date']));
|
|
|
|
|
$month = str_replace(
|
|
|
|
|
array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
|
|
|
|
|
$months,
|
|
|
|
|
$month
|
|
|
|
|
);
|
|
|
|
|
$orderedSessions[$month][] = $item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $orderedSessions;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 11:12:23 +02:00
|
|
|
function createArraySession($event, $session) {
|
|
|
|
|
$isMapadoEvent = $event->isMapadoEvent() == 'true';
|
|
|
|
|
$arraySession = $session->toArray();
|
|
|
|
|
|
|
|
|
|
$arraySession['title'] = $event->title()->value();
|
|
|
|
|
$arraySession['authors'] = $event->authors();
|
|
|
|
|
$arraySession['place'] = $event->place();
|
|
|
|
|
$arraySession['public'] = $event->public();
|
|
|
|
|
$arraySession['event-url'] = $event->url();
|
2024-09-10 13:47:04 +02:00
|
|
|
$arraySession['duration'] = $event->duration();
|
2024-09-03 11:12:23 +02:00
|
|
|
$arraySession['ticketingUrl'] = $isMapadoEvent ? $session->ticketingUrl() : false;
|
|
|
|
|
$arraySession['bookableStock'] = $isMapadoEvent ? $session->bookableStock()->value() : 'free';
|
2024-09-04 17:02:37 +02:00
|
|
|
$arraySession['totalStock'] = $isMapadoEvent ? (int) $event->totalStock()->value() : 'free';
|
2024-09-03 11:12:23 +02:00
|
|
|
$arraySession['color'] = $event->color();
|
2024-09-06 14:32:11 +02:00
|
|
|
$arraySession['categories'] = $event->categories();
|
2024-09-03 11:12:23 +02:00
|
|
|
|
|
|
|
|
return $arraySession;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 19:11:58 +02:00
|
|
|
return function($page) {
|
|
|
|
|
$currentSeason = $page->children()->first();
|
|
|
|
|
$today = date('Ymd');
|
|
|
|
|
|
|
|
|
|
$previousEvents = new Pages();
|
|
|
|
|
$nextEvents = new Pages();
|
|
|
|
|
|
2024-08-30 14:37:13 +02:00
|
|
|
$currentSeasonSessions = [];
|
|
|
|
|
|
2024-08-28 19:11:58 +02:00
|
|
|
foreach ($currentSeason->children() as $event) {
|
|
|
|
|
$sessions = $event->isMapadoEvent() == 'true' ? $event->remoteSessions() : $event->sessions();
|
|
|
|
|
|
|
|
|
|
$isStillShowing = false;
|
|
|
|
|
|
|
|
|
|
foreach ($sessions->toStructure() as $session) {
|
2024-09-03 11:12:23 +02:00
|
|
|
$arraySession = createArraySession($event, $session);
|
2024-09-02 14:02:13 +02:00
|
|
|
$currentSeasonSessions[] = $arraySession;
|
2024-08-28 19:11:58 +02:00
|
|
|
$sessionDate = str_replace('-', '', $session->date()->toDate('YMMdd'));
|
|
|
|
|
|
|
|
|
|
if ($sessionDate >= $today) {
|
|
|
|
|
$isStillShowing = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($isStillShowing) {
|
|
|
|
|
$nextEvents->add($event);
|
|
|
|
|
} else {
|
|
|
|
|
$previousEvents->add($event);
|
2024-08-30 14:37:13 +02:00
|
|
|
}
|
2024-08-28 19:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'previousEvents' => $previousEvents,
|
2024-08-30 14:37:13 +02:00
|
|
|
'nextEvents' => $nextEvents,
|
2024-09-04 13:43:27 +02:00
|
|
|
'currentSeasonSessions' => sortByMonth($currentSeasonSessions)
|
2024-08-28 19:11:58 +02:00
|
|
|
];
|
|
|
|
|
};
|