src/Controller/HomeController.php line 326
<?phpnamespace App\Controller;use App\Entity\Client;use App\Entity\Contrat;use App\Entity\Chantier;use App\Entity\Personne;use App\Entity\Activites;use App\Entity\Prestation;use App\Form\ChantierType;use App\Entity\Utilisateur;use App\Entity\Qualification;use App\Service\ClientService;use App\Service\AccessByClient;use App\Service\PersonneService;use App\Entity\ProfilUtilisateur;use App\Entity\DesignationActivite;use App\Repository\ContratRepository;use App\Entity\RepresentantEntreprise;use App\Repository\PointageRepository;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use App\Repository\RepresentantEntrepriseRepository;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;class HomeController extends AbstractController{#[Route('/', name: 'app_home')]public function index(): Response{return $this->redirectToRoute('app_redirect_auth');}#[Route('/{nom}.php', name: 'app_publicpage_static')]public function staticPage($nom): Response{$html = file_get_contents('pages/' . $nom . ".php");return $this->render('static_page/index.html.twig', ['html' => $html,]);}#[Route('/p/dashboard', name: 'app_dashboard')]public function dashboard(EntityManagerInterface $entityManager,PointageRepository $pointageRepository,AccessByClient $accessByClient,ContratRepository $contratRepository,PersonneService $personneService,RepresentantEntrepriseRepository $representantEntrepriseRepository,ClientService $clientService): Response{/** @var Utilisateur $currentUser */$currentUser = $this->getUser();// --------- INIT DB --------------$clientAdmin = $entityManager->getRepository(Client::class)->find($currentUser->getIdClient());if ($clientAdmin) {$clientService->initDB($clientAdmin);}// --------- /// INIT DB /// --------------$currentDate = new \DateTime();$currentDateDebut = clone $currentDate;$currentDateDebut->setTime(0, 0);$currentDateFin = clone $currentDate;$currentDateFin->setTime(23, 59);$allPointageDuJour = $pointageRepository->findByDate($currentDateDebut, $currentDateFin);$allPointageDuJour = $accessByClient->getAccess_pointage($allPointageDuJour, $currentUser);$allChantiers = $entityManager->getRepository(Chantier::class)->findBy(['estActif' => true]);$allPersonnes = $entityManager->getRepository(Personne::class)->findBy(['estActif' => true]);$allPersonnes = $accessByClient->getAccess_personne($allPersonnes, $currentUser);$personneActifInternes = $personneService->getPersonneInterne($allPersonnes);$personneActifExternes = $personneService->getPersonneExterne($allPersonnes);$allChantiers = $accessByClient->getAccess_chantier($allChantiers, $currentUser);// -------------- NOMBRE STATISTIQUE --------------------------------------------------------------$nbChantierActif = count($allChantiers);$nbPersonneActifInternes = count($personneActifInternes);$nbPersonneActifExternes = count($personneActifExternes);// -------------------------------------------------------------------------------------------------/** @var Personne[] $persInData */$persInData = [];$dataChart_personne_entreprise = [];$dataChart_personne_qualification = [];$dataChart_chantier_categorie = [];$dataChart_chantier_region = [];foreach ($allPersonnes as $pers) {if (!in_array($pers, $persInData)) {// ---------------- PERSONNE EXTERNE ------------------------if (!$pers->isPersInterne()) {/** @var Contrat $persContrat */$persContrat = null;$personneContrats = $contratRepository->findByDatePrecisAndPersonne($currentDate, $pers);if (count($personneContrats) > 0) {$persContrat = $personneContrats[0];}if ($persContrat) {$persInData[] = $pers;// --------- PERSONNE PAR ENTREPRISE --------------$testIndexEntreprise = array_search(needle: $persContrat->getIdentreprise()->getEntDenomination(),haystack: array_column($dataChart_personne_entreprise, 'name'));if ($testIndexEntreprise !== false) {$dataChart_personne_entreprise[$testIndexEntreprise]['value'] += 1;} else {$dataChart_personne_entreprise[] = ['name' => $persContrat->getIdentreprise()->getEntDenomination(),'value' => 1];}// --------- //// PERSONNE PAR ENTREPRISE //// --------------// --------- PERSONNE PAR QUALIFICATION --------------$testIndexQualification = array_search(needle: $persContrat->getIdqualification()->getQlfDesignation(),haystack: array_column($dataChart_personne_qualification, 'name'));if ($testIndexQualification !== false) {$dataChart_personne_qualification[$testIndexQualification]['value'] += 1;} else {$dataChart_personne_qualification[] = ['name' => $persContrat->getIdqualification()->getQlfDesignation(),'value' => 1];}// --------- //// PERSONNE PAR QUALIFICATION //// --------------}}// ---------------- ///// PERSONNE EXTERNE ///// ------------------------// ---------------- PERSONNE INTERNE ------------------------if ($pers->isPersInterne()) {$persInData[] = $pers;/** @var RepresentantEntreprise $persRepresentant */$persRepresentant = null;$personneRepresentants = $representantEntrepriseRepository->findByDatePrecisAndPersonne($currentDate, $pers);if (count($personneRepresentants) > 0) {$persRepresentant = $personneRepresentants[0];}// --------- PERSONNE PAR ENTREPRISE --------------// Le nom est interne si pas de représentant$nomEntreprise = $persRepresentant?->getEntreprise()?->getEntDenomination() ?? 'Interne';$testIndexEntreprise = array_search(needle: $nomEntreprise,haystack: array_column($dataChart_personne_entreprise, 'name'));if ($testIndexEntreprise !== false) {$dataChart_personne_entreprise[$testIndexEntreprise]['value'] += 1;} else {$dataChart_personne_entreprise[] = ['name' => $nomEntreprise,'value' => 1];}// --------- //// PERSONNE PAR ENTREPRISE //// --------------// --------- PERSONNE PAR QUALIFICATION --------------if ($pers->getIdqualification()) {$testIndexQualification = array_search(needle: $pers->getIdqualification()->getQlfDesignation(),haystack: array_column($dataChart_personne_qualification, 'name'));if ($testIndexQualification !== false) {$dataChart_personne_qualification[$testIndexQualification]['value'] += 1;} else {$dataChart_personne_qualification[] = ['name' => $pers->getIdqualification()->getQlfDesignation(),'value' => 1];}}// --------- //// PERSONNE PAR QUALIFICATION //// --------------}// ---------------- //// PERSONNE INTERNE //// ------------------------}}// --------- CHANTIER CATEGORIE --------------foreach ($allChantiers as $cht) {if ($cht->getIdgroupechantier()) {$testIndexChantierCateg = array_search(needle: $cht->getIdgroupechantier()->getGpchtLibelle(),haystack: array_column($dataChart_chantier_categorie, 'name'));if ($testIndexChantierCateg !== false) {$dataChart_chantier_categorie[$testIndexChantierCateg]['value'] += 1;} else {$dataChart_chantier_categorie[] = ['name' => $cht->getIdgroupechantier()->getGpchtLibelle(),'value' => 1];}}}// --------- //// CHANTIER CATEGORIE //// --------------// --------- CHANTIER REGION --------------foreach ($allChantiers as $cht) {if ($cht->getIdregion()) {$testIndexChantierRegion = array_search(needle: $cht->getIdregion()->getRegNom(),haystack: array_column($dataChart_chantier_region, 'name'));if ($testIndexChantierRegion !== false) {$dataChart_chantier_region[$testIndexChantierRegion]['value'] += 1;} else {$dataChart_chantier_region[] = ['name' => $cht->getIdregion()->getRegNom(),'color' => $cht->getIdregion()->getRegCouleur(),'value' => 1];}}}// --------- /// CHANTIER REGION /// --------------// --------- FLASH PROFILE PAR DEFAUT --------------$defaultProfile = $entityManager->getRepository(ProfilUtilisateur::class)->findOneBy(["idclient" => $currentUser->getIdClient(),"default" => true,"estActif" => true]);if ($defaultProfile&& count($defaultProfile->getTableAccess()) == 0) {$messageInfo = "Veuillez contacter votre administrateur pour gérer vos droits d'accès sur la plateforme";if ($currentUser->isRole("ROLE_ADMIN")) {$messageInfo = "Veuillez configurer les paramètres par défaut du \"Profil utilisateur\"";$this->addFlash('info', $messageInfo);} else {if ($currentUser->getIdprofil()&& count($currentUser->getIdprofil()->getTableAccess()) == 0) {$this->addFlash('error', $messageInfo);}}}// --------- /// FLASH PROFILE PAR DEFAUT /// --------------return $this->render('home/index.html.twig', ['dataChart_personne_entreprise' => json_encode($dataChart_personne_entreprise, JSON_UNESCAPED_UNICODE),'dataChart_personne_qualification' => json_encode($dataChart_personne_qualification, JSON_UNESCAPED_UNICODE),'dataChart_chantier_categorie' => json_encode($dataChart_chantier_categorie, JSON_UNESCAPED_UNICODE),'dataChart_chantier_region' => json_encode($dataChart_chantier_region, JSON_UNESCAPED_UNICODE),'nbChantierActif' => $nbChantierActif,'nbPersonneActifInternes' => $nbPersonneActifInternes,'nbPersonneActifExternes' => $nbPersonneActifExternes,]);}#[Route('/my-test', name: 'app_mytest')]public function myTest(): Response{return $this->render('home/index.html.twig', []);}#[Route('/p', name: 'app_redirect_auth')]public function redirectAuth(): Response{if ($this->isGranted("ROLE_SUPER_ADMIN")) {return $this->redirectToRoute("app_admin_compte_admin_index");}return $this->redirectToRoute("app_dashboard");}#[Route('/p/liste-chantier', name: 'liste.chantier')]public function listeChantier(): Response{return $this->render('chantier/index.html.twig',[]);}#[Route('/p/new-chantier', name: 'new.chantier')]public function new(Request $request,EntityManagerInterface $entityManager): Response{/*** @var Utilisateur $currentUser*/$currentUser = $this->getUser();//$formOptions = $this->getFormOptionAccess($entityManager, $accessByClient, $currentUser, $personneService);$chantier = new Chantier();// INIT ACTIVITE CHANTIERif ($chantier->getListActivites()->count() == 0) {$chActivite = new Activites();$chantier->addListActivite($chActivite);}// INIT PRESTATION CHANTIERif ($chantier->getListPrestations()->count() == 0) {$chPrestation = new Prestation();$chantier->addListPrestation($chPrestation);}$form = $this->createForm(ChantierType::class, $chantier);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$chantier->setIdClientMere($currentUser->getIdClient());// DELETE ACTIVITE & PRESTATION IF NULL// $this->removeUnitule($chantier);$entityManager->persist($chantier);$entityManager->flush();$entityManager->persist($chantier);$entityManager->flush();//$this->updateActiviteOnSubmit($chantier, $entityManager);//$this->updatePrestationOnSubmit($chantier, $entityManager);return $this->redirectToRoute('app_administration_chantier_index', [], Response::HTTP_SEE_OTHER);}// LIST QUALIFICATION FOR INIT ADD PRESTATION/** @var Qualification[] $listQualifications *////$listQualifications = $formOptions['qualifications'];// LIST DESIGNATION FOR INIT ADD ACTIVITE/** @var DesignationActivite[] $listQualifications *///$listDesignationActivites = $formOptions['designation_activies'];return $this->render('chantier/new.html.twig', ['chantier' => $chantier,'form' => $form->createView(),]);}#[Route('/p/edit-chantier', name: 'edit.chantier')]public function edit(Request $request,EntityManagerInterface $entityManager): Response{/*** @var Utilisateur $currentUser*/$currentUser = $this->getUser();//$formOptions = $this->getFormOptionAccess($entityManager, $accessByClient, $currentUser, $personneService);$chantier = new Chantier();// INIT ACTIVITE CHANTIERif ($chantier->getListActivites()->count() == 0) {$chActivite = new Activites();$chantier->addListActivite($chActivite);}// INIT PRESTATION CHANTIERif ($chantier->getListPrestations()->count() == 0) {$chPrestation = new Prestation();$chantier->addListPrestation($chPrestation);}$form = $this->createForm(ChantierType::class, $chantier);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$chantier->setIdClientMere($currentUser->getIdClient());// DELETE ACTIVITE & PRESTATION IF NULL// $this->removeUnitule($chantier);$entityManager->persist($chantier);$entityManager->flush();$entityManager->persist($chantier);$entityManager->flush();//$this->updateActiviteOnSubmit($chantier, $entityManager);//$this->updatePrestationOnSubmit($chantier, $entityManager);return $this->redirectToRoute('app_administration_chantier_index', [], Response::HTTP_SEE_OTHER);}// LIST QUALIFICATION FOR INIT ADD PRESTATION/** @var Qualification[] $listQualifications *////$listQualifications = $formOptions['qualifications'];// LIST DESIGNATION FOR INIT ADD ACTIVITE/** @var DesignationActivite[] $listQualifications *///$listDesignationActivites = $formOptions['designation_activies'];return $this->render('chantier/edit.html.twig', ['chantier' => $chantier,'form' => $form->createView(),]);}#[Route('/p/liste-bordereaux', name: 'liste.bordereaux')]public function listeBordereaux(): Response{return $this->render('bordereaux/index.html.twig',[]);}#[Route('/p/new-bordereaux', name: 'new.bordereaux')]public function newBordereaux(): Response{return $this->render('bordereaux/new.html.twig',[]);}#[Route('/p/edit-bordereaux', name: 'edit.bordereaux')]public function editBordereaux(): Response{return $this->render('bordereaux/edit.html.twig',[]);}#[Route('/p/detail-bordereaux', name: 'detail.bordereaux')]public function detailBordereaux(): Response{return $this->render('bordereaux/detail.html.twig',[]);}#[Route('/p/modifier-bordereaux', name: 'modifier.bordereaux')]public function modifierBordereaux(): Response{return $this->render('bordereaux/modifier.html.twig',[]);}#[Route('/p/afficher-editer-bordereaux', name: 'affichage.modification.bordereaux')]public function afficherEditerBordereaux(): Response{return $this->render('bordereaux/affichage-and-modification.html.twig',[]);}#[Route('/p/liste-etat-avancement', name: 'liste.etat.avancement')]public function listeAvancement(): Response{return $this->render('etat-avancement/index.html.twig',[]);}#[Route('/p/new-etat-avancement', name: 'new.etat.avancement')]public function newAvancement(): Response{return $this->render('etat-avancement/nouvelle.html.twig',[]);}#[Route('/p/detail-etat-avancement', name: 'detail.etat.avancement')]public function detailAvancement(): Response{return $this->render('etat-avancement/detail.html.twig',[]);}#[Route('/p/edit-etat-avancement', name: 'edit.etat.avancement')]public function editAvancement(): Response{return $this->render('etat-avancement/edit1.html.twig',[]);}#[Route('/p/modifier-etat-avancement', name: 'modifier.etat.avancement')]public function modifierAvancement(): Response{return $this->render('etat-avancement/edit.html.twig',[]);}#[Route('/p/cloturer-etat-avancement', name: 'cloturer.etat.avancement')]public function cloturerAvancement(): Response{return $this->render('etat-avancement/cloturer.html.twig',[]);}#[Route('/p/ajouter-fichier', name: 'ajouter.fichier')]public function ajouterFichier(): Response{return $this->render('administration/chantier/ajouter-fichier.html.twig',[]);}#[Route('/p/document-etat-avancement', name: 'document.etat.avancement')]public function docAvancement(): Response{return $this->render('etat-avancement/document.html.twig',[]);}#[Route('/p/document1-etat-avancement', name: 'document1.etat.avancement')]public function docAvancemente(): Response{return $this->render('etat-avancement/document1.html.twig',[]);}#[Route('/p/liste-rubriques', name: 'liste.rubriques')]public function listeRubrique(): Response{return $this->render('rubriques/index.html.twig',[]);}#[Route('/p/new-rubriques', name: 'new.rubriques')]public function newRubrique(): Response{return $this->render('rubriques/new.html.twig',[]);}#[Route('/p/edit-rubriques', name: 'edit.rubriques')]public function editRubrique(): Response{return $this->render('rubriques/edit.html.twig',[]);}#[Route('/p/rapport-avancement', name: 'rapport.avancement')]public function rapportAvancement(): Response{return $this->render('rapport/rapport-avancement.html.twig',[]);}#[Route('/p/rapport-recapitulatif', name: 'rapport.recapitulatif')]public function rapportRecapitulatif(): Response{return $this->render('rapport/rapport-recapitulatif.html.twig',[]);}#[Route('/p/rapport-rectificatif', name: 'rapport.rectificatif')]public function rapportRectificatif(): Response{return $this->render('rapport/rapport-rectificatif.html.twig',[]);}#[Route('/p/document', name: 'rapport.document')]public function document(): Response{return $this->render('administration/chantier/document.html.twig',[]);}#[Route('/p/unite', name: 'unite.index')]public function uniteIndex(): Response{return $this->render('unites/index.html.twig',[]);}#[Route('/p/unite-edut', name: 'unite.edit')]public function editUnite(): Response{return $this->render('unites/edit.html.twig',[]);}#[Route('/p/unite-new', name: 'unite.new')]public function newUnite(): Response{return $this->render('unites/new.html.twig',[]);}#[Route('/p/prestation', name: 'prestation.index')]public function prestationIndex(): Response{return $this->render('prestation/index.html.twig',[]);}#[Route('/p/saisie-etat-avancement', name: 'saisie.etat.avancement')]public function saisieEtatAvancement(): Response{return $this->render('etat-avancement/page-saisie-etat-avancement.html.twig',[]);}#[Route('/p/copie-etat-avancement', name: 'copie.etat.avancement')]public function copieEtatAvancement(): Response{return $this->render('etat-avancement/copier.html.twig',[]);}#[Route('/p/inserer-position', name: 'inserer.position')]public function insererPosition(): Response{return $this->render('bordereaux/inserer-position.html.twig',[]);}}