Refactor
This commit is contained in:
parent
c184f79f8a
commit
9308ce76a5
2 changed files with 9 additions and 5 deletions
|
@ -15,6 +15,13 @@ readonly final class Events implements \IteratorAggregate {
|
||||||
private function __construct(private array $events) {
|
private function __construct(private array $events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function filter(\Closure $callback): self {
|
||||||
|
return new self(array_filter(
|
||||||
|
array: $this->events,
|
||||||
|
callback: $callback,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function first(): Event {
|
public function first(): Event {
|
||||||
return array_values($this->events)[0];
|
return array_values($this->events)[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,11 @@ final class Presentation extends Node implements NodeInterface {
|
||||||
public const NODE_TYPE = 'presentation';
|
public const NODE_TYPE = 'presentation';
|
||||||
|
|
||||||
public function getPastEvents(): Events {
|
public function getPastEvents(): Events {
|
||||||
$events = $this->get('field_events')->referencedEntities();
|
$events = Events::new($this->get('field_events')->referencedEntities());
|
||||||
|
|
||||||
$today = strtotime('today');
|
$today = strtotime('today');
|
||||||
|
|
||||||
return Events::new(array_filter(
|
return $events->filter(fn (Event $event) => $event->getEventDate() < $today);
|
||||||
array: $events,
|
|
||||||
callback: fn (Event $event): bool => $event->getEventDate() < $today,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue