src/Controller/Dysfonctionnement/ReunionController.php line 52

Open in your IDE?
  1. <?php 
  2. namespace App\Controller\Dysfonctionnement;
  3. use App\Entity\ActionPlan;
  4. use App\Entity\Dysfonctionnement\Cause5p;
  5. use App\Entity\Dysfonctionnement\Cause6m;
  6. use App\Entity\Dysfonctionnement\Constat;
  7. use App\Entity\Reunion;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use App\Entity\User;
  13. use App\Notification\SendNotification;
  14. use Dompdf\Dompdf;
  15. use Dompdf\Options;
  16. use Symfony\Component\Filesystem\Filesystem;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. /**
  19.  * @Route("/dysfonctionnement/reunion")
  20.  */
  21. class ReunionController extends AbstractController
  22. {
  23.     private $notifyReunion;
  24.     public function __construct(SendNotification $notifyReunion)
  25.     {
  26.         $this->notifyReunion $notifyReunion;
  27.     }
  28.     /**
  29.      * @Route("/5p/{id}", name="analyse_5p", methods={"GET"})
  30.      */
  31.     public function index5P(Reunion $reunion): Response
  32.     {
  33.         $users $this->getDoctrine()->getRepository(User::class)->findAll();
  34.         $time $reunion->getDurationEstimated()*60;
  35.         return $this->render('dysfonctionnementTemplate/reunion/index.html.twig',[
  36.             'users'=> $users,
  37.             'reunion'=>$reunion,
  38.             'time'=>$time,
  39.             'hide_global_timer'=>true,
  40.         ]);
  41.     }
  42.     /**
  43.      * @Route("/6m/{id}", name="analyse_6m", methods={"GET"})
  44.      */
  45.     public function index6M(Reunion $reunion): Response
  46.     {
  47.         $users $this->getDoctrine()->getRepository(User::class)->findAll();
  48.         $time $reunion->getDurationEstimated()*60;
  49.         $actionplan $reunion->getConstat()->getActionPlanCorrectifDefinitive();
  50.         $all_causes $reunion->getConstat()->getCause6ms();
  51.         $causes_methodes=[];
  52.         $causes_materiels=[];
  53.         $causes_matieres=[];
  54.         $causes_main_doeuvre=[];
  55.         $causes_milieu=[];
  56.         $causes_management=[];
  57.         foreach($all_causes as $cause) {
  58.             switch ($cause->getBranch()) {
  59.                 case Cause6m::BRANCH_METHODES:
  60.                     $causes_methodes[]=$cause;
  61.                     break;
  62.                 case Cause6m::BRANCH_MATERIELS:
  63.                     $causes_materiels[]=$cause;
  64.                     break;
  65.                 case Cause6m::BRANCH_MATIERES:
  66.                     $causes_matieres[]=$cause;
  67.                     break;
  68.                 case Cause6m::BRANCH_MAIN_DOEUVRE:
  69.                     $causes_main_doeuvre[]=$cause;
  70.                     break;
  71.                 case Cause6m::BRANCH_MILIEU:
  72.                     $causes_milieu[]=$cause;
  73.                     break;
  74.                 case Cause6m::BRANCH_MANAGEMENT:
  75.                     $causes_management[]=$cause;
  76.                     break;
  77.             }
  78.         }
  79.         return $this->render('dysfonctionnementTemplate/reunion/reunion_6m.html.twig',[
  80.             'users'=> $users,
  81.             'reunion'=>$reunion,
  82.             'actionplan'=>$actionplan,
  83.             'time'=>$time,
  84.             'causes_methodes'=>$causes_methodes,
  85.             'causes_materiels'=>$causes_materiels,
  86.             'causes_matieres'=>$causes_matieres,
  87.             'causes_main_doeuvre'=>$causes_main_doeuvre,
  88.             'causes_milieu'=>$causes_milieu,
  89.             'causes_management'=>$causes_management,
  90.             'hide_global_timer'=>true,
  91.         ]);
  92.     }
  93.     /**
  94.      * @Route("/pdf/{id}", name="generate_constat_pdf", methods={"GET","POST"})
  95.      */
  96.     public function generate_constat_pdf(Reunion $reunionRequest $request)
  97.     {
  98.         
  99.         $path_logo $this->getParameter('kernel.project_dir').'/public/img/persyst-logo.png';
  100.         $type_logo pathinfo($path_logoPATHINFO_EXTENSION);
  101.         $data_logo file_get_contents($path_logo);
  102.         $base64_logo 'data:image/' $type_logo ';base64,' base64_encode($data_logo);
  103.        
  104.         // Configure Dompdf according to your needs
  105.         $pdfOptions = new Options();
  106.         
  107.         $pdfOptions->set('defaultFont''Arial');
  108.         $pdfOptions->setIsRemoteEnabled(true);
  109.         // Instantiate Dompdf with our options
  110.         $dompdf = new Dompdf($pdfOptions);
  111.         
  112.         // Retrieve the HTML generated in our twig file
  113.         if($reunion->getConstat()->getMethodeAnalyse()==Constat::ANALYSE_5P) {
  114.             $html $this->renderView('pdf/constat_reunion/index.html.twig', [
  115.                 'base64_logo' => $base64_logo,
  116.                 'reunion'=>$reunion
  117.             ]);
  118.         
  119.         }else {
  120.             $html $this->renderView('pdf/constat_reunion/rapport6m.html.twig', [
  121.                 'base64_logo' => $base64_logo,
  122.                 'reunion'=>$reunion
  123.             ]);
  124.         }
  125.         
  126.         // Load HTML to Dompdf
  127.         $dompdf->loadHtml($html);
  128.         
  129.         // (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
  130.         $dompdf->setPaper('A4''portrait');
  131.         
  132.         // Render the HTML as PDF
  133.         $dompdf->render();
  134.         $doc 'reunion_constat_'.$reunion->getRef().'.pdf';
  135.         $dir $this->getParameter('kernel.project_dir').'/public/uploads/pdf/reunion/'.$reunion->getId().'/';
  136.         if (!file_exists($dir)) {
  137.             $fs=new Filesystem();
  138.             $fs->mkdir($dir);
  139.         }
  140.         $output $dompdf->output();
  141.         $pdfFilepath =  $dir.$doc;
  142.         file_put_contents($pdfFilepath$output);
  143.         
  144.         $reunion->setPdfFile('uploads/pdf/reunion/'.$reunion->getId().'/'.$doc);
  145.         
  146.         $this->getDoctrine()->getManager()->flush();
  147.       
  148.         
  149.         $diffuser $request->query->get('diffuser','');
  150.         if($diffuser) {
  151.             foreach ($reunion->getParticipants() as $invited) {
  152.                 $this->notifyReunion->notifyReunion(
  153.                     $reunion->getCreatedBy()->getEmail(),
  154.                     $invited->getUser()->getEmail(),
  155.                     $reunion->getRef(),
  156.                     $reunion->getPdfFile()
  157.                 );
  158.             }
  159.             return $this->redirectToRoute('analyse_5p',array('id'=>$reunion->getId()));
  160.         }
  161.         $dompdf->stream($doc, [
  162.             "Attachment" => true
  163.         ]);
  164.         
  165.     }
  166.     /**
  167.      * @Route("/loadConstats", name="loadConstats", methods={"POST"})
  168.      */
  169.     public function loadConstats(Request $request): JsonResponse
  170.     {
  171.         $constat_id=$request->query->get('constat','');
  172.         
  173.         $type_constat $request->request->get('type_constat''');
  174.         if($type_constat =="Réclamation / plainte") {
  175.             $type_constat "reclamation";
  176.         }
  177.         if($type_constat =="Dysfonctionnement") {
  178.             $type_constat "dysfonctionnement";
  179.         }
  180.         $reunion_title $request->request->get('reunion_title''');
  181.         $methodeAnalyse="6m";
  182.         if($reunion_title =="Arbre des causes - 5P") {
  183.             $methodeAnalyse "5p";
  184.         }
  185.         $constats_data=[];
  186.         if($type_constat) {
  187.             $constats $this->getDoctrine()->getRepository(Constat::class)->findBy(['type'=>$type_constat,'methodeAnalyse'=>$methodeAnalyse]);
  188.             foreach($constats as $constat) {
  189.                 
  190.                 if(!$constat->getReunion() || strval($constat->getId()) == $constat_id) {
  191.                     $constats_data[] = ['id'=>$constat->getId(),'title'=>$constat->getReference()];
  192.                 }
  193.             }
  194.         }
  195.         return new JsonResponse(['constats'=>$constats_data],200);
  196.     }
  197.     /**
  198.      * @Route("/5p/save_cause5p", name="save_cause5p", methods={"POST"})
  199.      */
  200.     public function save_cause5p(Request $request): JsonResponse
  201.     {
  202.         $em $this->getDoctrine()->getManager();
  203.         $id $request->request->get('id');
  204.         $question $request->request->get('question','');
  205.         $reponse $request->request->get('reponse','');
  206.         $maitrisable $request->request->get('maitrisable','non');
  207.         $effet $request->request->get('effet');
  208.         $closed $request->request->get('closed','');
  209.         $maitrisable_bool $maitrisable=='oui';
  210.         $cause5p $this->getDoctrine()->getRepository(Cause5p::class)->find($id);
  211.         $cause5p->setQuestion($question);
  212.         $cause5p->setReponse($reponse);
  213.         $cause5p->setIsMaitrisable($maitrisable_bool);
  214.         $cause5p->setEffet($effet);
  215.         if($closed) {
  216.             $constat $cause5p->getConstat();
  217.             $constat->setIsAnalyseClosed(true);
  218.             if($cause5p->getQuestionNumber() <5) {
  219.                 $rest_cause5p $this->getDoctrine()->getRepository(Cause5p::class)->findCause5ps($cause5p->getQuestionNumber(),$cause5p->getConstat());
  220.                 foreach($rest_cause5p as $cause) {
  221.                     $cause->setIsClosed(true);
  222.                 }
  223.             }
  224.         }
  225.         
  226.         
  227.         $em->flush();
  228.         return new JsonResponse(['updated'=>1]);
  229.     }
  230.     /**
  231.      * @Route("/5p/save_cause5p/all", name="save_all_causes5p", methods={"POST"})
  232.      */
  233.     public function save_all_causes5p(Request $request): JsonResponse
  234.     {
  235.         $all_causes $request->request->get('all_causes',[]);
  236.         if($all_causes) {
  237.             $last_question_number=1;
  238.             foreach($all_causes as $cause) {
  239.                 $cause5p $this->getDoctrine()->getRepository(Cause5p::class)->find($cause['id']);
  240.                 $cause5p->setQuestion($cause['question']);
  241.                 $cause5p->setReponse($cause['reponse']);
  242.                 $maitrisable_bool $cause['maitrisable']=='oui';
  243.                 $cause5p->setIsMaitrisable($maitrisable_bool);
  244.                 $cause5p->setEffet($cause['effet']);
  245.                 $constat $cause5p->getConstat();
  246.                 $last_question_number $cause5p->getQuestionNumber();
  247.             }
  248.             $closed $request->request->get('closed','');
  249.             if($closed) {
  250.                 $constat->setIsAnalyseClosed(true);
  251.                 if($cause5p->getQuestionNumber() <5) {
  252.                     $rest_cause5p $this->getDoctrine()->getRepository(Cause5p::class)->findCause5ps($last_question_number,$constat);
  253.                     foreach($rest_cause5p as $cause) {
  254.                         $cause->setIsClosed(true);
  255.                     }
  256.                 }
  257.             }
  258.             $em $this->getDoctrine()->getManager();
  259.             $em->flush();
  260.         }
  261.         
  262.         return new JsonResponse(['updated'=>1]);
  263.     }
  264.     /**
  265.      * @Route("/save_reunion/{id}", name="save_reunion", methods={"POST"})
  266.      */
  267.     public function save_reunion(Reunion $reunionRequest $request):JsonResponse
  268.     {
  269.         $em$this->getDoctrine()->getManager();
  270.         $responsables $request->request->get('responsables',[]);
  271.         $comment $request->request->get('comment','');
  272.         $constat $reunion->getConstat();
  273.         $constat->removeAllResponsables();
  274.         foreach($responsables as $responsable_id) {
  275.             $responsable$em->getRepository(User::class)->find($responsable_id);
  276.             $constat->addResponsable($responsable);
  277.         }
  278.         
  279.         $reunion->setCommentaire($comment);
  280.         $em->flush();
  281.         return new JsonResponse(['saved'=>1]);
  282.     }
  283. }