Move all files to sculpin/
This commit is contained in:
parent
c5d71803a5
commit
0f61b4e9ee
1514 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Experience\TwigExtension;
|
||||
|
||||
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class ExperienceTwigExtension extends AbstractExtension
|
||||
{
|
||||
private static int $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 (int) (new \DateTimeImmutable())->format('Y') - self::$startYear;
|
||||
}
|
||||
}
|
||||
55
sculpin/src/Presentation/Collection/Collection.php
Normal file
55
sculpin/src/Presentation/Collection/Collection.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presentation\Collection;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Iterator;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* @implements IteratorAggregate<TItem>
|
||||
* @template TItem
|
||||
*/
|
||||
class Collection implements Countable, IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @param TItem[] $items
|
||||
*/
|
||||
final public function __construct(protected array $items = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self<TItem>
|
||||
*/
|
||||
public function filter(callable $callback): self
|
||||
{
|
||||
return new static(
|
||||
array_filter(
|
||||
array: $this->items,
|
||||
callback: $callback,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getIterator(): Iterator
|
||||
{
|
||||
return new ArrayIterator($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TItem[]
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presentation\Collection;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
||||
|
||||
/**
|
||||
* @extends Collection<ProxySourceItem>
|
||||
*/
|
||||
final class PresentationCollection extends Collection
|
||||
{
|
||||
/**
|
||||
* @return Collection<ProxySourceItem>
|
||||
*/
|
||||
public function getAllEvents(): Collection
|
||||
{
|
||||
$events = array_reduce(
|
||||
array: $this->items,
|
||||
callback: function (array $events, ProxySourceItem $presentation): array {
|
||||
$events[] = $presentation->data()->get('events');
|
||||
|
||||
return $events;
|
||||
},
|
||||
initial: [],
|
||||
);
|
||||
|
||||
return new Collection(array_merge(...$events));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<ProxySourceItem>
|
||||
*/
|
||||
public function getPastEvents(): Collection
|
||||
{
|
||||
$today = new DateTimeImmutable('today');
|
||||
|
||||
return $this->getAllEvents()
|
||||
->filter(fn(array $event) => $event['date'] < $today->getTimestamp());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Presentation\TwigExtension;
|
||||
|
||||
use App\Presentation\Collection\PresentationCollection;
|
||||
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';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ProxySourceItem[] $presentations
|
||||
*/
|
||||
public function getPresentationCount(array $presentations): int
|
||||
{
|
||||
$presentationCollection = new PresentationCollection($presentations);
|
||||
|
||||
return $presentationCollection->getPastEvents()->count();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue