fix months order

This commit is contained in:
isUnknown 2024-09-16 16:28:12 +02:00
parent 3e6f00c387
commit 35d6587379
2 changed files with 22 additions and 6 deletions

View file

@ -1,22 +1,36 @@
<?php
function sortByMonth($sessions) {
$months = array(
$currentMonth = date('F');
$frenchMonths = array(
'janvier', 'février', 'mars', 'avril', 'mai', 'juin',
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
);
$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)
);
$orderedSessions = array();
foreach ($months as $month) {
foreach ($frenchMonths 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,
$englishMonths,
$frenchMonths,
$month
);
$orderedSessions[$month][] = $item;

View file

@ -82,7 +82,9 @@
<template x-if="tab.includes('Calendrier')">
<div class="program-content__events">
<section class="collapsable-sections">
<?php foreach($currentSeasonSessions as $month => $sessions): ?>
<?php
foreach($currentSeasonSessions as $month => $sessions): ?>
<?php if (count($sessions) > 0): ?>
<?php snippet('collapsable-section', ['title' => $month, 'padding' => false], slots: true) ?>
<?php slot('content') ?>
@ -95,7 +97,7 @@
try {
$endTime = strlen($session['duration']) > 0 ? getEndTime($session) : false;
} catch (\Throwable $th) {https://ntb-full.adrien-payet.fr/
} catch (\Throwable $th) {
throw new Exception($session['title'] .' - ' . $th->getMessage(), 1);
}
?>