src/Controller/Dashboard/DashboardController.php line 29

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Dashboard;
  4. use App\Autowire\EntityManagerTrait;
  5. use App\Controller\BaseController;
  6. use App\Dto\StatCardDto;
  7. use App\Dto\StatCardDtoCollection;
  8. use App\Entity\Appointment;
  9. use App\Entity\Enum\RequestStateEnum;
  10. use App\Entity\Request as Demande;
  11. use App\Entity\Stock;
  12. use App\Form\ModelType\Appointment\Autowire\AppointmentFormHandlerTrait;
  13. use App\Form\ModelType\Appointment\Model\AppointmentModel;
  14. use App\Values\MenuEntry;
  15. use DateTimeImmutable;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. class DashboardController extends BaseController
  20. {
  21.     use EntityManagerTrait;
  22.     use AppointmentFormHandlerTrait;
  23.     #[Route('/'name'dashboard_index'methods'GET')]
  24.     public function index(): Response
  25.     {
  26.         $form $this->getFormHandler()->createForm(
  27.             model: new AppointmentModel(),
  28.         );
  29.         $appointment $this
  30.             ->getRepository(Appointment::class)
  31.             ->findBy(array('date' => new DateTimeImmutable()));
  32.         $stocksAlertes $this
  33.             ->getRepository(Stock::class)
  34.             ->getAlertsStocks();
  35.         return $this->render('dashboard/index.html.twig', [
  36.             'form' => $form->createView(),
  37.             'appointments'=> $appointment,
  38.             'stocks_alerts' => $stocksAlertes
  39.         ]);
  40.     }
  41.     #[Route('/'name'dashboard_create_appointment'methods'POST')]
  42.     public function createAppointment(Request $request): Response
  43.     {
  44.         $form $this->getFormHandler()->handleForm(
  45.             request$request,
  46.             model: new AppointmentModel()
  47.         );
  48.         if ($form instanceof Response) {
  49.             return $form;
  50.         }
  51.         $appointment $this
  52.             ->getRepository(Appointment::class)
  53.             ->findBy(array('date' => new DateTimeImmutable()));
  54.         $stocksAlertes $this
  55.             ->getRepository(Stock::class)
  56.             ->getAlertsStocks();
  57.         return $this->render('dashboard/index.html.twig', [
  58.             'form' => $form->createView(),
  59.             'appointments'=> $appointment,
  60.             'stocks_alerts' => $stocksAlertes
  61.         ]);
  62.     }
  63.     public function getMenuEntry(): MenuEntry
  64.     {
  65.         return MenuEntry::DASHBOARD;
  66.     }
  67.     public function getStatCards(): ?StatCardDtoCollection
  68.     {
  69.         $collection = new StatCardDtoCollection();
  70.         $collection->addElement(new StatCardDto(
  71.             label'Voitures réparées',
  72.             value$this->getRepository(Demande::class)->getNbByState(RequestStateEnum::FINISHED)
  73.         ));
  74.         $collection->addElement(new StatCardDto(
  75.             label'En cours de réparations',
  76.             value$this->getRepository(Demande::class)->getNbByState(RequestStateEnum::IN_PROGRESS)
  77.         ));
  78.         $collection->addElement(new StatCardDto(
  79.             label'En attente de réparations',
  80.             value$this->getRepository(Demande::class)->getNbByState(RequestStateEnum::PENDING)
  81.         ));
  82.         return $collection;
  83.     }
  84. }