oliverdavies.uk/modules/opd_presentations/src/Entity/Presentation.php

27 lines
679 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Drupal\opd_presentations\Entity;
2025-06-10 20:47:23 +01:00
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
2025-06-10 20:47:23 +01:00
use Drupal\opd_presentations\Collection\EventCollection;
2025-06-12 02:10:08 +01:00
use Drupal\opd_presentations\Entity\Event;
final class Presentation extends Node implements NodeInterface {
2025-06-10 20:47:23 +01:00
public function getPastEvents(): EventCollection {
2025-06-10 20:47:23 +01:00
$events = $this->get('field_events')->referencedEntities();
$today = (new DrupalDateTime('today'))->format('U');
2025-06-10 20:47:23 +01:00
return new EventCollection(array_filter(
2025-06-10 20:47:23 +01:00
array: $events,
2025-06-12 02:10:08 +01:00
callback: fn (Event $event): bool => $event->getEventDate() < $today,
2025-06-10 20:47:23 +01:00
));
}
}