Extend the collection usage
This commit is contained in:
parent
dbbfac0283
commit
0063bcffc5
|
@ -16,21 +16,21 @@ class FormatTalksExtension extends \Twig_Extension
|
||||||
|
|
||||||
public function formatTalks($data, $onlyUpcoming = false, $onlyPrevious = false)
|
public function formatTalks($data, $onlyUpcoming = false, $onlyPrevious = false)
|
||||||
{
|
{
|
||||||
$event_data = $data['events'];
|
$events = collect($data['events']);
|
||||||
|
|
||||||
$talks = [];
|
|
||||||
foreach ($data['talks'] as $talk) {
|
|
||||||
foreach ($talk['events'] as $event) {
|
|
||||||
$event = array_merge($event, $event_data[$event['event']]);
|
|
||||||
|
|
||||||
$talks[] = compact('talk', 'event');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$today = (new \DateTime())->format('Y-m-d');
|
$today = (new \DateTime())->format('Y-m-d');
|
||||||
|
|
||||||
return collect($talks)
|
return collect($data['talks'])->map(function ($talk) use ($events) {
|
||||||
->filter(function ($talk) use ($today, $onlyPrevious, $onlyUpcoming) {
|
// Build an associative array with the talk, as well as the
|
||||||
|
// specified event data (e.g. date and time) as well as the shared
|
||||||
|
// event data (e.g. event name and website).
|
||||||
|
return collect($talk['events'])->map(function ($event) use ($talk, $events) {
|
||||||
|
$event = collect($event);
|
||||||
|
$event = $event->merge($events->get($event->get('event')));
|
||||||
|
|
||||||
|
return compact('event', 'talk');
|
||||||
|
});
|
||||||
|
})->flatten(1)->filter(function ($talk) use ($today, $onlyPrevious, $onlyUpcoming) {
|
||||||
if ($onlyUpcoming) {
|
if ($onlyUpcoming) {
|
||||||
return $talk['event']['date'] > $today;
|
return $talk['event']['date'] > $today;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue