program - show events without sessions at the end of next events #18

This commit is contained in:
isUnknown 2024-11-08 16:32:47 +01:00
parent 9c55ee0e5d
commit 881f384e22
2 changed files with 21 additions and 17 deletions

View file

@ -22,24 +22,24 @@ function getMonthNumber($month) {
function splitNextAndPreviousEvents($events) {
$next = new Pages();
$previous = new Pages();
$noDateEvents = new Pages();
foreach ($events as $event) {
$sessions = $event->isMapadoEvent() == 'true' ? $event->remoteSessions()->toStructure() : $event->sessions()->toStructure();
$sessionDates = $sessions->map(function($session) {
return $session->date()->value();
})->data;
if (empty($sessionDates)) {
$noDateEvents->add($event);
continue;
}
$futureDates = array_filter($sessionDates, function ($date) {
// strtotime() gives the timestamp for midnight
// time() gives the current timestamp so if the event occurs today it will be considered as past after midnight
// so we need to add a day, in seconds
$oneDayInSecond = 24*60*60;
$oneDayInSecond = 24 * 60 * 60;
$dateTimeStamp = strtotime($date) + $oneDayInSecond;
return $dateTimeStamp >= time();
});
if (!empty($futureDates)) {
$next->add($event);
@ -48,12 +48,15 @@ function splitNextAndPreviousEvents($events) {
}
}
$next = $next->merge($noDateEvents);
return [
'next' => $next,
'previous' => $previous,
];
}
function buildFieldsString($requestFields) {
$fields = [];
foreach ($requestFields as $field) {