26 lines
598 B
PHP
26 lines
598 B
PHP
<?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) : '';
|
|
}
|
|
}
|