Re-add ability to display upcoming and only previous talks
This commit is contained in:
parent
97050c7f29
commit
b1ee4887b5
|
@ -8,12 +8,20 @@ use: [talks]
|
||||||
{% block content %}
|
{% 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>
|
<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>
|
<h2>Last 5 Talks</h2>
|
||||||
|
|
||||||
{% set data = { talks: data.talks, events: site.events } %}
|
|
||||||
{% include "talks-table" with {
|
{% 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 %}
|
{% endblock %}
|
||||||
|
|
|
@ -15,6 +15,6 @@ talks:
|
||||||
<p>Here are a list of my previous conference and user group talks:</p>
|
<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 } %}
|
{% 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>
|
||||||
|
|
|
@ -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'];
|
$event_data = $data['events'];
|
||||||
|
|
||||||
$talks = [];
|
$talks = [];
|
||||||
foreach ($data['talks'] as $talk) {
|
foreach ($data['talks'] as $talk) {
|
||||||
foreach ($talk['events'] as $event) {
|
foreach ($talk['events'] as $event) {
|
||||||
$event = array_merge($event, $event_data[$event['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)
|
return collect($talks)
|
||||||
->sortByDesc('event.date')
|
->filter(function ($talk) use ($today, $onlyPrevious, $onlyUpcoming) {
|
||||||
->all();
|
if ($onlyUpcoming) {
|
||||||
|
return $talk['event']['date'] > $today;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($onlyPrevious) {
|
||||||
|
return $talk['event']['date'] < $today;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
})->sortByDesc('event.date')->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in a new issue