program > calendar : fix months sorting

This commit is contained in:
isUnknown 2025-08-01 16:15:26 +02:00
parent 881f384e22
commit 79f754466b

View file

@ -1,37 +1,45 @@
<?php
function sortByMonth($sessions) {
$frenchMonths = array(
$frenchMonths = [
'janvier', 'février', 'mars', 'avril', 'mai', 'juin',
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
);
$englishMonths = array(
];
$englishMonths = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
);
];
$currentMonthIndex = date('n') - 1;
$grouped = [];
$orderedSessions = [];
foreach ($sessions as $item) {
$monthIndex = date('n', strtotime($item['date'])) - 1;
$month = date('F', strtotime($item['date']));
$monthInFrench = str_replace($englishMonths, $frenchMonths, $month);
if ($monthIndex >= $currentMonthIndex || $monthIndex < 8) {
$month = date('F', strtotime($item['date']));
$monthInFrench = str_replace($englishMonths, $frenchMonths, $month);
// Décalage pour commencer par septembre (index 8)
$shiftedIndex = ($monthIndex + 12 - 8) % 12;
if (!isset($orderedSessions[$monthInFrench])) {
$orderedSessions[$monthInFrench] = [];
}
$orderedSessions[$monthInFrench][] = $item;
if (!isset($grouped[$shiftedIndex])) {
$grouped[$shiftedIndex] = ['name' => $monthInFrench, 'sessions' => []];
}
$grouped[$shiftedIndex]['sessions'][] = $item;
}
ksort($grouped); // Trie en commençant par septembre
$orderedSessions = [];
foreach ($grouped as $month) {
$orderedSessions[$month['name']] = $month['sessions'];
}
return $orderedSessions;
}
function createArraySession($event, $session) {
$isMapadoEvent = $event->isMapadoEvent() == 'true';
$arraySession = $session->toArray();