add admin panel #20
@ -5,25 +5,29 @@ namespace App\Controller\Admin;
|
|||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
use App\Entity\Payment;
|
use App\Entity\Payment;
|
||||||
use App\Entity\Ticket;
|
use App\Entity\Ticket;
|
||||||
|
use App\Repository\PaymentRepository;
|
||||||
|
use App\Repository\TicketRepository;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
|
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
#[AdminDashboard(routePath: '/admin', routeName: 'admin')]
|
#[AdminDashboard(routePath: '/admin', routeName: 'admin')]
|
||||||
class ViewController extends AbstractDashboardController
|
class ViewController extends AbstractDashboardController
|
||||||
{
|
{
|
||||||
public function __construct(private AdminUrlGenerator $adminUrlGenerator)
|
public function __construct(private readonly PaymentRepository $paymentRepository, private readonly TicketRepository $ticketRepository)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/admin', name: 'admin')]
|
#[Route('/admin', name: 'admin')]
|
||||||
public function index(): Response
|
public function index(): Response
|
||||||
{
|
{
|
||||||
return $this->redirect($this->adminUrlGenerator->setController(CustomerCrudController::class)->generateUrl());
|
return $this->render('admin/dashboard.html.twig', [
|
||||||
|
'total' => $this->paymentRepository->getTotalMoneyMade(),
|
||||||
|
'foodData' => $this->ticketRepository->getFoodData(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureDashboard(): Dashboard
|
public function configureDashboard(): Dashboard
|
||||||
@ -33,6 +37,7 @@ class ViewController extends AbstractDashboardController
|
|||||||
|
|
||||||
public function configureMenuItems(): iterable
|
public function configureMenuItems(): iterable
|
||||||
{
|
{
|
||||||
|
yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home');
|
||||||
yield MenuItem::linkToCrud('Customers', 'fa fa-users', Customer::class);
|
yield MenuItem::linkToCrud('Customers', 'fa fa-users', Customer::class);
|
||||||
yield MenuItem::linkToCrud('Tickets', 'fa fa-ticket', Ticket::class);
|
yield MenuItem::linkToCrud('Tickets', 'fa fa-ticket', Ticket::class);
|
||||||
yield MenuItem::linkToCrud('Payments', 'fa fa-money', Payment::class);
|
yield MenuItem::linkToCrud('Payments', 'fa fa-money', Payment::class);
|
||||||
|
13
src/DataObjects/FoodData.php
Normal file
13
src/DataObjects/FoodData.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DataObjects;
|
||||||
|
|
||||||
|
class FoodData
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $totalMeat = 0,
|
||||||
|
public int $totalVegetarian = 0,
|
||||||
|
public int $totalVegan = 0,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
@ -15,4 +15,15 @@ class PaymentRepository extends ServiceEntityRepository
|
|||||||
{
|
{
|
||||||
parent::__construct($registry, Payment::class);
|
parent::__construct($registry, Payment::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTotalMoneyMade(): float
|
||||||
|
{
|
||||||
|
$all = $this->findAll();
|
||||||
|
$total = 0.0;
|
||||||
|
foreach ($all as $payment) {
|
||||||
|
$total += $payment->getTotal();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $total;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\DataObjects\FoodData;
|
||||||
use App\Entity\Ticket;
|
use App\Entity\Ticket;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
@ -15,4 +16,22 @@ class TicketRepository extends ServiceEntityRepository
|
|||||||
{
|
{
|
||||||
parent::__construct($registry, Ticket::class);
|
parent::__construct($registry, Ticket::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFoodData(): FoodData
|
||||||
|
{
|
||||||
|
$qb = $this->createQueryBuilder('t')
|
||||||
|
->select(
|
||||||
|
'SUM(CASE WHEN t.foodType = 1 THEN 1 ELSE 0 END) as totalMeat',
|
||||||
|
'SUM(CASE WHEN t.foodType = 2 THEN 1 ELSE 0 END) as totalVegetarian',
|
||||||
|
'SUM(CASE WHEN t.foodType = 3 THEN 1 ELSE 0 END) as totalVegan'
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $qb->getQuery()->getSingleResult();
|
||||||
|
|
||||||
|
return new FoodData(
|
||||||
|
(int) $result['totalMeat'],
|
||||||
|
(int) $result['totalVegetarian'],
|
||||||
|
(int) $result['totalVegan']
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
8
templates/admin/dashboard.html.twig
Normal file
8
templates/admin/dashboard.html.twig
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% extends '@EasyAdmin/page/content.html.twig' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{{ total }} €
|
||||||
|
meat: {{ foodData.totalMeat }}
|
||||||
|
vegetarian: {{ foodData.totalVegetarian }}
|
||||||
|
vegan: {{ foodData.totalVegan }}
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user