46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Twig;
|
|
|
|
use App\Controller\Admin\TicketCrudController;
|
|
use App\Enum\FoodData;
|
|
use App\Enum\TicketData;
|
|
use chillerlan\QRCode\QRCode;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
use Twig\Extension\AbstractExtension;
|
|
use Twig\TwigFilter;
|
|
|
|
class Ticket extends AbstractExtension
|
|
{
|
|
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
|
|
{
|
|
}
|
|
|
|
public function getFilters(): array
|
|
{
|
|
return [
|
|
new TwigFilter('food', $this->getFoodName(...)),
|
|
new TwigFilter('ticket', $this->getTicket(...)),
|
|
new TwigFilter('qr', $this->generateUrl(...)),
|
|
];
|
|
}
|
|
|
|
public function getFoodName(int $id): string
|
|
{
|
|
return FoodData::FOOD_DATA[$id] ?? 'N/A';
|
|
}
|
|
|
|
public function getTicket(int $id): array
|
|
{
|
|
return TicketData::TICKET_DATA[$id] ?? ['name' => 'N/A', 'price' => 'N/A'];
|
|
}
|
|
|
|
public function generateUrl(\App\Entity\Ticket $ticket): string
|
|
{
|
|
return (new QRCode)->render($this->urlGenerator->generate('admin', [
|
|
'crudAction' => 'detail',
|
|
'crudControllerFqcn' => TicketCrudController::class,
|
|
'entityId' => $ticket->getCustomer()?->getId()
|
|
], UrlGeneratorInterface::ABSOLUTE_URL));
|
|
}
|
|
} |