Rename and re-organise custom modules
- Rename `opd_talks` to `opdavies_talks` - Rename `custom` to `opdavies_blog`
This commit is contained in:
parent
e4e898f22c
commit
9b1a8fb3be
53 changed files with 125 additions and 116 deletions
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opdavies_talks\Service;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\paragraphs\ParagraphInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
final class TalkCounter {
|
||||
|
||||
private EntityStorageInterface $nodeStorage;
|
||||
|
||||
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
|
||||
$this->nodeStorage = $entityTypeManager->getStorage('node');
|
||||
}
|
||||
|
||||
public function getCount(): int {
|
||||
$today = Carbon::today()->format('Y-m-d H:i:s');
|
||||
|
||||
return $this->getTalks()
|
||||
->flatMap->getEvents()
|
||||
->filter(fn(ParagraphInterface $event) => $event->get('field_date')->getString() <= $today)
|
||||
->count();
|
||||
}
|
||||
|
||||
private function getTalks(): Collection {
|
||||
$talks = $this->nodeStorage->loadByProperties([
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
'type' => 'talk',
|
||||
]);
|
||||
|
||||
return new Collection($talks);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue