diff --git a/source/talks.html.twig b/source/talks.html.twig index 9d420c2b..eb768736 100644 --- a/source/talks.html.twig +++ b/source/talks.html.twig @@ -28,7 +28,7 @@ talks: {% set talks = getTalks(page.talks|merge(data.talks)) %}
-

After giving my first talk in September 2012, I have now given {{ talks|events|pastEvents|length }} presentations at various conferences and meetups, on topics including PHP, Drupal, Git, CSS and systems administration.

+

After giving my first talk in September 2012, I have now given {{ talks|pastEvents|length }} presentations at various conferences and meetups, on topics including PHP, Drupal, Git, CSS and systems administration.

diff --git a/src/Talks/src/TwigExtension/TalksExtension.php b/src/Talks/src/TwigExtension/TalksExtension.php index e00d8f2b..bb485d0e 100644 --- a/src/Talks/src/TwigExtension/TalksExtension.php +++ b/src/Talks/src/TwigExtension/TalksExtension.php @@ -30,14 +30,12 @@ class TalksExtension extends AbstractExtension { return [ new TwigFunction('getTalks', [$this, 'getTalks']), - new TwigFunction('getEvents', [$this, 'getEvents']), ]; } public function getFilters() { return [ - new TwigFilter('events', [$this, 'getEvents']), new TwigFilter('pastEvents', [$this, 'filterPastEvents']), new TwigFilter('pastTalks', [$this, 'filterPastTalks']), new TwigFilter('upcomingEvents', [$this, 'filterUpcomingEvents']), @@ -67,13 +65,6 @@ class TalksExtension extends AbstractExtension }); } - public function getEvents($talks): Collection - { - return collect($talks)->flatMap(function ($talk): array { - return $talk['events']; - }); - } - public function filterUpcomingTalks(Collection $talks): array { return $talks->filter(function ($talk): bool { @@ -90,21 +81,28 @@ class TalksExtension extends AbstractExtension private function getLastDate($talk): string { - return $this->getEvents(collect([$talk])) + return $this->eventsFromTalks(collect([$talk])) ->pluck('date')->max(); } - public function filterUpcomingEvents(Collection $events): array + public function filterUpcomingEvents($talks): array { - return $events->filter(function ($event): bool { + return $this->eventsFromTalks($talks)->filter(function ($event): bool { return $event['date'] >= $this->today; })->sortBy('date')->toArray(); } - public function filterPastEvents(Collection $events): array + public function filterPastEvents($talks): array { - return $events->filter(function ($event): bool { + return $this->eventsFromTalks($talks)->filter(function ($event): bool { return $event['date'] < $this->today; })->sortBy('date')->toArray(); } + + private function eventsFromTalks($talks): Collection + { + return collect($talks)->flatMap(function ($talk): array { + return $talk['events']; + }); + } }