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

89 lines
2.8 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) {
2024-09-16 16:28:12 +02:00
$currentMonth = date('F');
$frenchMonths = array(
2024-08-30 14:37:13 +02:00
'janvier', 'février', 'mars', 'avril', 'mai', 'juin',
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
);
2024-09-16 16:28:12 +02:00
$englishMonths = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$currentMonthIndex = date('n');
$frenchMonths = array_merge(
array_slice($frenchMonths, $currentMonthIndex - 1, 12),
array_slice($frenchMonths, 0, $currentMonthIndex - 1)
);
$englishMonths = array_merge(
array_slice($englishMonths, $currentMonthIndex - 1, 12),
array_slice($englishMonths, 0, $currentMonthIndex - 1)
);
2024-08-30 14:37:13 +02:00
$orderedSessions = array();
2024-09-16 16:28:12 +02:00
foreach ($frenchMonths as $month) {
2024-08-30 14:37:13 +02:00
$orderedSessions[$month] = array();
}
foreach ($sessions as $item) {
$month = date('F', strtotime($item['date']));
$month = str_replace(
2024-09-16 16:28:12 +02:00
$englishMonths,
$frenchMonths,
2024-08-30 14:37:13 +02:00
$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();
2024-09-12 15:39:44 +02:00
$arraySession['authors'] = $event->authors()->inline();
2024-09-03 11:12:23 +02:00
$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();
$arraySession['ticketingUrl'] = $isMapadoEvent ? $session->ticketingUrl()->value() : $event->bookingUrl()->value();
2024-09-03 11:12:23 +02:00
$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();
$arraySession['categories'] = $event->categories();
2024-09-03 11:12:23 +02:00
return $arraySession;
}
2024-09-13 16:44:50 +02:00
return function($kirby, $page) {
2024-08-28 19:11:58 +02:00
$currentSeason = $page->children()->first();
$today = date('Ymd');
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;
}
}
}
return [
2024-09-13 16:44:50 +02:00
'pastEvents' => filterPastEvents($kirby->collection('ordered-season')),
'futureEvents' => filterFutureEvents($kirby->collection('ordered-season')),
2024-09-04 13:43:27 +02:00
'currentSeasonSessions' => sortByMonth($currentSeasonSessions)
2024-08-28 19:11:58 +02:00
];
};