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