program > calendar : fix months sorting
This commit is contained in:
parent
881f384e22
commit
79f754466b
1 changed files with 22 additions and 14 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue