Add TalkCollection, move logic for getting events
Add a `TalkCollection` which extends Laravel/Tighten's, and add a method there for getting the events from the talks. This makes this logic more reusable and also makes the code in the `TalkCounter` service simpler.
This commit is contained in:
parent
1f0926ac16
commit
0c1321fed5
3 changed files with 30 additions and 15 deletions
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace Drupal\opdavies_talks\Service;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Drupal\opdavies_talks\Entity\Node\Talk;
|
||||
use Drupal\opdavies_talks\Repository\TalkRepository;
|
||||
use Drupal\paragraphs\ParagraphInterface;
|
||||
|
||||
|
@ -22,8 +21,9 @@ final class TalkCounter {
|
|||
|
||||
return $this->talkRepository
|
||||
->findAllPublished()
|
||||
->flatMap(fn(Talk $talk) => $talk->getEvents())
|
||||
->filter(fn(ParagraphInterface $event) => $event->get('field_date')->getString() <= $today)
|
||||
->getEvents()
|
||||
->filter(fn(ParagraphInterface $event) => $event->get('field_date')
|
||||
->getString() <= $today)
|
||||
->count();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue