Remove custom Twig extensions
Go back to calculating the talk count inline and using a macro to get the number of years experience.
This commit is contained in:
parent
c4ac4a8d3f
commit
94a4190be6
14 changed files with 1659 additions and 1871 deletions
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Experience;
|
||||
|
||||
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class ExperienceTwigExtension extends AbstractExtension
|
||||
{
|
||||
private static $startYear = 2007;
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('get_years_of_experience', [$this, 'getYearsOfExperience']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'experience';
|
||||
}
|
||||
|
||||
public function getYearsOfExperience(): int
|
||||
{
|
||||
return (new \DateTimeImmutable())->format('Y') - self::$startYear;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Presentations;
|
||||
|
||||
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class PresentationTwigExtension extends AbstractExtension
|
||||
{
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('get_presentation_count', [$this, 'getPresentationCount']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'presentations';
|
||||
}
|
||||
|
||||
public function getPresentationCount(array $presentations): int
|
||||
{
|
||||
$today = (new \DateTime('today'))->getTimestamp();
|
||||
|
||||
return collect($presentations)
|
||||
->flatMap(fn (ProxySourceItem $presentation) => $presentation->data()->get('events'))
|
||||
->filter(
|
||||
function (array $event) use ($today): bool {
|
||||
assert(array_key_exists(array: $event, key: 'date'));
|
||||
|
||||
return $event['date'] < $today;
|
||||
}
|
||||
)
|
||||
->count();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue