2024-05-03 11:30:24 +00:00
|
|
|
<?php
|
|
|
|
|
2024-09-02 17:00:00 +00:00
|
|
|
namespace Modules\Presentations\TwigExtension;
|
2024-05-03 11:30:24 +00:00
|
|
|
|
2024-05-03 11:53:05 +00:00
|
|
|
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
2024-05-03 11:30:24 +00:00
|
|
|
use Twig\Extension\AbstractExtension;
|
|
|
|
use Twig\TwigFunction;
|
|
|
|
|
2024-09-02 17:00:00 +00:00
|
|
|
class PresentationTwigExtension extends AbstractExtension
|
2024-05-03 11:30:24 +00:00
|
|
|
{
|
|
|
|
public function getFunctions(): array
|
|
|
|
{
|
|
|
|
return [
|
2024-09-02 17:00:00 +00:00
|
|
|
new TwigFunction('get_presentation_count', [$this, 'getPresentationCount']),
|
2024-05-03 11:30:24 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(): string
|
|
|
|
{
|
2024-09-02 17:00:00 +00:00
|
|
|
return 'modules.presentations';
|
2024-05-03 11:30:24 +00:00
|
|
|
}
|
|
|
|
|
2024-09-02 17:00:00 +00:00
|
|
|
public function getPresentationCount(array $presentations): int
|
2024-05-03 11:53:05 +00:00
|
|
|
{
|
2024-08-01 20:08:20 +00:00
|
|
|
$today = (new \DateTime('today'))->getTimestamp();
|
2024-05-03 11:53:05 +00:00
|
|
|
|
2024-09-02 17:00:00 +00:00
|
|
|
return collect($presentations)
|
|
|
|
->flatMap(fn (ProxySourceItem $presentation) => $presentation->data()->get('events'))
|
2024-05-03 11:53:05 +00:00
|
|
|
->filter(
|
|
|
|
function (array $event) use ($today): bool {
|
|
|
|
assert(array_key_exists(array: $event, key: 'date'));
|
|
|
|
|
|
|
|
return $event['date'] < $today;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
->count();
|
|
|
|
}
|
2024-05-03 11:30:24 +00:00
|
|
|
}
|