2020-06-30 12:50:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-08-24 09:26:44 +01:00
|
|
|
namespace Drupal\opdavies_talks\Service;
|
2020-06-30 12:50:21 +01:00
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2021-02-10 02:30:10 +00:00
|
|
|
use Drupal\opdavies_talks\Repository\TalkRepository;
|
2020-06-30 12:50:21 +01:00
|
|
|
use Drupal\paragraphs\ParagraphInterface;
|
|
|
|
|
|
|
|
final class TalkCounter {
|
|
|
|
|
2021-02-10 02:30:10 +00:00
|
|
|
private TalkRepository $talkRepository;
|
2020-06-30 12:50:21 +01:00
|
|
|
|
2021-02-10 02:30:10 +00:00
|
|
|
public function __construct(TalkRepository $talkRepository) {
|
|
|
|
$this->talkRepository = $talkRepository;
|
2020-06-30 12:50:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCount(): int {
|
|
|
|
$today = Carbon::today()->format('Y-m-d H:i:s');
|
|
|
|
|
2021-02-10 02:30:10 +00:00
|
|
|
return $this->talkRepository
|
|
|
|
->findAllPublished()
|
2021-02-10 07:54:43 +00:00
|
|
|
->getEvents()
|
|
|
|
->filter(fn(ParagraphInterface $event) => $event->get('field_date')
|
|
|
|
->getString() <= $today)
|
2020-06-30 12:50:21 +01:00
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|