add admin panel
This commit is contained in:
parent
e3a67adf63
commit
584901f413
@ -12,6 +12,7 @@
|
||||
"doctrine/doctrine-bundle": "^2.13",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.4",
|
||||
"doctrine/orm": "^3.3",
|
||||
"easycorp/easyadmin-bundle": "^4.24",
|
||||
"php-flasher/flasher-noty-symfony": "^2.1",
|
||||
"phpdocumentor/reflection-docblock": "^5.6",
|
||||
"stripe/stripe-php": "^16.4",
|
||||
|
1050
composer.lock
generated
1050
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -15,4 +15,6 @@ return [
|
||||
Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
|
||||
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
|
||||
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
|
||||
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
|
||||
EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true],
|
||||
];
|
||||
|
39
config/packages/security.yaml
Normal file
39
config/packages/security.yaml
Normal file
@ -0,0 +1,39 @@
|
||||
security:
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: users_in_memory
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
# - { path: ^/admin, roles: ROLE_ADMIN }
|
||||
# - { path: ^/profile, roles: ROLE_USER }
|
||||
|
||||
when@test:
|
||||
security:
|
||||
password_hashers:
|
||||
# By default, password hashers are resource intensive and take time. This is
|
||||
# important to generate secure password hashes. In tests however, secure hashes
|
||||
# are not important, waste resources and increase test times. The following
|
||||
# reduces the work factor to the lowest possible values.
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
|
||||
algorithm: auto
|
||||
cost: 4 # Lowest possible value for bcrypt
|
||||
time_cost: 3 # Lowest possible value for argon
|
||||
memory_cost: 10 # Lowest possible value for argon
|
7
config/packages/translation.yaml
Normal file
7
config/packages/translation.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
framework:
|
||||
default_locale: en
|
||||
translator:
|
||||
default_path: '%kernel.project_dir%/translations'
|
||||
fallbacks:
|
||||
- en
|
||||
providers:
|
3
config/routes/security.yaml
Normal file
3
config/routes/security.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
_security_logout:
|
||||
resource: security.route_loader.logout
|
||||
type: service
|
42
src/Controller/Admin/CustomerCrudController.php
Normal file
42
src/Controller/Admin/CustomerCrudController.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Payment;
|
||||
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\TextField;
|
||||
|
||||
class CustomerCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Customer::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
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')
|
||||
->setCrudController(PaymentCrudController::class)
|
||||
->formatValue(fn(?Payment $payment) => ($payment?->getTotal() ?? 'N/A') . ' €');
|
||||
yield
|
||||
}
|
||||
|
||||
|
||||
public function configureActions(Actions $actions): Actions
|
||||
{
|
||||
return $actions
|
||||
->add(Crud::PAGE_INDEX, Action::DETAIL)
|
||||
->disable(Action::DELETE)
|
||||
->disable(Action::NEW)
|
||||
->disable(Action::EDIT);
|
||||
}
|
||||
}
|
36
src/Controller/Admin/PaymentCrudController.php
Normal file
36
src/Controller/Admin/PaymentCrudController.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Payment;
|
||||
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\BooleanField;
|
||||
|
||||
class PaymentCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Payment::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield AssociationField::new('customer', 'Customer')
|
||||
->setCrudController(CustomerCrudController::class)
|
||||
->formatValue(fn($value, $payment) => $payment->getCustomer()->getEmail());
|
||||
yield BooleanField::new('completed', 'Completed')->renderAsSwitch(false);
|
||||
}
|
||||
|
||||
public function configureActions(Actions $actions): Actions
|
||||
{
|
||||
return $actions
|
||||
->add(Crud::PAGE_INDEX, Action::DETAIL)
|
||||
->disable(Action::DELETE)
|
||||
->disable(Action::NEW)
|
||||
->disable(Action::EDIT);
|
||||
}
|
||||
}
|
45
src/Controller/Admin/TicketCrudController.php
Normal file
45
src/Controller/Admin/TicketCrudController.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Ticket;
|
||||
use App\Enum\FoodData;
|
||||
use App\Enum\TicketData;
|
||||
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\ChoiceField;
|
||||
|
||||
class TicketCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return Ticket::class;
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield ChoiceField::new('type', 'Name')
|
||||
->setChoices(TicketData::TYPES);
|
||||
|
||||
yield ChoiceField::new('foodType', 'Ernährung')
|
||||
->setChoices(FoodData::TYPES);
|
||||
|
||||
yield AssociationField::new('customer', 'Kunde')
|
||||
->setCrudController(CustomerCrudController::class)
|
||||
->formatValue(fn(Customer $customer) => $customer->getEmail());
|
||||
}
|
||||
|
||||
|
||||
public function configureActions(Actions $actions): Actions
|
||||
{
|
||||
return $actions
|
||||
->add(Crud::PAGE_INDEX, Action::DETAIL)
|
||||
->disable(Action::DELETE)
|
||||
->disable(Action::NEW)
|
||||
->disable(Action::EDIT);
|
||||
}
|
||||
}
|
40
src/Controller/Admin/ViewController.php
Normal file
40
src/Controller/Admin/ViewController.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Payment;
|
||||
use App\Entity\Ticket;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[AdminDashboard(routePath: '/admin', routeName: 'admin')]
|
||||
class ViewController extends AbstractDashboardController
|
||||
{
|
||||
public function __construct(private AdminUrlGenerator $adminUrlGenerator)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/admin', name: 'admin')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->redirect($this->adminUrlGenerator->setController(CustomerCrudController::class)->generateUrl());
|
||||
}
|
||||
|
||||
public function configureDashboard(): Dashboard
|
||||
{
|
||||
return Dashboard::new()->setTitle('Abiball Admin Interface');
|
||||
}
|
||||
|
||||
public function configureMenuItems(): iterable
|
||||
{
|
||||
yield MenuItem::linkToCrud('Customers', 'fa fa-users', Customer::class);
|
||||
yield MenuItem::linkToCrud('Tickets', 'fa fa-ticket', Ticket::class);
|
||||
yield MenuItem::linkToCrud('Payments', 'fa fa-money', Payment::class);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Enum\TicketData;
|
||||
use App\Repository\PaymentRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
@ -63,4 +64,11 @@ class Payment
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTotal(): float
|
||||
{
|
||||
return $this->customer->getTickets()->reduce(function (float $total, Ticket $ticket) {
|
||||
return $total + TicketData::TICKET_DATA[$ticket->getType()]['price'];
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
12
src/Enum/FoodData.php
Normal file
12
src/Enum/FoodData.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
class FoodData
|
||||
{
|
||||
public const TYPES = [
|
||||
'Mit Fleisch' => 1,
|
||||
'Vegetarisch' => 2,
|
||||
'Vegan' => 3,
|
||||
];
|
||||
}
|
@ -22,4 +22,11 @@ class TicketData
|
||||
'price' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
public const TYPES = [
|
||||
'Ticket' => 1,
|
||||
'After-Show Ticket' => 2,
|
||||
'Kind (6-12 Jahre)' => 3,
|
||||
'Kind (0-6 Jahre)' => 4,
|
||||
];
|
||||
}
|
||||
|
44
symfony.lock
44
symfony.lock
@ -35,6 +35,15 @@
|
||||
"migrations/.gitignore"
|
||||
]
|
||||
},
|
||||
"easycorp/easyadmin-bundle": {
|
||||
"version": "4.24",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "3.0",
|
||||
"ref": "b131e6cbfe1b898a508987851963fff485986285"
|
||||
}
|
||||
},
|
||||
"php-flasher/flasher-noty-symfony": {
|
||||
"version": "v2.1.2"
|
||||
},
|
||||
@ -146,6 +155,19 @@
|
||||
"config/routes.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/security-bundle": {
|
||||
"version": "7.2",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.4",
|
||||
"ref": "2ae08430db28c8eb4476605894296c82a642028f"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/security.yaml",
|
||||
"config/routes/security.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/stimulus-bundle": {
|
||||
"version": "2.22",
|
||||
"recipe": {
|
||||
@ -161,6 +183,19 @@
|
||||
"assets/controllers/hello_controller.js"
|
||||
]
|
||||
},
|
||||
"symfony/translation": {
|
||||
"version": "7.2",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.3",
|
||||
"ref": "e28e27f53663cc34f0be2837aba18e3a1bef8e7b"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/translation.yaml",
|
||||
"translations/.gitignore"
|
||||
]
|
||||
},
|
||||
"symfony/twig-bundle": {
|
||||
"version": "7.2",
|
||||
"recipe": {
|
||||
@ -174,6 +209,15 @@
|
||||
"templates/base.html.twig"
|
||||
]
|
||||
},
|
||||
"symfony/uid": {
|
||||
"version": "7.2",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "7.0",
|
||||
"ref": "0df5844274d871b37fc3816c57a768ffc60a43a5"
|
||||
}
|
||||
},
|
||||
"symfony/ux-icons": {
|
||||
"version": "2.22",
|
||||
"recipe": {
|
||||
|
0
translations/.gitignore
vendored
Normal file
0
translations/.gitignore
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user