Switch dates to from/to range, sort by most recent end date

This commit is contained in:
isUnknown 2026-05-06 11:21:41 +02:00
parent 03099845a8
commit 7e6854da22
2 changed files with 16 additions and 22 deletions

View file

@ -35,19 +35,23 @@ tabs:
columns:
name:
width: 1/2
dates:
width: 1/2
from:
width: 1/4
to:
width: 1/4
fields:
name:
label: Lieu
placeholder: Théâtre-Sénart, Scène Nationale, Lieusaint
type: text
dates:
label: Dates
type: structure
fields:
date:
label: Date
type: date
display: DD/MM/YYYY
from:
label: Du
type: date
display: DD/MM/YYYY
width: 1/2
to:
label: Au
type: date
display: DD/MM/YYYY
width: 1/2
files: tabs/files

View file

@ -7,20 +7,10 @@ class EventPage extends Page
$groups = array_values($this->dates()->toStructure()->data());
usort($groups, fn($a, $b) => strcmp(
$this->firstDateOf($a),
$this->firstDateOf($b)
$b->to()->value() ?? '',
$a->to()->value() ?? ''
));
return $groups;
}
private function firstDateOf($group): string
{
$dates = array_filter(array_map(
fn($item) => $item->date()->value(),
array_values($group->dates()->toStructure()->data())
));
return !empty($dates) ? min($dates) : '';
}
}