nouveau-theatre-de-besancon/site/controllers/program.php

72 lines
2.1 KiB
PHP
Raw Normal View History

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-09-02 14:02:13 +02:00
$arraySession = $session->toArray();
$arraySession['title'] = $event->title()->value();
$arraySession['authors'] = $event->authors();
$arraySession['place'] = $event->place();
$arraySession['duration'] = $event->isMapadoEvent() == 'true' ? $event->remoteDuration() : $event->duration();
$arraySession['ticketingUrl'] = '';
2024-09-02 16:32:21 +02:00
$arraySession['bookableStock'] = $event->isMapadoEvent() == 'true' ? $session->bookableStock()->value() : 'free';
$arraySession['color'] = $event->color();
2024-09-02 14:02:13 +02:00
$currentSeasonSessions[] = $arraySession;
2024-08-30 14:37:13 +02:00
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,
'currentSeasonSessions' => sortByMonth($currentSeasonSessions)
2024-08-28 19:11:58 +02:00
];
};