Remove events filter, make method private
This commit is contained in:
parent
b7352e2fe9
commit
54fd609c5b
|
@ -28,7 +28,7 @@ talks:
|
||||||
{% set talks = getTalks(page.talks|merge(data.talks)) %}
|
{% set talks = getTalks(page.talks|merge(data.talks)) %}
|
||||||
|
|
||||||
<header class="mb-6">
|
<header class="mb-6">
|
||||||
<p class="text-lg">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.</p>
|
<p class="text-lg">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.</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="spaced-y-10">
|
<div class="spaced-y-10">
|
||||||
|
|
|
@ -30,14 +30,12 @@ class TalksExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFunction('getTalks', [$this, 'getTalks']),
|
new TwigFunction('getTalks', [$this, 'getTalks']),
|
||||||
new TwigFunction('getEvents', [$this, 'getEvents']),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFilter('events', [$this, 'getEvents']),
|
|
||||||
new TwigFilter('pastEvents', [$this, 'filterPastEvents']),
|
new TwigFilter('pastEvents', [$this, 'filterPastEvents']),
|
||||||
new TwigFilter('pastTalks', [$this, 'filterPastTalks']),
|
new TwigFilter('pastTalks', [$this, 'filterPastTalks']),
|
||||||
new TwigFilter('upcomingEvents', [$this, 'filterUpcomingEvents']),
|
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
|
public function filterUpcomingTalks(Collection $talks): array
|
||||||
{
|
{
|
||||||
return $talks->filter(function ($talk): bool {
|
return $talks->filter(function ($talk): bool {
|
||||||
|
@ -90,21 +81,28 @@ class TalksExtension extends AbstractExtension
|
||||||
|
|
||||||
private function getLastDate($talk): string
|
private function getLastDate($talk): string
|
||||||
{
|
{
|
||||||
return $this->getEvents(collect([$talk]))
|
return $this->eventsFromTalks(collect([$talk]))
|
||||||
->pluck('date')->max();
|
->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;
|
return $event['date'] >= $this->today;
|
||||||
})->sortBy('date')->toArray();
|
})->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;
|
return $event['date'] < $this->today;
|
||||||
})->sortBy('date')->toArray();
|
})->sortBy('date')->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function eventsFromTalks($talks): Collection
|
||||||
|
{
|
||||||
|
return collect($talks)->flatMap(function ($talk): array {
|
||||||
|
return $talk['events'];
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue