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

27 lines
690 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-10 20:47:23 +01:00
use Drupal\paragraphs\Entity\Paragraph;
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,
callback: fn (Paragraph $event): bool => $event->get('field_date')->value < $today,
2025-06-10 20:47:23 +01:00
));
}
}