src/Controller/IndicatorController.php line 260

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ActionPlan;
  4. use App\Entity\Activity;
  5. use App\Entity\bilan\Entity;
  6. use App\Entity\Comments;
  7. use App\Entity\Domain;
  8. use App\Entity\Indicator;
  9. use App\Entity\IndicatorValues;
  10. use App\Entity\Processus;
  11. use App\Entity\SelectedOption;
  12. use App\Enum\CalculModeEnum;
  13. use App\Enum\TypeEnum;
  14. use App\Form\IndicatorType;
  15. use App\Repository\IndicatorRepository;
  16. use App\Repository\IndicatorValuesRepository;
  17. use App\Security\ProcessusVoter;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use App\Utils\Utility;
  24. use Doctrine\Common\Collections\ArrayCollection;
  25. use Doctrine\Common\Inflector\Inflector;
  26. use Symfony\Component\Validator\Constraints\IsNull;
  27. /**
  28.  * @Route("/indicator")
  29.  */
  30. class IndicatorController extends AbstractController
  31. {
  32.     /**
  33.      * @Route("/", name="indicator_index", methods={"GET"})
  34.      */
  35.     public function index(): Response
  36.     {
  37.         $indicators $this->getDoctrine()
  38.             ->getRepository(Indicator::class)
  39.             ->findAll();
  40.         return $this->render('indicator/index.html.twig', [
  41.             'indicators' => $indicators,
  42.         ]);
  43.     }
  44.     /**
  45.      * @Route("/new", name="indicator_new", methods={"GET","POST"})
  46.      */
  47.     public function new(Request $request): Response
  48.     {
  49.         $this->denyAccessUnlessGranted(ProcessusVoter::PROCESSUS_CONFIGURATION_CRUD);
  50.         $indicator = new Indicator();
  51.         /* generate ref indicator */
  52.         $lastIdIndicator=0;
  53.         $lastIndicator $this->getDoctrine()->getRepository(Indicator::class)->findOneBy([], ['id' => 'desc']);
  54.         if(is_object($lastIndicator))
  55.         {
  56.             $lastIdIndicator $lastIndicator->getId();
  57.         }
  58.         $utility = new Utility;
  59.         $refIndicator $utility->generateRef($lastIdIndicator,Indicator::PREFIX);
  60.         $indicator->setRef($refIndicator);
  61.         $options=[];
  62.         $processus_id $request->query->get('processus_id');
  63.         if($processus_id)
  64.         {
  65.             $processus $this->getDoctrine()->getRepository(Processus::class)->find($processus_id);
  66.             $indicator->setProcessus($processus);
  67.             $options['processus_disabled']=true;
  68.         }
  69.         $hasActionPlan $request->query->get('actionplan');
  70.         $indicator->setStatus(Indicator::STATUS_VALIDATED);
  71.         $indicator->setType(Indicator::TYPE_SURVEILLANCE);
  72.         if($hasActionPlan) {
  73.             $options['activity_disabled']=true;
  74.             $indicator->setStatus(Indicator::STATUS_DRAFT);
  75.             $indicator->setType(Indicator::TYPE_OBJECTIF);
  76.         }
  77.         
  78.         $all_processus $this->getDoctrine()->getRepository(Processus::class)->findAll();
  79.         $all_processus = new ArrayCollection($all_processus);
  80.         //$all_processus->removeElement($processus);
  81.         $all_processus_value='';
  82.         foreach($all_processus as $proc)
  83.         {
  84.             $all_processus_value.= $proc->getId();
  85.             if($proc != $all_processus->last())
  86.             {
  87.                 $all_processus_value.=',';
  88.             }
  89.         }
  90.         
  91.         $form $this->createForm(IndicatorType::class, $indicator,$options);
  92.         
  93.         
  94.         return $this->render('indicator/new.html.twig', [
  95.             'indicator' => $indicator,
  96.             'form' => $form->createView(),
  97.             'all_processus_value'=>$all_processus_value
  98.         ]);
  99.     }
  100.     /**
  101.      * @Route("/SaveIndicator", name="SaveIndicator", methods={"POST"})
  102.      */
  103.     public function saveIndicator(Request $request)
  104.     {
  105.         $this->denyAccessUnlessGranted(ProcessusVoter::PROCESSUS_CONFIGURATION_CRUD);
  106.         if (!$request->isXmlHttpRequest()) {
  107.             return new JsonResponse(array('status' => 'error','message' => 'Access forbidden!'), 400);
  108.         }
  109.         if(isset($request->request))
  110.         {
  111.             
  112.             $id $request->request->get('indicatorId');
  113.             $title $request->request->get('title');
  114.             $ref $request->request->get('ref');
  115.             $unity $request->request->get('unity');
  116.             $calculMode $request->request->get('calculMode');
  117.             $period $request->request->get('period');
  118.             $seuilMinAnnual intval($request->request->get('seuilMinAnnual'));
  119.             $seuilMaxAnnual intval($request->request->get('seuilMaxAnnual'));
  120.             $seuilMin intval($request->request->get('seuilMin'));
  121.             $seuilMax intval($request->request->get('seuilMax'));
  122.             $status $request->request->get('status');
  123.             $type $request->request->get('type');
  124.             $entity_id $request->request->get('entity');
  125.             $entity $this->getDoctrine()->getRepository(Entity::class)->find($entity_id);
  126.             $domain_id $request->request->get('domain');
  127.             $domain $this->getDoctrine()->getRepository(Domain::class)->find($domain_id);
  128.             $processus_id $request->request->get('processus');
  129.             
  130.             $processus $this->getDoctrine()->getRepository(Processus::class)->find($processus_id);
  131.             $activity_id $request->request->get('activity');
  132.             $activity $this->getDoctrine()->getRepository(Activity::class)->find($activity_id);
  133.             $proc_ids $request->request->get('proc');
  134.             //consolide part
  135.             $category=$request->request->get('category');
  136.             $indicatorA_id=$request->request->get('indicatorA');
  137.             $indicatorB_id=$request->request->get('indicatorB');
  138.             $operation=$request->request->get('operation');
  139.             
  140.             $user $this->getUser();
  141.             $edit '0';
  142.             if(empty($id))
  143.             {
  144.                 $indicator = new Indicator();
  145.                 $indicator->setRef($ref);
  146.                 $indicator->setType($type);
  147.                 $indicator->setCreatedBy($user);
  148.                 $indicator->setResponsible($user);
  149.             }
  150.             else
  151.             {
  152.                 $indicator $this->getDoctrine()->getRepository(Indicator::class)->find($id);
  153.                 $edit ='1';
  154.             }
  155.             
  156.             $indicator->setTitle($title);
  157.             $indicator->setUnity($unity);
  158.             $indicator->setCalculMode($calculMode);
  159.             $indicator->setPeriod($period);
  160.             $indicator->setSeuilMinAnnual($seuilMinAnnual);
  161.             $indicator->setSeuilMaxAnnual($seuilMaxAnnual);
  162.             $indicator->setSeuilMin($seuilMin);
  163.             $indicator->setSeuilMax($seuilMax);
  164.             $indicator->setProcessus($processus);
  165.             if($entity) {
  166.                 $indicator->setEntity($entity);
  167.             }
  168.             if($domain) {
  169.                 $indicator->setDomain($domain);
  170.             }
  171.             
  172.             //if($type == Indicator::TYPE_SURVEILLANCE) {
  173.             $indicator->setActivity($activity);
  174.             //}
  175.             
  176.             $indicator->setStatus($status);
  177.             $indicator->setCategory($category);
  178.             
  179.             $indicator->removeAllProcessusClients();
  180.             if(!empty($proc_ids))
  181.             {
  182.                 
  183.                 foreach($proc_ids as $element)
  184.                 {
  185.                     $pid_array explode(',',$element);
  186.                     foreach($pid_array as $pid)
  187.                     {
  188.                         if($pid == $indicator->getProcessus()->getId()) continue;
  189.                         
  190.                         $processus_related $this->getDoctrine()->getRepository(Processus::class)->find($pid);
  191.                         $indicator->addProc($processus_related);
  192.                         if($indicator->getActivity())
  193.                         {
  194.                             $indicator->getActivity()->addProcessusClient($processus_related);
  195.                         }
  196.                     }
  197.                 }
  198.                 $indicator->setDataOut(true);
  199.             }else
  200.             {
  201.                 $indicator->setDataOut(false);
  202.             }
  203.             if($category==Indicator::CAT_CONSOLIDE)
  204.             {
  205.                 
  206.                 $indicatorA $this->getDoctrine()->getRepository(Indicator::class)->find($indicatorA_id);
  207.                 $indicatorB $this->getDoctrine()->getRepository(Indicator::class)->find($indicatorB_id);
  208.                 $indicator->setIndicatorA($indicatorA);
  209.                 $indicator->setIndicatorB($indicatorB);
  210.                 $indicator->setOperation($operation);
  211.             }else {
  212.                 $indicator->setIndicatorA(NULL);
  213.                 $indicator->setIndicatorB(NULL);
  214.                 $indicator->setOperation('');
  215.             }
  216.             
  217.             if(empty($id))
  218.             {
  219.                 /* initialize indicator values */
  220.                 $indicatorValues = new IndicatorValues();
  221.                 $indicatorValues->setYear(date('Y'));
  222.                 $indicator->addIndicatorValue($indicatorValues);
  223.             }
  224.             $entityManager $this->getDoctrine()->getManager();
  225.             if(empty($id))
  226.             {
  227.                 $entityManager->persist($indicatorValues);
  228.                 $entityManager->persist($indicator);
  229.             }
  230.             $entityManager->flush();
  231.             $response = array('id' => $indicator->getId(),'title'=>$title,'edit'=>$edit);
  232.         }
  233.         return new JsonResponse($response,200);
  234.     }
  235.     /**
  236.      * @Route("/{id}", name="indicator_show", methods={"GET"})
  237.      */
  238.     public function show(Indicator $indicator,IndicatorRepository $indicatorRepository): Response
  239.     {
  240.         $utility = new Utility;
  241.         $array_indicator_values=[];
  242.         if($indicator->getCategory()==Indicator::CAT_CONSOLIDE)
  243.         {
  244.             $indicatorRepository->setConsolidatedIndicatorValues($indicator);
  245.         }
  246.         $indicatorValues$indicator->getIndicatorValues();
  247.         $user $this->getUser();
  248.         $selectedCalculMode="Brut";
  249.         $selectedOption $this->getDoctrine()->getRepository(SelectedOption::class)->findOneBy(['user'=>$user,'indicator'=>$indicator]);
  250.         if($selectedOption)
  251.         {
  252.             if($selectedOption->getCalculMode())
  253.             {
  254.                 $selectedCalculMode $selectedOption->getCalculMode();
  255.             }
  256.         }
  257.         foreach($indicatorValues as $indicatorValue)
  258.         {
  259.             $array_indicator_value=[];
  260.             $color_parts_array=  $utility->random_rgb_color_array();
  261.             $array_indicator_value['year']=$indicatorValue->getYear();
  262.             $array_indicator_value['fillColor']= $utility->generate_rgb_color($color_parts_array,0.2);
  263.             $array_indicator_value['color']= $utility->generate_rgb_color($color_parts_array,1);
  264.             $array_indicator_value['Jan'] = floatval($indicatorValue->getJan($selectedCalculMode));
  265.             $array_indicator_value['Feb'] = floatval($indicatorValue->getFeb($selectedCalculMode));
  266.             $array_indicator_value['Mar'] = floatval($indicatorValue->getMar($selectedCalculMode));
  267.             $array_indicator_value['Apr'] = floatval($indicatorValue->getApr($selectedCalculMode));
  268.             $array_indicator_value['Mai'] = floatval($indicatorValue->getMai($selectedCalculMode));
  269.             $array_indicator_value['Jun'] = floatval($indicatorValue->getJun($selectedCalculMode));
  270.             $array_indicator_value['Jul'] = floatval($indicatorValue->getJul($selectedCalculMode));
  271.             $array_indicator_value['Aug'] = floatval($indicatorValue->getAug($selectedCalculMode));
  272.             $array_indicator_value['Sep'] = floatval($indicatorValue->getSep($selectedCalculMode));
  273.             $array_indicator_value['Oct'] = floatval($indicatorValue->getOct($selectedCalculMode));
  274.             $array_indicator_value['Nov'] = floatval($indicatorValue->getNov($selectedCalculMode));
  275.             $array_indicator_value['December'] = floatval($indicatorValue->getDecember($selectedCalculMode));
  276.             
  277.             $array_indicator_values[]=$array_indicator_value;
  278.         }
  279.         $user $this->getUser();
  280.         $selectedOption $this->getDoctrine()->getRepository(SelectedOption::class)->findOneBy(['user'=>$user,'indicator'=>$indicator]);
  281.         if(!$selectedOption)
  282.         {
  283.             $selectedOption = new SelectedOption();
  284.             $selectedOption->setChart('courbe');
  285.             $selectedOption->setAddedToDashboard(false);
  286.         }
  287.         return $this->render('indicator/show.html.twig', [
  288.             'indicator' => $indicator,
  289.             'array_indicator_values'  => $array_indicator_values,
  290.             'menu'=>'processus',
  291.             'left_menu'=>"surveillance_performances",
  292.             'selectedOption'=>$selectedOption
  293.         ]);
  294.     }
  295.     /**
  296.      * @Route("/{id}/edit", name="indicator_edit", methods={"GET","POST"})
  297.      */
  298.     public function edit(Indicator $indicator): Response
  299.     {
  300.         $all_processus $this->getDoctrine()->getRepository(Processus::class)->findAll();
  301.         $all_processus = new ArrayCollection($all_processus);
  302.         $all_processus->removeElement($indicator->getProcessus());
  303.         $all_processus_value='';
  304.         foreach($all_processus as $proc)
  305.         {
  306.             $all_processus_value.= $proc->getId();
  307.             if($proc != $all_processus->last())
  308.             {
  309.                 $all_processus_value.=',';
  310.             }
  311.         }
  312.         $all_activity_processus_value='';
  313.         foreach($indicator->getProc() as $proc)
  314.         {
  315.             $all_activity_processus_value.= $proc->getId();
  316.             if($proc != $all_processus->last())
  317.             {
  318.                 $all_activity_processus_value.=',';
  319.             }
  320.         }
  321.         $all_processus_selected=$all_processus_value == $all_activity_processus_value;
  322.         
  323.         $options['category_default']=$indicator->getCategory();
  324.         if($indicator->getType()==Indicator::TYPE_OBJECTIF) {
  325.             $options['processus_disabled']=true;
  326.             $options['activity_disabled']=false;
  327.         }
  328.         $form $this->createForm(IndicatorType::class, $indicator,$options);
  329.         
  330.         return $this->render('indicator/edit.html.twig', [
  331.             'indicator' => $indicator,
  332.             'form' => $form->createView(),
  333.             'all_processus_value'=>$all_processus_value,
  334.             'all_processus_selected'=>$all_processus_selected
  335.         ]);
  336.     }
  337.     /**
  338.      * @Route("/delete/{id}", name="indicator_delete", methods={"GET"})
  339.      */
  340.     public function delete(Indicator $indicatorRequest $request): Response
  341.     {
  342.         $this->denyAccessUnlessGranted(ProcessusVoter::PROCESSUS_CONFIGURATION_CRUD);
  343.         $entityManager $this->getDoctrine()->getManager();
  344.         $entityManager->remove($indicator);
  345.         $entityManager->flush();
  346.         $referer $request->headers->get('referer');
  347.         return $this->redirect($referer);
  348.         //return $this->redirectToRoute('surveillanceGlobal');
  349.     }
  350.     /**
  351.      * @Route("/delete/ajax", name="indicator_delete_ajax", methods={"GET"})
  352.      */
  353.     public function deleteAjax(Request $request)
  354.     {
  355.         $this->denyAccessUnlessGranted(ProcessusVoter::PROCESSUS_CONFIGURATION_CRUD);
  356.         if (!$request->isXmlHttpRequest()) {
  357.             return new JsonResponse(array('status' => 'error','message' => 'Access forbidden!'), 400);
  358.         }
  359.         $id$request->query->get('id');
  360.         $indicator$this->getDoctrine()->getRepository(Indicator::class)->find($id);
  361.         
  362.         $entityManager $this->getDoctrine()->getManager();
  363.         $entityManager->remove($indicator);
  364.         $entityManager->flush();
  365.         $response = array('status' =>'ok');
  366.         
  367.         return new JsonResponse($response,200);
  368.     }
  369.     /**
  370.      * @Route("/surveillance/all", name="surveillance", methods={"GET"})
  371.      */
  372.     public function surveillance(Request $request,IndicatorValuesRepository $indicatorValuesRepository): Response
  373.     {
  374.         
  375.         $actionplanId$request->query->get('actionplanId');
  376.         $processusId$request->query->get('processusId');
  377.         $years $indicatorValuesRepository->getYears();
  378.         
  379.         return $this->render('indicator/surveillance.html.twig',[
  380.             'actionplanId'=>$actionplanId,
  381.             'processusId'=>$processusId,
  382.             'years'=>$years
  383.         ]);
  384.     }
  385.     /**
  386.      * @Route("/surveillanceGlobal/all", name="surveillanceGlobal", methods={"GET"})
  387.      */
  388.     public function surveillanceGlobal(IndicatorRepository $indicatorRepositoryIndicatorValuesRepository $indicatorValuesRepository): Response
  389.     {
  390.         $em $this->getDoctrine()->getManager();
  391.         $processus $em->getRepository(Processus::class)->findAll();
  392.         $entities $em->getRepository(Entity::class)->findAll();
  393.         $domains $em->getRepository(Domain::class)->findAll();
  394.         $years $indicatorValuesRepository->getYears();
  395.         $max_years $indicatorRepository->getMaxYearForEachIndicator();
  396.         $current_year date('Y');
  397.         $new_indicator_values=0;
  398.         foreach($max_years as $max_year){
  399.             if($max_year['year'] < $current_year) {
  400.                 $indicator  $indicatorRepository->find($max_year['id']);
  401.                 $indicatorValues = new IndicatorValues();
  402.                 $indicatorValues->setYear(date('Y'));
  403.                 $indicatorValues->setIndicator($indicator);
  404.                 $em->persist($indicatorValues);
  405.                 $new_indicator_values++;
  406.             }
  407.         }
  408.         if($new_indicator_values 0$em->flush();
  409.         
  410.         //menu 
  411.         $menu="processus";
  412.         $left_menu="surveillance_performances";
  413.         return $this->render('indicator/surveillanceGlobal.html.twig',[
  414.             'processus'=>$processus,
  415.             'entities'=>$entities,
  416.             'domains'=>$domains,
  417.             'years'=>$years,
  418.             'menu'=>$menu,
  419.             'left_menu'=>$left_menu
  420.         ]);
  421.     }
  422.     /**
  423.      * @Route("/list/json", name="indicator_list", methods={"GET"})
  424.      */
  425.     public function listIndicators(IndicatorRepository $indicatorRepository,Request $request)
  426.     {
  427.         
  428.         $actionPlan='';
  429.         $actionplanId$request->query->get('actionplanId');
  430.         if($actionplanId>0)
  431.         {
  432.             $actionPlan$this->getDoctrine()->getRepository(ActionPlan::class)->find($actionplanId);
  433.         }
  434.         $processus='';
  435.         $processusId$request->query->get('processusId');
  436.         if($processusId>0)
  437.         {
  438.             $processus$this->getDoctrine()->getRepository(Processus::class)->find($processusId);
  439.         }
  440.         
  441.         $user $this->getUser();
  442.         
  443.         $actionsData $indicatorRepository->transformAll($user,$actionPlan,$processus);
  444.         return new JsonResponse($actionsData);
  445.     }
  446.     
  447.     /**
  448.      * @Route("/updateIndicatorVlaues", name="update_indicatorValues", methods={"POST"})
  449.      */
  450.     public function updateIndicatorVlaues(Request $request)
  451.     {
  452.         $this->denyAccessUnlessGranted(ProcessusVoter::PROCESSUS_INDICATOR_INSERT);
  453.         if (!$request->isXmlHttpRequest()) {
  454.             return new JsonResponse(array('status' => 'error','message' => 'Access forbidden!'), 400);
  455.         }
  456.         if(isset($request->request))
  457.         {
  458.             $entityManager $this->getDoctrine()->getManager();
  459.             $id $request->request->get('id');
  460.             $indicator_id $request->request->get('indicator_id');
  461.             $columnName $request->request->get('columnName');
  462.             $columnValue $request->request->get('columnValue');
  463.             
  464.             if(empty($columnValue))
  465.             {
  466.                 if($columnValue != "0")
  467.                 {
  468.                     $columnValue=NULL;
  469.                 }
  470.             }
  471.             $id =intval($id);
  472.             $indicatorValue $entityManager->getRepository(IndicatorValues::class)->find($id);
  473.             if($columnName == "setCalculMode")
  474.             {
  475.                 $indicator $entityManager->getRepository(Indicator::class)->find($indicator_id);
  476.                 $user $this->getUser();
  477.                 $selectedOption $entityManager->getRepository(SelectedOption::class)->findOneBy(['user'=>$user,'indicator'=>$indicator]);
  478.                 if($selectedOption)
  479.                 {
  480.                     $selectedOption->$columnName($columnValue);
  481.                 }
  482.                 else
  483.                 {
  484.                     $selectedOption = new SelectedOption();
  485.                     $selectedOption->setUser($user);
  486.                     $selectedOption->setIndicator($indicator);
  487.                     $selectedOption->$columnName($columnValue);
  488.                     $entityManager->persist($selectedOption);
  489.                 }
  490.             }
  491.             else
  492.             {
  493.                 $indicatorValue->$columnName($columnValue);
  494.             }
  495.             $entityManager->flush();
  496.             $response = array(
  497.                 'status' => "ok"
  498.             );
  499.         }
  500.         return new JsonResponse($response,200);
  501.     }
  502.     // /**
  503.     //  * @Route("/{id}/updateSelectedOptions", name="update_selected_options", methods={"POST"})
  504.     //  */
  505.     //  public function updateSelectedOptions(Indicator $indicator, Request $request)
  506.     // {
  507.     //     if(isset($request->request)) {
  508.     //         $entityManager = $this->getDoctrine()->getManager();
  509.     //         $user=$this->getUser();
  510.     //         $chart = $request->request->get('chart');
  511.     //         $addedToDashboard = $request->request->get('in_tdb');
  512.     //         $comment = $request->request->get('comment');
  513.     //         $selectedOption = $entityManager->getRepository(SelectedOption::class)->findOneBy(['user'=>$user,'indicator'=>$indicator]);
  514.     //         if(!$selectedOption)
  515.     //         {
  516.     //             $selectedOption = new SelectedOption();
  517.     //             $selectedOption->setUser($user);
  518.     //             $selectedOption->setIndicator($indicator);
  519.     //             $selectedOption->setChart($chart);
  520.     //             $selectedOption->setAddedToDashboard($addedToDashboard);
  521.     //             $entityManager->persist($selectedOption);
  522.     //         }else {
  523.     //             $selectedOption->setChart($chart);
  524.     //             $selectedOption->setAddedToDashboard($addedToDashboard);
  525.     //         }
  526.     //         $indicator->setComment($comment);
  527.     //         $entityManager->flush();
  528.     //     }
  529.     //     return $this->redirectToRoute('indicator_show',['id'=>$indicator->getId()]);
  530.     // }
  531.     /**
  532.      * @Route("/{id}/updateSelectedOptions", name="update_selected_options", methods={"POST"})
  533.      */
  534.     public function updateSelectedOptions(Indicator $indicatorRequest $request)
  535.     {
  536.         if (!$request->isXmlHttpRequest()) {
  537.             return new JsonResponse(array('status' => 'error','message' => 'Access forbidden!'), 400);
  538.         }
  539.         $response = array('status' => 'nok');
  540.         if(isset($request->request)) {
  541.             $entityManager $this->getDoctrine()->getManager();
  542.             $user=$this->getUser();
  543.             $chart $request->request->get('chart');
  544.             $addedToDashboard $request->request->get('in_tdb');
  545.             $selectedOption $entityManager->getRepository(SelectedOption::class)->findOneBy(['user'=>$user,'indicator'=>$indicator]);
  546.             if(!$selectedOption)
  547.             {
  548.                 $selectedOption = new SelectedOption();
  549.                 $selectedOption->setUser($user);
  550.                 $selectedOption->setIndicator($indicator);
  551.                 $selectedOption->setChart($chart);
  552.                 $selectedOption->setAddedToDashboard($addedToDashboard);
  553.                 $entityManager->persist($selectedOption);
  554.             }else {
  555.                 $selectedOption->setChart($chart);
  556.                 $selectedOption->setAddedToDashboard($addedToDashboard);
  557.             }
  558.             $entityManager->flush();
  559.             $response = array('status' => 'ok');
  560.         }
  561.         return new JsonResponse($response,200);
  562.     }
  563.     /**
  564.      * @Route("/dashboard/all", name="dashboard_indicators", methods={"GET"})
  565.      */
  566.     public function showDashboard(IndicatorRepository $indicatorRepositoryRequest $request)
  567.     {
  568.         //set comment
  569.         $comment $this->getDoctrine()->getRepository(Comments::class)->findOneBy(['object'=>'indicator']);
  570.         if(empty($comment))
  571.         {
  572.             $comment =  new Comments();
  573.             $comment->setCreatedBy($this->getUser());
  574.             $comment->setObject('indicator');
  575.             $entityManager $this->getDoctrine()->getManager();
  576.             $entityManager->persist($comment);
  577.             $entityManager->flush();
  578.         }
  579.         
  580.         $utility = new Utility;
  581.         $user $this->getUser();
  582.         $selected_processus $request->query->get('processus');
  583.         $selectedOptions $this->getDoctrine()->getRepository(SelectedOption::class)->findBy(['user'=>$user,'addedToDashboard'=>1]);
  584.         $indicators_chart_data=[];
  585.         $indicators = [];
  586.         foreach($selectedOptions as $selectedIndicator)
  587.         {
  588.             $indicator $selectedIndicator->getIndicator();
  589.             if(!$indicator) continue;
  590.             if(!empty($selected_processus))
  591.             {
  592.                 
  593.                 if(($indicator->getProcessus()->getId() != $selected_processus)) {
  594.                     if(!$indicator->getProc()->exists(fn($key,$proc)=>$proc->getId()==$selected_processus) ) {
  595.                         continue;
  596.                     }
  597.                 }
  598.             }
  599.             $id $indicator->getId();
  600.             $indicators[]= $indicator;
  601.             if($indicator->getCategory()==Indicator::CAT_CONSOLIDE)
  602.             {
  603.                 $indicatorRepository->setConsolidatedIndicatorValues($indicator);
  604.             }
  605.             $indicatorValues$indicator->getIndicatorValues();
  606.             $indicators_chart_data[$id]['chart'] = $selectedIndicator->getChart();
  607.             foreach($indicatorValues as $indicatorValue)
  608.             {
  609.                 $array_indicator_value=[];
  610.                 $color_parts_array=  $utility->random_rgb_color_array();
  611.                 $array_indicator_value['year']=$indicatorValue->getYear();
  612.                 $array_indicator_value['fillColor']= $utility->generate_rgb_color($color_parts_array,0.2);
  613.                 $array_indicator_value['color']= $utility->generate_rgb_color($color_parts_array,1);
  614.                 $array_indicator_value['Jan'] = floatval($indicatorValue->getJan());
  615.                 $array_indicator_value['Feb'] = floatval($indicatorValue->getFeb());
  616.                 $array_indicator_value['Mar'] = floatval($indicatorValue->getMar());
  617.                 $array_indicator_value['Apr'] = floatval($indicatorValue->getApr());
  618.                 $array_indicator_value['Mai'] = floatval($indicatorValue->getMai());
  619.                 $array_indicator_value['Jun'] = floatval($indicatorValue->getJun());
  620.                 $array_indicator_value['Jul'] = floatval($indicatorValue->getJul());
  621.                 $array_indicator_value['Aug'] = floatval($indicatorValue->getAug());
  622.                 $array_indicator_value['Sep'] = floatval($indicatorValue->getSep());
  623.                 $array_indicator_value['Oct'] = floatval($indicatorValue->getOct());
  624.                 $array_indicator_value['Nov'] = floatval($indicatorValue->getNov());
  625.                 $array_indicator_value['December'] = floatval($indicatorValue->getDecember());
  626.                 $indicators_chart_data[$id]['data'][]=$array_indicator_value;
  627.             }
  628.         }
  629.         //processus
  630.         $processus_list $this->getDoctrine()->getRepository(Processus::class)->findAll();
  631.         
  632.         
  633.         return $this->render('indicator/dashboard.html.twig', [
  634.             'menu'=>'processus',
  635.             'left_menu'=>"tbd_indicators",
  636.             'indicators' => $indicators,
  637.             'indicators_chart_data' => $indicators_chart_data,
  638.             'commentDashboard'=>$comment,
  639.             'processus_list'=>$processus_list,
  640.             'selected_processus'=>$selected_processus
  641.         ]);
  642.     }
  643.     /**
  644.      * @Route("/saveComment/{id}", name="save_indicator_comment", methods={"POST"})
  645.      */
  646.     public function SaveComment(Indicator $indicatorRequest $request)
  647.     {
  648.         $this->denyAccessUnlessGranted(ProcessusVoter::PROCESSUS_CONFIGURATION_CRUD);
  649.         if (!$request->isXmlHttpRequest()) {
  650.             return new JsonResponse(array('status' => 'error','message' => 'Access forbidden!'), 400);
  651.         }
  652.         if(isset($request->request))
  653.         {
  654.             $entityManager $this->getDoctrine()->getManager();
  655.             $commentText $request->request->get('commentText');
  656.             $indicator->setComment($commentText);
  657.             $entityManager->flush();
  658.             $response = array('status' => 'ok');
  659.         }
  660.         return new JsonResponse($response,200);
  661.     }
  662.     /**
  663.      * @Route("/processus/{id}", name="processus_indicators", methods={"GET"})
  664.      */
  665.     public function processusIndicators(Processus $processus)
  666.     {
  667.         $activities $this->getDoctrine()->getRepository(Activity::class)->findBy(['processus'=>$processus]);
  668.         $hasActivities = !empty($activities);
  669.         return $this->render('processus/indicators.html.twig',[
  670.             'processus'=>$processus,
  671.             'hasActivities'=>$hasActivities
  672.         ]);
  673.     }
  674.      /**
  675.      * @Route("/processus/list/{id}", name="processus_indicators_json", methods={"GET"})
  676.      */
  677.     public function processus_indicators_json(Processus $processusIndicatorRepository $indicatorRepository)
  678.     {
  679.         $user $this->getUser();
  680.         $all_processus $this->getDoctrine()->getRepository(Processus::class)->findAll();
  681.         $all_processus = new ArrayCollection($all_processus);
  682.         $indicatorsData $indicatorRepository->transformAllList($processus$user$all_processus);
  683.         return new JsonResponse($indicatorsData);
  684.     }
  685. }