src/Controller/DashboardController.php line 25
<?php
namespace App\Controller;
use App\Entity\Schedules;
use App\Entity\Users;
use App\Form\DateSchedulesType;
use App\Form\UsersSchedulesType;
use App\Repository\PhoneManagersRepository;
use App\Repository\ReservedVehiclesRepository;
use App\Repository\SchedulesRepository;
use App\Repository\UsersRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractController
{
#[Route('/admin', name: 'home_admin')]
#[Route('/admin/', name: 'home_admin')]
#[Route('/admin/dashboard', name: 'dashboard')]
##[Route('/admin/dashboard/{selectUser<\d+>?}', name: 'dashboard', methods: ['GET'])]
#[Route('/admin/dashboard/{scheduleAt}', name: 'dashboard-date', methods: ['GET'])]
public function index(Request $request, SchedulesRepository $repoSchedules, UsersRepository $repoUsers, ReservedVehiclesRepository $repoVehiclesReserved, PhoneManagersRepository $repoPhoneManager, $scheduleAt = null, $selectUser = null): Response
{
if (is_null($scheduleAt)) {
$scheduleAt = new \DateTimeImmutable($scheduleAt);
$currentDate = $scheduleAt->format("Y-m-d");
} else {
$scheduleAt = new \DateTimeImmutable($scheduleAt);
$currentDate = $scheduleAt->format("Y-m-d");
}
$role = ($this->getUser()->getRoles());
if (in_array('ROLE_SUPER_ADMIN', $role) || in_array('ROLE_ADMIN', $role)) {
$admin = true;
} else {
$admin = false;
}
if (is_null($selectUser)) {
$user = $repoUsers->find($this->getUser());
} else {
$user = $repoUsers->find($selectUser);
}
$dateSchedule = new Schedules();
$dateSchedule->setScheduleAt($scheduleAt);
/*$form = $this->createForm(UsersSchedulesType::class, null, [
'action' => $this->generateUrl('dashboard'),
'method' => 'GET'
]);*/
$form = $this->createForm(DateSchedulesType::class, $dateSchedule, [
'action' => $this->generateUrl('dashboard-date'),
'method' => 'GET'
]);
//dd($user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$task = $form->getData();
$formatDate = $task->getScheduleAt()->format("Y-m-d");
//dd($formatDate);
return $this->redirectToRoute('dashboard-date', ['scheduleAt' => $formatDate]);
}
$schedules = $repoSchedules->findScheduleSinceTodayByUser($user->getId());
//dd($schedules);
$listSchedule = [];
//1 - On récupère les intervention de la date courante
$schedulesByDate = $repoSchedules->findSchedulesByDate($currentDate, false);
$bidule = [];
$truc = [];
dump($schedulesByDate);
//2 - On récupère les intervenants pour chaque mission
foreach ($schedulesByDate as $key => $value) {
foreach ($value->getUsers() as $k => $v) {
$truc[$v->getId()] = $v->getFirstname() . ' ' . $v->getLastname();
if (!array_key_exists($v->getId(), $bidule)) {
$bidule[$v->getId()][] = $value;
} else {
array_push($bidule[$v->getId()], $value);
}
//$bidule[$v->getId()] = 'coucou';
}
//dump($value->getUsers());
}
dump($truc);
dump($bidule);
$schedulesByUsers = [];
$i = 0;
foreach ($schedulesByDate as $key => $value) {
$listUsers = '';
foreach ($value->getUsers() as $v) {
$listUsers .= $v->getFirstname() . ' ' . $v->getLastname() . ' - ';
$userId = $v->getId();
//dump($listUsers);
}
$listUsers = rtrim($listUsers, ' - ');
$schedulesByUsers[$userId] = [
'user' => $listUsers,
'schedules' => $repoSchedules->findScheduleByUserAndDate($userId, $currentDate),
];
break;
}
//$truc = $repoSchedules->findScheduleByUserAndDate(6, '2023-06-02');
$machin = $repoUsers->schedulesByDate('2023-06-02', 6);
//dump($machin);
//$responsivePhone = $repoUsers->findOneBy(['phone_responsible' => true]);
$vehiclesReserved = $repoVehiclesReserved->findForSchedules($scheduleAt);
//dump($scheduleAt->format('Y-m-d'));
$phoneManagers = $repoPhoneManager->findByDate($scheduleAt->format('Y-m-d'));
//dump($listSchedule);
return $this->renderForm('admin/dashboard/index.html.twig', [
'currentDate' => $currentDate,
'schedules' => $listSchedule,
'schedulesByDate' => $schedulesByDate,
'schedulesByUsers' => $schedulesByUsers,
'form' => $form,
'phoneResponsives' => $phoneManagers,
'vehiclesReserved' => $vehiclesReserved,
'truc' => $truc,
'bidule' => $bidule,
]);
}
}