parent
3b8b099ae9
commit
1c4093922c
36
src/Controller/Admin/CheckinAction.php
Normal file
36
src/Controller/Admin/CheckinAction.php
Normal 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'));
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
|
||||
|
||||
class TicketCrudController extends AbstractCrudController
|
||||
@ -22,16 +23,19 @@ class TicketCrudController extends AbstractCrudController
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield ChoiceField::new('type', 'Name')
|
||||
yield ChoiceField::new('type', 'Typ')
|
||||
->setChoices(TicketData::TYPES);
|
||||
|
||||
yield ChoiceField::new('foodType', 'Ernährung')
|
||||
->setChoices(FoodData::TYPES);
|
||||
|
||||
yield AssociationField::new('customer', 'Kunde')
|
||||
yield AssociationField::new('customer', 'Käufer')
|
||||
->setCrudController(CustomerCrudController::class)
|
||||
->formatValue(fn(Customer $customer) => $customer->getEmail())
|
||||
->hideOnForm();
|
||||
|
||||
yield BooleanField::new('checkedIn', '')
|
||||
->setTemplatePath('admin/checked_in.html.twig');
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,6 +27,9 @@ class Ticket implements \Stringable
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Customer $customer = null;
|
||||
|
||||
#[ORM\Column(options: ['default' => false])]
|
||||
private ?bool $checkedIn = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@ -84,4 +87,16 @@ class Ticket implements \Stringable
|
||||
{
|
||||
return TicketData::TICKET_DATA[$this->type]['name'];
|
||||
}
|
||||
|
||||
public function isCheckedIn(): ?bool
|
||||
{
|
||||
return $this->checkedIn;
|
||||
}
|
||||
|
||||
public function setCheckedIn(bool $checkedIn): static
|
||||
{
|
||||
$this->checkedIn = $checkedIn;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Ticket>
|
||||
* @method Ticket|null findOneById(int $entityId)
|
||||
*/
|
||||
class TicketRepository extends ServiceEntityRepository
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
@ -9,11 +10,22 @@ class Environment extends AbstractExtension
|
||||
{
|
||||
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
|
||||
{
|
||||
return $_ENV[$name];
|
||||
}
|
||||
|
||||
public function getEntityId(FieldDto $field): string
|
||||
{
|
||||
$url = $field->getCustomOption('toggleUrl');
|
||||
preg_match('/entityId=(\d+)/', $url, $matches);
|
||||
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
7
templates/admin/checked_in.html.twig
Normal file
7
templates/admin/checked_in.html.twig
Normal file
@ -0,0 +1,7 @@
|
||||
{% if not field.value %}
|
||||
<form action="{{ path('admin_checkin', {'entityId': entityId(field)}) }}" method="post">
|
||||
<button type="submit">Einchecken</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<button disabled>Eingecheckt</button>
|
||||
{% endif %}
|
Loading…
x
Reference in New Issue
Block a user