refactor: move into a website directory

This commit is contained in:
Oliver Davies 2022-07-13 18:09:09 +01:00
parent 86529d7148
commit 3c5c0e808a
747 changed files with 133 additions and 2 deletions

View file

@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Collection;
use Carbon\Carbon;
use Illuminate\Support\Collection;
/**
* @template TKey of array-key
* @template TValue
*/
final class TalkCollection extends Collection
{
private const DATE_FORMAT = 'Y-m-d';
private const KEY_EVENTS = 'events';
private const KEY_EVENT_DATE = 'date';
/**
* @return self<TKey, TValue>
*/
public function getEvents(): self
{
return $this->flatMap(fn($talk): array => (array) $talk[self::KEY_EVENTS]);
}
/**
* @return self<TKey, TValue>
*/
public function onlyPastTalks(): self
{
$today = Carbon::today()->format(self::DATE_FORMAT);
return $this->filter(fn(array $event): bool => $event[self::KEY_EVENT_DATE] < $today);
}
}

View file

@ -1,59 +0,0 @@
<?php
declare(strict_types=1);
namespace App\TwigExtension;
use App\Collection\TalkCollection;
use Illuminate\Support\Collection;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* @template TKey of array-key
* @template TValue
*/
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']),
];
}
/**
* @param TValue $talk
*/
public function getLastEventDate($talk): ?string
{
return Collection::make($talk['events'])
->pluck('date')
->sort()
->last();
}
/**
* @param iterable<int, TValue> $talks
*/
public function getPastTalkCount(iterable $talks = []): int
{
return $this->getEventsFromTalks($talks)->count();
}
/**
* @param iterable<int, TValue> $talks
*
* @return TalkCollection<int, TValue>
*/
private function getEventsFromTalks(iterable $talks): TalkCollection
{
$talkCollection = new TalkCollection($talks);
return $talkCollection
->getEvents()
->onlyPastTalks();
}
}