src/Controller/bilanControllers/AnalyseSSTController.php line 97

Open in your IDE?
  1. <?php
  2. namespace App\Controller\bilanControllers;
  3. use App\Entity\bilan\Job;
  4. use App\Entity\bilan\Location;
  5. use App\Entity\bilan\Mission;
  6. use App\Entity\bilan\Task;
  7. use App\Entity\bilan\Zone;
  8. use App\Entity\Processus;
  9. use App\Entity\User;
  10. use App\Repository\bilan\SituationRisqueRepository;
  11. use App\Repository\bilan\JobRepository;
  12. use App\Repository\Configuration\CompanyEntityRepository;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use App\Repository\ProcessusRepository;
  19. /**
  20.  * @Route("/analyseSST")
  21.  */
  22. class AnalyseSSTController extends AbstractController
  23. {
  24.     private ProcessusRepository $processusRepository;
  25.     private JobRepository $jobRepository;
  26.     private CompanyEntityRepository $companyEntityRepository;
  27.     public function __construct(ProcessusRepository $processusRepositoryJobRepository $jobRepositoryCompanyEntityRepository $companyEntityRepository)
  28.     {
  29.         $this->processusRepository $processusRepository;
  30.         $this->jobRepository $jobRepository;
  31.         $this->companyEntityRepository $companyEntityRepository;
  32.     }
  33.     private function getYearsList(): array
  34.     {
  35.         $currentYear = (int)date('Y');
  36.         $years = [];
  37.         for ($year $currentYear$year >= 2020$year--) {
  38.             $years[] = $year;
  39.         }
  40.         return $years;
  41.     }
  42.     /**
  43.      * @Route("/", name="analyseSST")
  44.      */
  45.     public function index(): Response
  46.     {
  47.         $entities $this->companyEntityRepository->findBy([], ['nom' => 'ASC']);
  48.         $processus $this->processusRepository->findProcessusInternal();
  49.         $jobs $this->jobRepository->findByUserEntity();
  50.         $missions $this->getDoctrine()->getRepository(Mission::class)->findAll();
  51.         $locations $this->getDoctrine()->getRepository(Location::class)->findAll();
  52.         $zones $this->getDoctrine()->getRepository(Zone::class)->findAll();
  53.         $years $this->getYearsList();
  54.         $users $this->getDoctrine()->getRepository(User::class)->findBy([], ['lastname' => 'ASC']);
  55. // Filter users with 'evrp' in their modules
  56.         $usersWithEvrp array_filter($users, function(User $user) {
  57.             $modules $user->getModules() ?? [];
  58.             return in_array('Bilan SST'$modules);
  59.         });
  60. //        $users= $this->getDoctrine()->getRepository(User::class)->findAll();
  61. ////        foreach($processus as $proc)
  62. ////        {
  63. ////            $user = $proc->getPilote();
  64. ////            if(!in_array($user,$users) && (!is_null($user))){
  65. ////                $users[]=$user;
  66. ////            }
  67. ////        }
  68. //        usort($users, function($a, $b) {
  69. //            return strcmp($a->getLastname(), $b->getLastname());
  70. //        });
  71.         $menu="evaluate";
  72.         $left_menu="analyseSST";
  73.         return $this->render('bilanTemplates/analyse_sst/index.html.twig', [
  74.             'menu' => $menu,
  75.             'left_menu' => $left_menu,
  76.             'processus' => $processus,
  77.             'users' => $usersWithEvrp,
  78.             'jobs' => $jobs,
  79.             'missions' => $missions,
  80.             'locations' => $locations,
  81.             'zones' => $zones,
  82.             'years' => $years,
  83.             'entities' => $entities,
  84.         ]);
  85.     }
  86.     /**
  87.      * @Route("/analyseSSTData", name="analyseSSTData", methods={"GET"})
  88.      */
  89.     public function analyseSSTData(Request $requestSituationRisqueRepository $situationRisqueRepository): Response
  90.     {
  91.         $field $request->query->get('field');
  92.         $situationRisqueData $situationRisqueRepository->transformAll($field);
  93.         return new JsonResponse($situationRisqueData);
  94.     }
  95.     // /**
  96.     //  * @Route("/datatableJobFilter", name="datatableJobFilter", methods={"GET"})
  97.     //  */
  98.     // public function datatableJobFilter(Request $request): Response
  99.     // {
  100.         
  101.     //     $em=$this->getDoctrine();
  102.     //     $processus_id= intval($request->query->get('processus_id'));
  103.     //     $job_id= intval($request->query->get('job_id'));
  104.     //     $mission_id= intval($request->query->get('mission_id'));
  105.     //     $user_id= intval($request->query->get('user_id'));
  106.         
  107.         
  108.     //     $user_data='';
  109.     //     $processus_list=[];
  110.     //     $processus_data=[];
  111.     //     $jobs_list=[];
  112.     //     $jobs_data=[];
  113.     //     $missions_list=[];
  114.     //     $missions_data=[];
  115.     //     /*
  116.     //     if($user_id){
  117.     //         $user_data = $user_id;
  118.     //         $user=$em->getRepository(User::class)->find($user_id);
  119.     //         $processus_list=$em->getRepository(Processus::class)->findBy(['pilote'=>$user]);
  120.     //         foreach($processus_list as $processus) {
  121.     //         }
  122.     //     }*/
  123.     //     if($user_id){
  124.     //         $user_data = $user_id;
  125.     //         $user=$em->getRepository(User::class)->find($user_id);
  126.     //         $processus_list=$em->getRepository(Processus::class)->findBy(['pilote'=>$user]);
  127.     //         foreach($processus_list as $proc){
  128.                 
  129.     //             if($proc->getPilote()==$user){
  130.     //                 $selected_processus = false;
  131.     //                 if($proc->getId()==$processus_id){
  132.     //                     $selected_processus=true;
  133.     //                 }
  134.     //                 $processus_data[][$proc->getId()]=[
  135.     //                     "id"=>$proc->getId(),
  136.     //                     "title"=>$proc->getTitle(),
  137.     //                     "selected"=>$selected_processus
  138.     //                 ];
  139.     //             }
  140.     //         }
  141.     //     }else {
  142.     //         $processus_list=$em->getRepository(Processus::class)->findAll();
  143.     //         foreach($processus_list as $proc){
  144.     //             $selected_processus = false;
  145.     //             if($proc->getId()==$processus_id){
  146.     //                 $selected_processus=true;
  147.     //             }
  148.     //             $processus_data[][$proc->getId()]=[
  149.     //                 "id"=>$proc->getId(),
  150.     //                 "title"=>$proc->getTitle(),
  151.     //                 "selected"=>$selected_processus
  152.     //             ];
  153.     //         }
  154.     //     }
  155.         
  156.     //     if($processus_id){
  157.             
  158.     //         $processus=$em->getRepository(Processus::class)->find($processus_id);
  159.     //         $user_data = $processus->getPilote()->getId();
  160.     //         $jobs_list=$em->getRepository(Job::class)->findBy(['processus'=>$processus]);
  161.     //         foreach($jobs_list as $job){
  162.     //             if($job->getProcessus()==$processus){
  163.     //                 $selected_job = false;
  164.     //                 if($job->getId()==$job_id){
  165.     //                     $selected_job=true;
  166.     //                 }
  167.     //                 $jobs_data[][$job->getId()]=[
  168.     //                     "id"=>$job->getId(),
  169.     //                     'title'=>$job->getTitle(),
  170.     //                     'selected'=>$selected_job
  171.     //                 ];
  172.     //             }
  173.     //         }
  174.     //     }else if($user_id){
  175.     //         foreach($processus_list as $processus) {
  176.     //             $jobs_list=$em->getRepository(Job::class)->findBy(['processus'=>$processus]);
  177.     //             foreach($jobs_list as $job){
  178.     //                 if($job->getProcessus()==$processus){
  179.     //                     $selected_job = false;
  180.     //                     if($job->getId()==$job_id){
  181.     //                         $selected_job=true;
  182.     //                     }
  183.     //                     $jobs_data[][$job->getId()]=[
  184.     //                         "id"=>$job->getId(),
  185.     //                         'title'=>$job->getTitle(),
  186.     //                         'selected'=>$selected_job
  187.     //                     ];
  188.     //                 }
  189.     //             }
  190.     //         }
  191.     //     }
  192.     //     else {
  193.     //         $jobs_list=$em->getRepository(Job::class)->findAll();
  194.     //         foreach($jobs_list as $job){
  195.     //             $selected_job = false;
  196.     //             if($job->getId()==$job_id){
  197.     //                 $selected_job=true;
  198.     //             }
  199.     //             $jobs_data[][$job->getId()]=[
  200.     //                 "id"=>$job->getId(),
  201.     //                 'title'=>$job->getTitle(),
  202.     //                 'selected'=>$selected_job
  203.     //             ];
  204.     //         }
  205.     //     }
  206.         
  207.     //     if($job_id){
  208.             
  209.     //         $job=$em->getRepository(Job::class)->find($job_id);
  210.     //         $user_data = $job->getProcessus()->getPilote()->getId();
  211.     //         if(!$processus_id)
  212.     //         {
  213.     //             $processus_id=$job->getProcessus()->getId();
  214.     //             foreach($processus_data as $key=>$proc_data){
  215.     //                 if(array_key_exists($processus_id,$proc_data)){
  216.                         
  217.     //                     $proc_data[$processus_id]['selected']=true;
  218.     //                     $processus_data[$key] = $proc_data;
  219.     //                 }
  220.     //             }
  221.     //         }
  222.     //         $missions_list=$em->getRepository(Mission::class)->findBy(['job'=>$job]);
  223.     //         foreach($missions_list as $mission){
  224.                 
  225.     //             if($mission->getJob()==$job){
  226.     //                 $selected_mission = false;
  227.     //                 if($mission->getId()==$mission_id){
  228.     //                     $selected_mission=true;
  229.     //                 }
  230.     //                 $missions_data[][$mission->getId()]=[
  231.     //                     "id"=>$mission->getId(),
  232.     //                     'title'=>$mission->getTitle(),
  233.     //                     'selected'=>$selected_mission
  234.     //                 ];
  235.     //             }
  236.     //         }
  237.     //     }else {
  238.             
  239.     //         foreach($jobs_list as $job)
  240.     //         {
  241.     //             $missions_list=$em->getRepository(Mission::class)->findBy(['job'=>$job]);
  242.     //             foreach($missions_list as $mission){
  243.     //                 if($mission->getJob()==$job){
  244.     //                     $selected_mission = false;
  245.     //                     if($mission->getId()==$mission_id){
  246.     //                         $selected_mission=true;
  247.     //                     }
  248.     //                     $missions_data[][$mission->getId()]=[
  249.     //                         "id"=>$mission->getId(),
  250.     //                         'title'=>$mission->getTitle(),
  251.     //                         'selected'=>$selected_mission
  252.     //                     ];
  253.     //                 }
  254.     //             }
  255.     //         }
  256.             
  257.     //     }
  258.     //     if($mission_id && !$job_id && !$processus_id && !$user_id){
  259.     //         $mission = $em->getRepository(Mission::class)->find($mission_id);
  260.     //         $job = $mission->getJob();
  261.     //         $processus = $job->getProcessus();
  262.     //         $user = $processus->getPilote();
  263.     //         $user_data = $user->getId();
  264.             
  265.     //         foreach($processus_data as $key=>$proc_data){
  266.     //             if(array_key_exists($processus->getId(),$proc_data)){
  267.     //                 $proc_data[$processus->getId()]['selected']=true;
  268.     //                 $processus_data[$key] = $proc_data;
  269.     //             }
  270.     //         }
  271.     //         foreach($jobs_data as $key=>$job_data){
  272.     //             if(array_key_exists($job->getId(),$job_data)){
  273.     //                 $job_data[$job->getId()]['selected']=true;
  274.     //                 $jobs_data[$key] = $job_data;
  275.     //             }
  276.     //         }
  277.             
  278.     //     }
  279.         
  280.         
  281.     //     $filters=[
  282.     //         'user_data'=>$user_data,
  283.     //         'processus_data'=>$processus_data,
  284.     //         'jobs_data'=>$jobs_data,
  285.     //         'missions_data'=>$missions_data,
  286.     //     ];
  287.         
  288.     //     return new JsonResponse($filters);
  289.     // }
  290.     // /**
  291.     //  * @Route("/datatableLocationFilter", name="datatableLocationFilter", methods={"POST"})
  292.     //  */
  293.     // public function datatableLocationFilter(Request $request): Response
  294.     // {
  295.         
  296.     //     $em=$this->getDoctrine();
  297.     //     $processus_id= intval($request->request->get('processus_id'));
  298.     //     $location_id= intval($request->request->get('location_id'));
  299.     //     $zone_id= intval($request->request->get('zone_id'));
  300.     //     $user_id= intval($request->request->get('user_id'));
  301.         
  302.     //     $user_data='';
  303.     //     $processus_list=[];
  304.     //     $processus_data=[];
  305.     //     $locations_list=[];
  306.     //     $locations_data=[];
  307.     //     $zones_list=[];
  308.     //     $zones_data=[];
  309.     //     if($user_id){
  310.     //         $user_data = $user_id;
  311.     //         $user=$em->getRepository(User::class)->find($user_id);
  312.     //         $processus_list=$em->getRepository(Processus::class)->findBy(['pilote'=>$user]);
  313.     //         foreach($processus_list as $proc){
  314.                 
  315.     //             if($proc->getPilote()==$user){
  316.     //                 $selected_processus = false;
  317.     //                 if($proc->getId()==$processus_id){
  318.     //                     $selected_processus=true;
  319.     //                 }
  320.     //                 $processus_data[][$proc->getId()]=[
  321.     //                     "id"=>$proc->getId(),
  322.     //                     "title"=>$proc->getTitle(),
  323.     //                     "selected"=>$selected_processus
  324.     //                 ];
  325.     //             }
  326.     //         }
  327.     //     }else {
  328.     //         $processus_list=$em->getRepository(Processus::class)->findAll();
  329.     //         foreach($processus_list as $proc){
  330.     //             $selected_processus = false;
  331.     //             if($proc->getId()==$processus_id){
  332.     //                 $selected_processus=true;
  333.     //             }
  334.     //             $processus_data[][$proc->getId()]=[
  335.     //                 "id"=>$proc->getId(),
  336.     //                 "title"=>$proc->getTitle(),
  337.     //                 "selected"=>$selected_processus
  338.     //             ];
  339.     //         }
  340.     //     }
  341.         
  342.     //     if($processus_id){
  343.             
  344.     //         $processus=$em->getRepository(Processus::class)->find($processus_id);
  345.     //         $user_data = $processus->getPilote()->getId();
  346.     //         $locations_list=$em->getRepository(Location::class)->findBy(['processus'=>$processus]);
  347.     //         foreach($locations_list as $location){
  348.     //             if($location->getProcessus()==$processus){
  349.     //                 $selected_location = false;
  350.     //                 if($location->getId()==$location_id){
  351.     //                     $selected_location=true;
  352.     //                 }
  353.     //                 $locations_data[][$location->getId()]=[
  354.     //                     "id"=>$location->getId(),
  355.     //                     'title'=>$location->getName(),
  356.     //                     'selected'=>$selected_location
  357.     //                 ];
  358.     //             }
  359.     //         }
  360.     //     }else if($user_id){
  361.     //         foreach($processus_list as $processus) {
  362.     //             $locations_list=$em->getRepository(Location::class)->findBy(['processus'=>$processus]);
  363.     //             foreach($locations_list as $location){
  364.     //                 if($location->getProcessus()==$processus){
  365.     //                     $selected_location = false;
  366.     //                     if($location->getId()==$location_id){
  367.     //                         $selected_location=true;
  368.     //                     }
  369.     //                     $locations_data[][$location->getId()]=[
  370.     //                         "id"=>$location->getId(),
  371.     //                         'title'=>$location->getName(),
  372.     //                         'selected'=>$selected_location
  373.     //                     ];
  374.     //                 }
  375.     //             }
  376.     //         }
  377.     //     }
  378.     //     else {
  379.     //         $locations_list=$em->getRepository(Location::class)->findAll();
  380.     //         foreach($locations_list as $location){
  381.     //             $selected_location = false;
  382.     //             if($location->getId()==$location_id){
  383.     //                 $selected_location=true;
  384.     //             }
  385.     //             $locations_data[][$location->getId()]=[
  386.     //                 "id"=>$location->getId(),
  387.     //                 'title'=>$location->getName(),
  388.     //                 'selected'=>$selected_location
  389.     //             ];
  390.     //         }
  391.     //     }
  392.         
  393.     //     if($location_id){
  394.             
  395.     //         $location=$em->getRepository(Location::class)->find($location_id);
  396.     //         $user_data = $location->getProcessus()->getPilote()->getId();
  397.     //         if(!$processus_id)
  398.     //         {
  399.     //             $processus_id=$location->getProcessus()->getId();
  400.     //             foreach($processus_data as $key=>$proc_data){
  401.     //                 if(array_key_exists($processus_id,$proc_data)){
  402.                         
  403.     //                     $proc_data[$processus_id]['selected']=true;
  404.     //                     $processus_data[$key] = $proc_data;
  405.     //                 }
  406.     //             }
  407.     //         }
  408.     //         $zones_list=$em->getRepository(Zone::class)->findBy(['location'=>$location]);
  409.     //         foreach($zones_list as $zone){
  410.                 
  411.     //             if($zone->getLocation()==$location){
  412.     //                 $selected_zone = false;
  413.     //                 if($zone->getId()==$zone_id){
  414.     //                     $selected_zone=true;
  415.     //                 }
  416.     //                 $zones_data[][$zone->getId()]=[
  417.     //                     "id"=>$zone->getId(),
  418.     //                     'title'=>$zone->getName(),
  419.     //                     'selected'=>$selected_zone
  420.     //                 ];
  421.     //             }
  422.     //         }
  423.     //     }else {
  424.             
  425.     //         foreach($locations_list as $location)
  426.     //         {
  427.     //             $zones_list=$em->getRepository(Zone::class)->findBy(['location'=>$location]);
  428.     //             foreach($zones_list as $zone){
  429.     //                 if($zone->getLocation()==$location){
  430.     //                     $selected_zone = false;
  431.     //                     if($zone->getId()==$zone_id){
  432.     //                         $selected_zone=true;
  433.     //                     }
  434.     //                     $zones_data[][$zone->getId()]=[
  435.     //                         "id"=>$zone->getId(),
  436.     //                         'title'=>$zone->getName(),
  437.     //                         'selected'=>$selected_zone
  438.     //                     ];
  439.     //                 }
  440.     //             }
  441.     //         }
  442.             
  443.     //     }
  444.     //     if($zone_id && !$location_id && !$processus_id && !$user_id){
  445.     //         $zone = $em->getRepository(Zone::class)->find($zone_id);
  446.     //         $location = $zone->getLocation();
  447.     //         $processus = $location->getProcessus();
  448.     //         $user = $processus->getPilote();
  449.     //         $user_data = $user->getId();
  450.             
  451.     //         foreach($processus_data as $key=>$proc_data){
  452.     //             if(array_key_exists($processus->getId(),$proc_data)){
  453.     //                 $proc_data[$processus->getId()]['selected']=true;
  454.     //                 $processus_data[$key] = $proc_data;
  455.     //             }
  456.     //         }
  457.     //         foreach($locations_data as $key=>$location_data){
  458.     //             if(array_key_exists($location->getId(),$location_data)){
  459.     //                 $location_data[$location->getId()]['selected']=true;
  460.     //                 $locations_data[$key] = $location_data;
  461.     //             }
  462.     //         }
  463.             
  464.     //     }
  465.         
  466.         
  467.     //     $filters=[
  468.     //         'user_data'=>$user_data,
  469.     //         'processus_data'=>$processus_data,
  470.     //         'locations_data'=>$locations_data,
  471.     //         'zones_data'=>$zones_data,
  472.     //     ];
  473.         
  474.     //     return new JsonResponse($filters);
  475.     // }
  476. }