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-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-08-30 14:37:13 +02:00
|
|
|
$currentSeasonSessions[] = $session->toArray();
|
|
|
|
|
|
2024-08-28 19:11:58 +02:00
|
|
|
$sessionDate = str_replace('-', '', $session->date()->toDate('YMMdd'));
|
|
|
|
|
|
|
|
|
|
if ($sessionDate >= $today) {
|
|
|
|
|
$isStillShowing = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
'currentSeasonSessions' => sortByMonth($currentSeasonSessions)
|
2024-08-28 19:11:58 +02:00
|
|
|
];
|
|
|
|
|
};
|