2025-06-10 20:47:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Drupal\opd_presentations\Entity;
|
|
|
|
|
2025-06-10 20:47:23 +01:00
|
|
|
use Drupal\Core\Datetime\DrupalDateTime;
|
2025-06-10 20:47:23 +01:00
|
|
|
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;
|
2025-06-10 20:47:23 +01:00
|
|
|
|
|
|
|
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
|
|
|
));
|
2025-06-10 20:47:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|