refactor: Remove the sortable_date for talks

Automatically calculate the sortable date for a talk using the event
dates. This means that the `sortable_date` in the YAML front matter can
be removed.

Fixes #4
This commit is contained in:
Oliver Davies 2021-09-08 23:47:14 +01:00
parent 42e0ae1297
commit efbd099515
36 changed files with 30 additions and 34 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\TwigExtension;
use App\Collection\TalkCollection;
use Illuminate\Support\Collection;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@ -13,10 +14,18 @@ final class TalkExtension extends AbstractExtension
public function getFunctions()
{
return [
new TwigFunction('get_last_event_date_for_talk', [$this, 'getLastEventDate']),
new TwigFunction('get_past_talk_count', [$this, 'getPastTalkCount']),
];
}
public function getLastEventDate($talk): ?string
{
$events = new Collection($talk['events']);
return $events->pluck('date')->sort()->last();
}
public function getPastTalkCount(iterable $talks = []): int
{
return $this->getEventsFromTalks($talks)->count();