Add EventPage model with sortedDates method
This commit is contained in:
parent
020abbfe66
commit
03099845a8
1 changed files with 26 additions and 0 deletions
26
site/models/event.php
Normal file
26
site/models/event.php
Normal 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) : '';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue