This commit is contained in:
Constantin Simonis 2025-02-06 19:46:21 +01:00
parent 8acd712e0b
commit d7b926a205
Signed by: csimonis
GPG Key ID: 3878FF77C24AF4D2
6 changed files with 102 additions and 7 deletions

View File

@ -4,11 +4,15 @@ namespace App\Controller\Admin;
use App\Entity\Customer;
use App\Entity\Payment;
use Doctrine\Common\Collections\Collection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
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\CollectionField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class CustomerCrudController extends AbstractCrudController
@ -22,12 +26,15 @@ class CustomerCrudController extends AbstractCrudController
{
yield TextField::new('firstname', 'Vorname');
yield TextField::new('lastname', 'Nachname');
yield TextField::new('email', 'E-Mail');
yield TextField::new('phone', 'Telefon');
yield AssociationField::new('payment', 'Zahlung')
yield EmailField::new('email', 'E-Mail');
yield TelephoneField::new('phone', 'Telefon');
yield AssociationField::new('payment', 'Total')
->setCrudController(PaymentCrudController::class)
->formatValue(fn(?Payment $payment) => ($payment?->getTotal() ?? 'N/A') . ' €');
yield
->formatValue(fn(?Payment $payment) => ($payment?->getTotal() ?? 0.0) . ' €')
->hideOnIndex();
yield CollectionField::new('tickets', 'Tickets')
->setTemplatePath('admin/customer_tickets.html.twig')
->hideOnIndex();
}
@ -39,4 +46,12 @@ class CustomerCrudController extends AbstractCrudController
->disable(Action::NEW)
->disable(Action::EDIT);
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setPageTitle(Crud::PAGE_INDEX, 'Kunden')
->setPageTitle(Crud::PAGE_DETAIL, 'Kunden')
->showEntityActionsInlined();
}
}

View File

@ -19,10 +19,10 @@ class PaymentCrudController extends AbstractCrudController
public function configureFields(string $pageName): iterable
{
yield AssociationField::new('customer', 'Customer')
yield AssociationField::new('customer', 'Kunde')
->setCrudController(CustomerCrudController::class)
->formatValue(fn($value, $payment) => $payment->getCustomer()->getEmail());
yield BooleanField::new('completed', 'Completed')->renderAsSwitch(false);
yield BooleanField::new('completed', 'Bezahlt')->renderAsSwitch(false);
}
public function configureActions(Actions $actions): Actions
@ -33,4 +33,11 @@ class PaymentCrudController extends AbstractCrudController
->disable(Action::NEW)
->disable(Action::EDIT);
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setPageTitle(Crud::PAGE_INDEX, 'Zahlungen')
->setPageTitle(Crud::PAGE_DETAIL, 'Zahlung');
}
}

View File

@ -42,4 +42,11 @@ class TicketCrudController extends AbstractCrudController
->disable(Action::NEW)
->disable(Action::EDIT);
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setPageTitle(Crud::PAGE_INDEX, 'Tickets')
->setPageTitle(Crud::PAGE_DETAIL, 'Ticket');
}
}

View File

@ -4,6 +4,12 @@ namespace App\Enum;
class FoodData
{
public const FOOD_DATA = [
1 => 'Mit Fleisch',
2 => 'Vegetarisch',
3 => 'Vegan'
];
public const TYPES = [
'Mit Fleisch' => 1,
'Vegetarisch' => 2,

31
src/Twig/Ticket.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace App\Twig;
use App\Enum\FoodData;
use App\Enum\TicketData;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
class Ticket extends AbstractExtension
{
public function getFilters(): array
{
return [
new TwigFilter('food', $this->getFoodName(...)),
new TwigFilter('ticket', $this->getTicket(...)),
];
}
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'];
}
}

View File

@ -0,0 +1,29 @@
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Ernährung</th>
<th>Preis</th>
<th></th>
</tr>
</thead>
<tbody>
{% for ticket in field.value %}
<tr>
<td>{{ (ticket.type | ticket)['name'] }}</td>
<td>{{ ticket.foodType | food }}</td>
<td>{{ (ticket.type | ticket)['price'] }}€</td>
<td>
<a href="{{ path('admin', { entity: 'App\Entity\Ticket', action: 'detail', id: ticket.id }) }}"
class="btn btn-info btn-sm">
View
</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="4" class="text-center">No Orders Found</td>
</tr>
{% endfor %}
</tbody>
</table>