diff --git a/src/Talks/src/TwigExtension/TalksExtension.php b/src/Talks/src/TwigExtension/TalksExtension.php index 651a633a..7b418c68 100644 --- a/src/Talks/src/TwigExtension/TalksExtension.php +++ b/src/Talks/src/TwigExtension/TalksExtension.php @@ -30,13 +30,13 @@ 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('past', [$this, 'filterPast']), new TwigFilter('upcoming', [$this, 'filterUpcoming']), ]; @@ -65,9 +65,9 @@ class TalksExtension extends AbstractExtension } - public function getEvents(Collection $talks): Collection + public function getEvents($talks): Collection { - return $talks->flatMap(function ($talk): array { + return collect($talks)->flatMap(function ($talk): array { return $talk['events']; }); } diff --git a/src/Talks/tests/RetrievingEventsTest.php b/src/Talks/tests/RetrievingEventsTest.php new file mode 100644 index 00000000..a51ec056 --- /dev/null +++ b/src/Talks/tests/RetrievingEventsTest.php @@ -0,0 +1,54 @@ +extension = new TalksExtension(); + } + + /** @test */ + public function getting_all_events() + { + $talkA = [ + 'title' => 'Talk A', + 'events' => [ + [ + 'event' => 'event_a', + 'date' => (new DateTime('-1 days'))->getTimestamp() + ], + [ + 'event' => 'event_b', + 'date' => (new DateTime('+1 days'))->getTimestamp() + ], + ], + ]; + + $talkB = [ + 'title' => 'Talk B', + 'events' => [ + [ + 'event' => 'event_a', + 'date' => (new DateTime('-3 days'))->getTimestamp() + ], + ], + ]; + + $this->assertCount(3, $this->extension->getEvents([$talkA, $talkB])); + } +}