src/Controller/DashboardController.php line 25

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Schedules;
  4. use App\Entity\Users;
  5. use App\Form\DateSchedulesType;
  6. use App\Form\UsersSchedulesType;
  7. use App\Repository\PhoneManagersRepository;
  8. use App\Repository\ReservedVehiclesRepository;
  9. use App\Repository\SchedulesRepository;
  10. use App\Repository\UsersRepository;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class DashboardController extends AbstractController
  16. {
  17.     #[Route('/admin'name'home_admin')]
  18.     #[Route('/admin/'name'home_admin')]
  19.     #[Route('/admin/dashboard'name'dashboard')]
  20.     ##[Route('/admin/dashboard/{selectUser<\d+>?}', name: 'dashboard', methods: ['GET'])]
  21.     #[Route('/admin/dashboard/{scheduleAt}'name'dashboard-date'methods: ['GET'])]
  22.     public function index(Request $requestSchedulesRepository $repoSchedulesUsersRepository $repoUsersReservedVehiclesRepository $repoVehiclesReservedPhoneManagersRepository $repoPhoneManager$scheduleAt null$selectUser null): Response
  23.     {
  24.         if (is_null($scheduleAt)) {
  25.             $scheduleAt = new \DateTimeImmutable($scheduleAt);
  26.             $currentDate $scheduleAt->format("Y-m-d");
  27.         } else {
  28.             $scheduleAt = new \DateTimeImmutable($scheduleAt);
  29.             $currentDate $scheduleAt->format("Y-m-d");
  30.         }
  31.         $role = ($this->getUser()->getRoles());
  32.         if (in_array('ROLE_SUPER_ADMIN'$role) || in_array('ROLE_ADMIN'$role)) {
  33.             $admin true;
  34.         } else {
  35.             $admin false;
  36.         }
  37.         if (is_null($selectUser)) {
  38.             $user $repoUsers->find($this->getUser());
  39.         } else {
  40.             $user $repoUsers->find($selectUser);
  41.         }
  42.         $dateSchedule = new Schedules();
  43.         $dateSchedule->setScheduleAt($scheduleAt);
  44.         /*$form = $this->createForm(UsersSchedulesType::class, null, [
  45.             'action' => $this->generateUrl('dashboard'),
  46.             'method' => 'GET'
  47.         ]);*/
  48.         $form $this->createForm(DateSchedulesType::class, $dateSchedule, [
  49.             'action' => $this->generateUrl('dashboard-date'),
  50.             'method' => 'GET'
  51.         ]);
  52.         //dd($user);
  53.         $form->handleRequest($request);
  54.         if ($form->isSubmitted() && $form->isValid()) {
  55.             $task $form->getData();
  56.             $formatDate $task->getScheduleAt()->format("Y-m-d");
  57.             //dd($formatDate);
  58.             return $this->redirectToRoute('dashboard-date', ['scheduleAt' => $formatDate]);
  59.         }
  60.         $schedules $repoSchedules->findScheduleSinceTodayByUser($user->getId());
  61.         //dd($schedules);
  62.         $listSchedule = [];
  63.         //1 - On récupère les intervention de la date courante
  64.         $schedulesByDate $repoSchedules->findSchedulesByDate($currentDatefalse);
  65.         $bidule = [];
  66.         $truc = [];
  67.         dump($schedulesByDate);
  68.         //2 - On récupère les intervenants pour chaque mission
  69.         foreach ($schedulesByDate as $key => $value) {
  70.             foreach ($value->getUsers() as $k => $v) {
  71.                 $truc[$v->getId()] =  $v->getFirstname() . ' ' $v->getLastname();
  72.                 if (!array_key_exists($v->getId(), $bidule)) {
  73.                     $bidule[$v->getId()][] = $value;
  74.                 } else {
  75.                     array_push($bidule[$v->getId()], $value);
  76.                 }
  77.                 //$bidule[$v->getId()] = 'coucou';
  78.             }
  79.             //dump($value->getUsers());
  80.         }
  81.         dump($truc);
  82.         dump($bidule);
  83.         $schedulesByUsers = [];
  84.         $i 0;
  85.         foreach ($schedulesByDate as $key => $value) {
  86.             $listUsers '';
  87.             foreach ($value->getUsers() as $v) {
  88.                 $listUsers .= $v->getFirstname() . ' ' $v->getLastname() . ' - ';
  89.                 $userId $v->getId();
  90.                 //dump($listUsers);
  91.             }
  92.             $listUsers rtrim($listUsers' - ');
  93.             $schedulesByUsers[$userId] = [
  94.                 'user' => $listUsers,
  95.                 'schedules' => $repoSchedules->findScheduleByUserAndDate($userId$currentDate),
  96.             ];
  97.             break;
  98.         }
  99.         //$truc = $repoSchedules->findScheduleByUserAndDate(6, '2023-06-02');
  100.         $machin $repoUsers->schedulesByDate('2023-06-02'6);
  101.         //dump($machin);
  102.         //$responsivePhone = $repoUsers->findOneBy(['phone_responsible' => true]);
  103.         $vehiclesReserved $repoVehiclesReserved->findForSchedules($scheduleAt);
  104.         //dump($scheduleAt->format('Y-m-d'));
  105.         $phoneManagers $repoPhoneManager->findByDate($scheduleAt->format('Y-m-d'));
  106.         //dump($listSchedule);
  107.         return $this->renderForm('admin/dashboard/index.html.twig', [
  108.             'currentDate' => $currentDate,
  109.             'schedules' => $listSchedule,
  110.             'schedulesByDate' => $schedulesByDate,
  111.             'schedulesByUsers' => $schedulesByUsers,
  112.             'form' => $form,
  113.             'phoneResponsives' => $phoneManagers,
  114.             'vehiclesReserved' => $vehiclesReserved,
  115.             'truc' => $truc,
  116.             'bidule' => $bidule,
  117.         ]);
  118.     }
  119. }