Re-add ability to display upcoming and only previous talks

This commit is contained in:
Oliver Davies 2017-10-28 09:08:34 +01:00
parent 97050c7f29
commit b1ee4887b5
3 changed files with 31 additions and 12 deletions

View file

@ -8,12 +8,20 @@ use: [talks]
{% block content %}
<p>I regularly speak at conferences and user groups about a range of subjects including Drupal, Sculpin and Git. If you would like to me to speak at your group or conference, please <a href="{{ site.url }}/contact">get in touch</a>.</p>
{% set data = { talks: data.talks, events: site.events } %}
{% set upcoming_talks = data|format_talks(true) %}
{% if upcoming_talks %}
<h2>Upcoming Talks</h2>
{% include "talks-table" with { talks: upcoming_talks } %}
{% endif %}
<h2>Last 5 Talks</h2>
{% set data = { talks: data.talks, events: site.events } %}
{% include "talks-table" with {
talks: data|format_talks|slice(0,5)
talks: data|format_talks(false, true)|slice(0,5)
} %}
<p>Upcoming talks can be found in the <a href="{{ site.url }}/talks/archive">talks archive</a>.</p>
<p>All previous talks can be found in the <a href="{{ site.url }}/talks/archive">talks archive</a>.</p>
{% endblock %}

View file

@ -15,6 +15,6 @@ talks:
<p>Here are a list of my previous conference and user group talks:</p>
{% set data = { talks: data.talks|merge(page.talks), events: site.events } %}
{% include "talks-table" with { talks: data|format_talks } %}
{% include "talks-table" with { talks: data|format_talks(false, true) } %}
<p>Upcoming talks can be found on the <a href="{{ site.url }}/talks">talks page]</a>.</p>
<p>Upcoming talks can be found on the <a href="{{ site.url }}/talks">talks page</a>.</p>

View file

@ -17,22 +17,33 @@ class FormatTalksExtension extends Twig_Extension
];
}
public function formatTalks($data)
public function formatTalks($data, $onlyUpcoming = false, $onlyPrevious = false)
{
$event_data = $data['events'];
$talks = [];
foreach ($data['talks'] as $talk) {
foreach ($talk['events'] as $event) {
$event = array_merge($event, $event_data[$event['event']]);
foreach ($talk['events'] as $event) {
$event = array_merge($event, $event_data[$event['event']]);
$talks[] = compact('talk', 'event');
}
$talks[] = compact('talk', 'event');
}
}
$today = (new \DateTime())->format('Y-m-d');
return collect($talks)
->sortByDesc('event.date')
->all();
->filter(function ($talk) use ($today, $onlyPrevious, $onlyUpcoming) {
if ($onlyUpcoming) {
return $talk['event']['date'] > $today;
}
if ($onlyPrevious) {
return $talk['event']['date'] < $today;
}
return true;
})->sortByDesc('event.date')->all();
}
/**