add functionality
All checks were successful
build / build (pull_request) Successful in 5m29s

This commit is contained in:
Constantin Simonis 2025-02-15 15:29:48 +01:00
parent deeadda315
commit bfe3ea37b5
Signed by: csimonis
GPG Key ID: 3878FF77C24AF4D2
5 changed files with 57 additions and 6 deletions

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controller\Admin;
use App\Repository\TicketRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class CheckinAction extends AbstractController
{
public function __construct(
private TicketRepository $ticketRepository,
private EntityManagerInterface $entityManager,
) {
}
#[Route(path: '/admin/checkin', name: 'admin_checkin', methods: Request::METHOD_POST)]
public function __invoke(Request $request): Response
{
$entityId = $request->query->get('entityId');
if (!$entityId || !$ticket = $this->ticketRepository->findOneById($entityId)) {
noty()->error('Ein Fehler ist aufgetreten.');
return $this->redirect($request->get('referer'));
}
$ticket->setCheckedIn(true);
$this->entityManager->flush();
return $this->redirect($request->headers->get('referer'));
}
}

View File

@ -34,7 +34,8 @@ class TicketCrudController extends AbstractCrudController
->formatValue(fn(Customer $customer) => $customer->getEmail()) ->formatValue(fn(Customer $customer) => $customer->getEmail())
->hideOnForm(); ->hideOnForm();
yield BooleanField::new('checkedIn', '')->setTemplatePath('admin/checked_in.html.twig'); yield BooleanField::new('checkedIn', '')
->setTemplatePath('admin/checked_in.html.twig');
} }

View File

@ -9,6 +9,7 @@ use Doctrine\Persistence\ManagerRegistry;
/** /**
* @extends ServiceEntityRepository<Ticket> * @extends ServiceEntityRepository<Ticket>
* @method Ticket|null findOneById(int $entityId)
*/ */
class TicketRepository extends ServiceEntityRepository class TicketRepository extends ServiceEntityRepository
{ {

View File

@ -2,6 +2,7 @@
namespace App\Twig; namespace App\Twig;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TwigFunction; use Twig\TwigFunction;
@ -9,11 +10,22 @@ class Environment extends AbstractExtension
{ {
public function getFunctions(): array public function getFunctions(): array
{ {
return [new TwigFunction('env', $this->getVar(...))]; return [
new TwigFunction('env', $this->getVar(...)),
new TwigFunction('entityId', $this->getEntityId(...)),
];
} }
public function getVar(string $name): string public function getVar(string $name): string
{ {
return $_ENV[$name]; return $_ENV[$name];
} }
public function getEntityId(FieldDto $field): string
{
$url = $field->getCustomOption('toggleUrl');
preg_match('/entityId=(\d+)/', $url, $matches);
return $matches[1];
}
} }

View File

@ -1,6 +1,7 @@
{% if not field.value %} {% if not field.value %}
<button data-controller="checkin" data-id="">Einchecken</button> <form action="{{ path('admin_checkin', {'entityId': entityId(field)}) }}" method="post">
{{ dump(field) }} <button type="submit">Einchecken</button>
</form>
{% else %} {% else %}
<button disabled>Eingechecked</button> <button disabled>Eingecheckt</button>
{% endif %} {% endif %}