src/Controller/Dysfonctionnement/AnalyseController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Dysfonctionnement;
  3. use App\Entity\Dysfonctionnement\CategoryConstat;
  4. use App\Entity\Dysfonctionnement\Constat;
  5. use App\Entity\Processus;
  6. use App\Entity\Reunion;
  7. use App\Entity\User;
  8. use App\EventListener\ConstatUpdated;
  9. use App\Repository\Dysfonctionnement\ConstatRepository;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use Dompdf\Dompdf;
  12. use Dompdf\Options;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\Filesystem\Filesystem;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. /**
  20.  * @Route("/dysfonctionnement/analyse")
  21.  */
  22. class AnalyseController extends AbstractController 
  23. {
  24.     /**
  25.      * @Route("/{id}", name="analyse")
  26.      */
  27.     public function index(Constat $constat ,Request $request): Response
  28.     {
  29.         $menu="ameliorer";
  30.         $left_menu="enregistrer_constat";
  31.         return $this->render('dysfonctionnementTemplate/analyse/index.html.twig', [
  32.             "constat" => $constat,
  33.             "menu" => $menu,
  34.             "left_menu" => $left_menu
  35.         ]);
  36.     }
  37.     /**
  38.      * @Route("/modal/decision/{id}", name="prise_decision_modal", methods={"GET","POST"})
  39.      */
  40.     public function priseDecisionModal(Request $requestConstat $constat): Response
  41.     {
  42.         $processus_list $this->getDoctrine()->getRepository(Processus::class)->findAll();
  43.         $users_list $this->getDoctrine()->getRepository(User::class)->findAll();
  44.         $categoryConstat $this->getDoctrine()->getRepository(CategoryConstat::class)->findAll();
  45.         $users_list_array = [];
  46.         foreach($users_list as $user) {
  47.             $fonction =  str_replace('"'""$user->getFonction());
  48.             $users_list_array[$user->getId()] = $fonction;
  49.         }
  50.         
  51.         return $this->render('dysfonctionnementTemplate/analyse/new.html.twig', [
  52.             'processus_list' => $processus_list,
  53.             'users_list' => $users_list,
  54.             'categoryConstat' => $categoryConstat,
  55.             'users_list_array'=>$users_list_array,
  56.             'constat' => $constat
  57.         ]);
  58.     }
  59.     /**
  60.      * @Route("/prise_decision/{id}", name="prise_decision_new", methods={"GET","POST"})
  61.      */
  62.     public function priseDecision(Request $requestConstat $constat): Response
  63.     {
  64.         $doctrine $this->getDoctrine();
  65.         $entityManager $this->getDoctrine()->getManager();
  66.         if (!$constat) {
  67.             throw $this->createNotFoundException(
  68.                 'There are no constat with the following id: ' $constat->getId()
  69.             );
  70.         }
  71.         $processus_id $request->request->get('processus');
  72.         $processus $doctrine->getRepository(Processus::class)->find($processus_id);
  73.         $category_id $request->request->get('categoryConstat');
  74.         $categoryConstat $doctrine->getRepository(CategoryConstat::class)->find($category_id);
  75.         $responsable_suivi_id $request->request->get('responsable_suivi');
  76.         $responsable_suivi $doctrine->getRepository(User::class)->find($responsable_suivi_id);
  77.         $cout $request->request->get('cout');
  78.         $commentaireDecision $request->request->get('commentaireDecision');
  79.         $is_investigation $request->request->get('is_investigation');
  80.         $action_temp $request->request->get('is_action_temp');
  81.         $cause_planifier $request->request->get('cause_planifier');
  82.         $methode_analyse $request->request->get('methode_analyse');
  83.         $priority $request->request->get('priority');
  84.         if ($is_investigation == "true" ) {
  85.             $constat->setNiveauTraitement("Sans suite");
  86.             $constat->setIsInvestigation(true);
  87.             $constat->setResponsableSuivie(Null);
  88.             $constat->setPriorite(Null);
  89.         }else {
  90.             $constat->setIsInvestigation(false);
  91.             $constat->setResponsableSuivie($responsable_suivi);
  92.             $constat->setPriorite($priority);
  93.         }
  94.         if ($action_temp == "true" ) {
  95.             $constat->setNiveauTraitement("Temporaire");
  96.             $constat->setIsActionTemp(true);
  97.         }else {
  98.             $constat->setIsActionTemp(false);
  99.         }
  100.         if ($cause_planifier == "true" ) {
  101.             $constat->setNiveauTraitement("Définitif");
  102.             $constat->setMethodeAnalyse($methode_analyse);
  103.             $constat->setCausePlanifier(true);
  104.         }
  105.         $constat->setProcessus($processus);
  106.         $constat->setCout(floatval($cout));
  107.         $constat->setCategoryConstat($categoryConstat);
  108.         $constat->setCommentaireDecision($commentaireDecision);
  109.         $constat->setDateCloture( new \DateTime('now'));
  110.         $entityManager->flush();
  111.         return $this->redirectToRoute('analyse',['id'=>$constat->getId()]);
  112.         // $menu="ameliorer";
  113.         // $left_menu="suivi_general";
  114.         // return $this->forward('App\Controller\Dysfonctionnement\AnalyseController::index',[
  115.         //     "constat" => $constat,
  116.         //     "menu" => $menu,
  117.         //     "left_menu" => $left_menu
  118.         // ]);
  119.     }
  120.     /**
  121.      * @Route("/list_pa_preventif/{id}", name="list_pa_preventif", methods={"GET"})
  122.      */
  123.     public function list_pa_preventif(Constat $constat
  124.     {
  125.         $actionPlansPreventif $constat->getActionPlanPreventif();
  126.         $actionPlansPreventif_data=['data'=>[]];
  127.         foreach($actionPlansPreventif->getActions() as $action) {
  128.             $ref=$action->getRef();
  129.             $actionPlansPreventif_data['data'][]=[
  130.                 'pa_ref'=>$ref,
  131.                 'pa_echeance'=>$action->getDateEndEstimated(true),
  132.                 'pa_responsable'=>$action->getCreatedBy()->getFullName(),
  133.                 'pa_title'=>$action->getTitle()
  134.             ];
  135.         }
  136.         return new JsonResponse($actionPlansPreventif_data);
  137.     }
  138.     /**
  139.      * @Route("/constat/generate_pdf/{id}", name="constat_generate_pdf", methods={"GET"})
  140.      */
  141.     public function constat_generate_pdf(Constat $constat)
  142.     {
  143.         $path_logo $this->getParameter('kernel.project_dir').'/public/img/persyst-logo.png';
  144.         $type_logo pathinfo($path_logoPATHINFO_EXTENSION);
  145.         $data_logo file_get_contents($path_logo);
  146.         $base64_logo 'data:image/' $type_logo ';base64,' base64_encode($data_logo);
  147.        
  148.         // Configure Dompdf according to your needs
  149.         $pdfOptions = new Options();
  150.         
  151.         $pdfOptions->set('defaultFont''Arial');
  152.         $pdfOptions->setIsRemoteEnabled(true);
  153.         // Instantiate Dompdf with our options
  154.         $dompdf = new Dompdf($pdfOptions);
  155.         // return $this->render('pdf/constat_analyse/index.html.twig',[
  156.         //     'base64_logo' => $base64_logo,
  157.         //     ''fontawesomecss_path'=>$fontawesomecss_path 
  158.         //     'constat'=>$constat
  159.         // ]);
  160.         
  161.         $html $this->renderView('pdf/constat_analyse/index.html.twig', [
  162.             'base64_logo' => $base64_logo,
  163.             'constat'=>$constat
  164.         ]);
  165.         $dompdf->loadHtml($html);
  166.         
  167.         // (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
  168.         $dompdf->setPaper('A4''portrait');
  169.         
  170.         // Render the HTML as PDF
  171.         $dompdf->render();
  172.         $doc 'constat_'.$constat->getReference().'.pdf';
  173.         $dir $this->getParameter('kernel.project_dir').'/public/uploads/pdf/constat/'.$constat->getId().'/';
  174.         if (!file_exists($dir)) {
  175.             $fs=new Filesystem();
  176.             $fs->mkdir($dir);
  177.         }
  178.         $output $dompdf->output();
  179.         $pdfFilepath =  $dir.$doc;
  180.         file_put_contents($pdfFilepath$output);
  181.         $constat->setPdfFile($pdfFilepath);
  182.         $constat->setEnableListener(false);
  183.         $em$this->getDoctrine()->getManager();
  184.         $em->flush();
  185.         $dompdf->stream($doc, [
  186.             "Attachment" => true
  187.         ]);
  188.         
  189.         
  190.     }
  191. }