src/Controller/Dashboard/DashboardController.php line 29
<?phpdeclare(strict_types=1);namespace App\Controller\Dashboard;use App\Autowire\EntityManagerTrait;use App\Controller\BaseController;use App\Dto\StatCardDto;use App\Dto\StatCardDtoCollection;use App\Entity\Appointment;use App\Entity\Enum\RequestStateEnum;use App\Entity\Request as Demande;use App\Entity\Stock;use App\Form\ModelType\Appointment\Autowire\AppointmentFormHandlerTrait;use App\Form\ModelType\Appointment\Model\AppointmentModel;use App\Values\MenuEntry;use DateTimeImmutable;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;class DashboardController extends BaseController{use EntityManagerTrait;use AppointmentFormHandlerTrait;#[Route('/', name: 'dashboard_index', methods: 'GET')]public function index(): Response{$form = $this->getFormHandler()->createForm(model: new AppointmentModel(),);$appointment = $this->getRepository(Appointment::class)->findBy(array('date' => new DateTimeImmutable()));$stocksAlertes = $this->getRepository(Stock::class)->getAlertsStocks();return $this->render('dashboard/index.html.twig', ['form' => $form->createView(),'appointments'=> $appointment,'stocks_alerts' => $stocksAlertes]);}#[Route('/', name: 'dashboard_create_appointment', methods: 'POST')]public function createAppointment(Request $request): Response{$form = $this->getFormHandler()->handleForm(request: $request,model: new AppointmentModel());if ($form instanceof Response) {return $form;}$appointment = $this->getRepository(Appointment::class)->findBy(array('date' => new DateTimeImmutable()));$stocksAlertes = $this->getRepository(Stock::class)->getAlertsStocks();return $this->render('dashboard/index.html.twig', ['form' => $form->createView(),'appointments'=> $appointment,'stocks_alerts' => $stocksAlertes]);}public function getMenuEntry(): MenuEntry{return MenuEntry::DASHBOARD;}public function getStatCards(): ?StatCardDtoCollection{$collection = new StatCardDtoCollection();$collection->addElement(new StatCardDto(label: 'Voitures réparées',value: $this->getRepository(Demande::class)->getNbByState(RequestStateEnum::FINISHED)));$collection->addElement(new StatCardDto(label: 'En cours de réparations',value: $this->getRepository(Demande::class)->getNbByState(RequestStateEnum::IN_PROGRESS)));$collection->addElement(new StatCardDto(label: 'En attente de réparations',value: $this->getRepository(Demande::class)->getNbByState(RequestStateEnum::PENDING)));return $collection;}}