refactor
This commit is contained in:
parent
8acd712e0b
commit
d7b926a205
@ -4,11 +4,15 @@ namespace App\Controller\Admin;
|
|||||||
|
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
use App\Entity\Payment;
|
use App\Entity\Payment;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
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;
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||||
|
|
||||||
class CustomerCrudController extends AbstractCrudController
|
class CustomerCrudController extends AbstractCrudController
|
||||||
@ -22,12 +26,15 @@ class CustomerCrudController extends AbstractCrudController
|
|||||||
{
|
{
|
||||||
yield TextField::new('firstname', 'Vorname');
|
yield TextField::new('firstname', 'Vorname');
|
||||||
yield TextField::new('lastname', 'Nachname');
|
yield TextField::new('lastname', 'Nachname');
|
||||||
yield TextField::new('email', 'E-Mail');
|
yield EmailField::new('email', 'E-Mail');
|
||||||
yield TextField::new('phone', 'Telefon');
|
yield TelephoneField::new('phone', 'Telefon');
|
||||||
yield AssociationField::new('payment', 'Zahlung')
|
yield AssociationField::new('payment', 'Total')
|
||||||
->setCrudController(PaymentCrudController::class)
|
->setCrudController(PaymentCrudController::class)
|
||||||
->formatValue(fn(?Payment $payment) => ($payment?->getTotal() ?? 'N/A') . ' €');
|
->formatValue(fn(?Payment $payment) => ($payment?->getTotal() ?? 0.0) . ' €')
|
||||||
yield
|
->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::NEW)
|
||||||
->disable(Action::EDIT);
|
->disable(Action::EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function configureCrud(Crud $crud): Crud
|
||||||
|
{
|
||||||
|
return $crud
|
||||||
|
->setPageTitle(Crud::PAGE_INDEX, 'Kunden')
|
||||||
|
->setPageTitle(Crud::PAGE_DETAIL, 'Kunden')
|
||||||
|
->showEntityActionsInlined();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ class PaymentCrudController extends AbstractCrudController
|
|||||||
|
|
||||||
public function configureFields(string $pageName): iterable
|
public function configureFields(string $pageName): iterable
|
||||||
{
|
{
|
||||||
yield AssociationField::new('customer', 'Customer')
|
yield AssociationField::new('customer', 'Kunde')
|
||||||
->setCrudController(CustomerCrudController::class)
|
->setCrudController(CustomerCrudController::class)
|
||||||
->formatValue(fn($value, $payment) => $payment->getCustomer()->getEmail());
|
->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
|
public function configureActions(Actions $actions): Actions
|
||||||
@ -33,4 +33,11 @@ class PaymentCrudController extends AbstractCrudController
|
|||||||
->disable(Action::NEW)
|
->disable(Action::NEW)
|
||||||
->disable(Action::EDIT);
|
->disable(Action::EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function configureCrud(Crud $crud): Crud
|
||||||
|
{
|
||||||
|
return $crud
|
||||||
|
->setPageTitle(Crud::PAGE_INDEX, 'Zahlungen')
|
||||||
|
->setPageTitle(Crud::PAGE_DETAIL, 'Zahlung');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,4 +42,11 @@ class TicketCrudController extends AbstractCrudController
|
|||||||
->disable(Action::NEW)
|
->disable(Action::NEW)
|
||||||
->disable(Action::EDIT);
|
->disable(Action::EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function configureCrud(Crud $crud): Crud
|
||||||
|
{
|
||||||
|
return $crud
|
||||||
|
->setPageTitle(Crud::PAGE_INDEX, 'Tickets')
|
||||||
|
->setPageTitle(Crud::PAGE_DETAIL, 'Ticket');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,12 @@ namespace App\Enum;
|
|||||||
|
|
||||||
class FoodData
|
class FoodData
|
||||||
{
|
{
|
||||||
|
public const FOOD_DATA = [
|
||||||
|
1 => 'Mit Fleisch',
|
||||||
|
2 => 'Vegetarisch',
|
||||||
|
3 => 'Vegan'
|
||||||
|
];
|
||||||
|
|
||||||
public const TYPES = [
|
public const TYPES = [
|
||||||
'Mit Fleisch' => 1,
|
'Mit Fleisch' => 1,
|
||||||
'Vegetarisch' => 2,
|
'Vegetarisch' => 2,
|
||||||
|
31
src/Twig/Ticket.php
Normal file
31
src/Twig/Ticket.php
Normal 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'];
|
||||||
|
}
|
||||||
|
}
|
29
templates/admin/customer_tickets.html.twig
Normal file
29
templates/admin/customer_tickets.html.twig
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user