Add EventPage model with sortedDates method

This commit is contained in:
isUnknown 2026-05-06 11:12:54 +02:00
parent 020abbfe66
commit 03099845a8

26
site/models/event.php Normal file
View file

@ -0,0 +1,26 @@
<?php
class EventPage extends Page
{
public function sortedDates(): array
{
$groups = array_values($this->dates()->toStructure()->data());
usort($groups, fn($a, $b) => strcmp(
$this->firstDateOf($a),
$this->firstDateOf($b)
));
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) : '';
}
}