src\Controller\RecController.php line 485

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Avis;
  4. use App\Entity\Histo;
  5. use App\Entity\Terme;
  6. use App\Entity\AvisAr;
  7. use App\Entity\LogCon;
  8. use App\Form\AvisType;
  9. use App\Entity\Domaine;
  10. use App\Entity\Visitor;
  11. use App\Entity\Historic;
  12. use App\Entity\HistoricAr;
  13. use App\Entity\Recommandation;
  14. use App\Entity\RecommandationAr;
  15. use App\Form\RecommandationType;
  16. use App\Form\RecommandationArType;
  17. use PhpOffice\PhpSpreadsheet\IOFactory;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use phpoffice\phpexcel\Classes\PHPExcel;
  20. use phpDocumentor\Reflection\Types\Integer;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  25. use Symfony\Component\Form\Extension\Core\Type\TextType;
  26. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  27. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  28. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  29. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  30. use Knp\Component\Pager\PaginatorInterface;
  31. class RecController extends AbstractController
  32. {
  33.     /**
  34.      * @Route("/rec", name="rec")
  35.      */
  36.     public function index_rec(Request $requestPaginatorInterface $paginator): Response
  37.     {
  38.         $repo $this->getDoctrine()->getRepository(Recommandation::class);
  39.         $query $repo->createQueryBuilder('r')->getQuery();
  40.         $Avisnom $repo->total_av();
  41.         $commission $repo->total_com();
  42.         $total $repo->total();
  43.         $recommandations $paginator->paginate(
  44.             $query,
  45.             $request->query->getInt('page'1),
  46.             // Numéro de la page
  47.             50 // Limite d'affichage
  48.         );
  49.         $recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
  50.         return $this->render('rec/index.html.twig', [
  51.             'recommandations' => $recommandations,
  52.             'nombre' => $total,
  53.             'av' => $Avisnom,
  54.             'com' => $commission
  55.         ]);
  56.     }
  57.     /**
  58.      * @Route("/rec/trad", name="rec_trad")
  59.      */
  60.     public function index_trad(Request $requestPaginatorInterface $paginator): Response
  61.     {
  62.         $repo $this->getDoctrine()->getRepository(Recommandation::class);
  63.         $query $repo->createQueryBuilder('r')->getQuery();
  64.         $Avisnom $repo->total_av();
  65.         $commission $repo->total_com();
  66.         $total $repo->total();
  67.         $recommandations $paginator->paginate(
  68.             $query,
  69.             $request->query->getInt('page'1),
  70.             // Numéro de la page
  71.             50 // Limite d'affichage
  72.         );
  73.         $recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
  74.         return $this->render('rec/index_trad.html.twig', [
  75.             'recommandations' => $recommandations,
  76.             'nombre' => $total,
  77.             'av' => $Avisnom,
  78.             'com' => $commission
  79.         ]);
  80.     }
  81.     /**
  82.      * @Route("/rec/ar", name="rec_ar")
  83.      */
  84.     public function index_ar(Request $requestPaginatorInterface $paginator): Response
  85.     {
  86.         $repo $this->getDoctrine()->getRepository(Recommandation::class);
  87.         $query $repo->createQueryBuilder('r')->getQuery();
  88.         $Avisnom $repo->total_av();
  89.         $commission $repo->total_com();
  90.         $total $repo->total();
  91.         $recommandations $paginator->paginate(
  92.             $query,
  93.             $request->query->getInt('page'1),
  94.             // Numéro de la page
  95.             50 // Limite d'affichage
  96.         );
  97.         $recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
  98.         return $this->render('rec/index_ar.html.twig', [
  99.             'recommandations' => $recommandations,
  100.             'nombre' => $total,
  101.             'av' => $Avisnom,
  102.             'com' => $commission
  103.         ]);
  104.     }
  105.     /**
  106.      * @Route("/rec/new", name="rec_create")
  107.      */
  108.     public function form(Request $requestEntityManagerInterface $manager)
  109.     {
  110.         $histo = new Historic();
  111.         $recommandation = new Recommandation();
  112.         $form $this->createForm(RecommandationType::class, $recommandation);
  113.         $form->add('AvisURL'EntityType::class, [
  114.             'class' => Avis::class,
  115.             'choice_label' => 'Intitule',
  116.             'label' => 'Avis'
  117.         ]);
  118.         $form->add('Ar'RecommandationArType::class);
  119.         $form->handleRequest($request);
  120.         $message null;
  121.         if ($form->isSubmitted() && $form->isValid()) {
  122.             $repo $this->getDoctrine()->getRepository(Recommandation::class);
  123.             $user $this->getUser();
  124.             $recommandationExist $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
  125.             if (!$recommandationExist) {
  126.                 $manager->persist($recommandation);
  127.                 $manager->flush();
  128.                 $message "Cette Recommandation est saisie avec succés";
  129.                 $histo->setRec($recommandation);
  130.                 $histo->setUser($user);
  131.                 $histo->setType("Création");
  132.                 $histo->setDate(new \DateTime());
  133.                 $manager->persist($histo);
  134.                 $manager->flush();
  135.                 return $this->redirect('rec/create.html.twig');
  136.             } else {
  137.                 $message "Cette Recommandation est déjà saisie";
  138.                 return $this->redirect('rec/create.html.twig');
  139.             }
  140.         }
  141.         $av true;
  142.         $lien '/rec/new/';
  143.         return $this->render('rec/create.html.twig', [
  144.             'formRecommandation' => $form->createView(),
  145.             'message' => $message,
  146.             'av' => $av,
  147.             'id' => $av->getid()
  148.             // 'recommandation' => $recommandation
  149.         ]);
  150.     }
  151.     /**
  152.      * @Route("/rec/{id}/edit", name="rec_edit")
  153.      */
  154.     public function formed(int $idRequest $requestEntityManagerInterface $manager)
  155.     {
  156.         $repo $this->getDoctrine()->getRepository(Recommandation::class);
  157.         $recommandation $repo->findOneBy(['id' => $id]);
  158.         $form $this->createForm(RecommandationType::class, $recommandation);
  159.         $form->add('AvisURL'EntityType::class, [
  160.             'class' => Avis::class,
  161.             'choice_label' => 'Intitule',
  162.         ]);
  163.         $form->add('Ar'RecommandationArType::class);
  164.         $form->handleRequest($request);
  165.         $message null;
  166.         if ($form->isSubmitted() && $form->isValid()) {
  167.             $manager->persist($recommandation);
  168.             $manager->flush();
  169.             $message "Cette Recommandation est modifiée avec succés";
  170.             $histo = new Histo();
  171.             $histo->setUser($this->getUser());
  172.             $histo->setType("Modification de recommandation");
  173.             $histo->setDate(new \DateTime());
  174.             $histo->setCommentaire("Modifier la recommandation \"" $recommandation->getRecommandation() . "\"/\"" $recommandation->getAr()->getRecommandation() . "\"  de l'avis \"" $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " $recommandation->getNPage() . "(fr) " $recommandation->getAr()->getNPage() . "(ar)");
  175.             $manager->persist($histo);
  176.             $manager->flush();
  177.         }
  178.         $av true;
  179.         return $this->render('rec/modify.html.twig', [
  180.             'formRecommandation' => $form->createView(),
  181.             'message' => $message,
  182.             'av' => $av,
  183.             'recommandation' => $recommandation
  184.         ]);
  185.     }
  186.     /**
  187.      * @Route("/rec/new/ar", name="rec_create_ar")
  188.      */
  189.     public function form_ar(RecommandationAr $recommandation nullRequest $requestEntityManagerInterface $manager)
  190.     {
  191.         $histo = new HistoricAr();
  192.         $recommandation = new RecommandationAr();
  193.         $form $this->createForm(RecommandationArType::class, $recommandation);
  194.         $form->add('AvisURL'EntityType::class, [
  195.             'class' => AvisAr::class,
  196.             'choice_label' => 'Intitule',
  197.             'label' => 'Avis'
  198.         ]);
  199.         $form->handleRequest($request);
  200.         $message null;
  201.         if ($form->isSubmitted() && $form->isValid()) {
  202.             $repo $this->getDoctrine()->getRepository(RecommandationAr::class);
  203.             $user $this->getUser();
  204.             $recommandationExist $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
  205.             if (!$recommandationExist) {
  206.                 $manager->persist($recommandation);
  207.                 $manager->flush();
  208.                 $message "لقد تمت إضافة هذه التوصية بنجاح";
  209.                 $histo->setRec($recommandation);
  210.                 $histo->setUser($user);
  211.                 $histo->setType("Création");
  212.                 $histo->setDate(new \DateTime());
  213.                 $manager->persist($histo);
  214.                 $manager->flush();
  215.             } else {
  216.                 $message "هذه التوصية موجودة بالفعل";
  217.             }
  218.         }
  219.         $av true;
  220.         return $this->render('rec/create_ar.html.twig', [
  221.             'formRecommandationAr' => $form->createView(),
  222.             'message' => $message,
  223.             'av' => $av,
  224.             'recommandation' => $recommandation
  225.         ]);
  226.     }
  227.     /**
  228.      * @Route("/rec/{id}/edit/ar", name="rec_edit_ar")
  229.      */
  230.     public function formed_ar(int $idRequest $requestEntityManagerInterface $manager)
  231.     {
  232.         $repo $this->getDoctrine()->getRepository(Recommandation::class);
  233.         $recommandation $repo->findOneBy(['Ar' => $id]);
  234.         $form $this->createForm(RecommandationType::class, $recommandation);
  235.         $form->add('AvisURL'EntityType::class, [
  236.             'class' => Avis::class,
  237.             'choice_label' => 'Intitule',
  238.         ]);
  239.         $form->add('Ar'RecommandationArType::class);
  240.         $form->handleRequest($request);
  241.         $message null;
  242.         if ($form->isSubmitted() && $form->isValid()) {
  243.             $manager->persist($recommandation);
  244.             $manager->flush();
  245.             $message "تم تعديل التوصية بنجاح";
  246.             $histo = new Histo();
  247.             $histo->setUser($this->getUser());
  248.             $histo->setType("Modification de recommandation");
  249.             $histo->setDate(new \DateTime());
  250.             $histo->setCommentaire("Modifier la recommandation \"" $recommandation->getRecommandation() . "\"/\"" $recommandation->getAr()->getRecommandation() . "\"  de l'avis \"" $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " $recommandation->getNPage() . "(fr) " $recommandation->getAr()->getNPage() . "(ar)");
  251.             $manager->persist($histo);
  252.             $manager->flush();
  253.         }
  254.         $av true;
  255.         return $this->render('rec/modify_ar.html.twig', [
  256.             'formRecommandation' => $form->createView(),
  257.             'message' => $message,
  258.             'av' => $av,
  259.             'recommandation' => $recommandation
  260.         ]);
  261.     }
  262.     /**
  263.      *@Route("/recom/{domaine}", name="rec_dom")
  264.      */
  265.     public function index_env(string $domaine): Response
  266.     {
  267.         $re $this->getDoctrine()->getRepository(Domaine::class);
  268.         $dom $re->findOneBy(['Intitule' => 'Rapport Annuels']);
  269.         $rep $this->getDoctrine()->getRepository(Avis::class);
  270.         $avis $rep->findBy(['domaineId' => $dom]);
  271.         return $this->render('rec/index_prepa1.html.twig', [
  272.             'Domaine' => $domaine,
  273.             'rapports' => $avis
  274.         ]);
  275.     }
  276.     /**
  277.      *@Route("/rec/{Domaine}", name="rec_domaine")
  278.      */
  279.     public function index_eco(string $DomaineRequest $requestPaginatorInterface $paginator): Response
  280.     {
  281.         $re $this->getDoctrine()->getRepository(Domaine::class);
  282.         $dom $re->findOneBy(['Intitule' => $Domaine]);
  283.         $rep $this->getDoctrine()->getRepository(Avis::class);
  284.         $avis $rep->findBy(['domaineId' => $dom]);
  285.         $repos $this->getDoctrine()->getRepository(Recommandation::class);
  286.         $recommandations $repos->findBy(['AvisURL' => $avis]);
  287.         $repo $this->getDoctrine()->getRepository(Recommandation::class);
  288.         $recommandations $repos->findBy(['AvisURL' => $avis]);
  289.         $query $repo->createQueryBuilder('r')->getQuery();
  290.         $total $repos->total_dom($dom->getId());
  291.         $total_com $rep->total_com($dom->getId());
  292.         $total_avis $rep->total_dom($dom->getId());
  293.         $recommandations $paginator->paginate(
  294.             $query,
  295.             $request->query->getInt('page'1),
  296.             // Numéro de la page
  297.             50 // Limite d'affichage
  298.         );
  299.         $recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
  300.         return $this->render('rec/index_eco.html.twig', [
  301.             'recommandations' => $recommandations,
  302.             'Domaine' => $Domaine,
  303.             'nombre' => $total,
  304.             'nombre_com' => $total_com,
  305.             'nombre_av' => $total_avis
  306.         ]);
  307.     }
  308.     /**
  309.      *@Route("/rec/Environement et developpement durable/ar", name="rec_dom_env")
  310.      */
  311.     public function index_env_ar(): Response
  312.     {
  313.         $domaine "البيئة والتنمية المستدامة";
  314.         return $this->render('rec/index_prepa.html.twig', [
  315.             'Domaine' => $domaine,
  316.         ]);
  317.     }
  318.     /**
  319.      *@Route("/recom/RAPPORTS ANNUELS/ar", name="rec_dom_rap")
  320.      */
  321.     public function index_rap_ar(): Response
  322.     {
  323.         $domaine "التقارير السنوية";
  324.         $re $this->getDoctrine()->getRepository(Domaine::class);
  325.         $dom $re->findOneBy(['Intitule' => 'Rapport Annuels']);
  326.         $rep $this->getDoctrine()->getRepository(Avis::class);
  327.         $avis $rep->findBy(['domaineId' => $dom]);
  328.         return $this->render('rec/index_prepa_ar.html.twig', [
  329.             'Domaine' => $domaine,
  330.             'rapports' => $avis
  331.         ]);
  332.     }
  333.     /**
  334.      *@Route("/rec/{domainefr}/ar", name="rec_domaine_ar")
  335.      */
  336.     public function index_eco_ar(string $domainefrRequest $requestPaginatorInterface $paginator): Response
  337.     {
  338.         $repoo $this->getDoctrine()->getRepository(Domaine::class);
  339.         $Domaine $repoo->findOneBy(['Intitule' => $domainefr]);
  340.         $repo $this->getDoctrine()->getRepository(RecommandationAr::class);
  341.         $query $repo->createQueryBuilder('r')->getQuery();
  342.         $recommandations $repo->findBy(['domainefr' => $domainefr]);
  343.         $total $repo->total_dom($domainefr);
  344.         $total_com $repo->total_dom_com($domainefr);
  345.         $total_avis $repo->total_dom_av($domainefr);
  346.         $recommandations $paginator->paginate(
  347.             $query,
  348.             $request->query->getInt('page'1),
  349.             // Numéro de la page
  350.             50 // Limite d'affichage
  351.         );
  352.         $recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
  353.         return $this->render('rec/index_eco_ar.html.twig', [
  354.             'recommandations' => $recommandations,
  355.             'Domaine' => $Domaine->getIntituleAr(),
  356.             'DomaineF' => $domainefr,
  357.             'nombre' => $total,
  358.             'nombre_com' => $total_com,
  359.             'nombre_av' => $total_avis
  360.         ]);
  361.     }
  362.     /**
  363.      * @Route("/ar", name="home_ar")
  364.      */
  365.     public function home_ar(EntityManagerInterface $manager)
  366.     {
  367.         $reposs $this->getDoctrine()->getRepository(RecommandationAr::class);
  368.         $totalar $reposs->total();
  369.         return $this->render('rec/home_ar.html.twig', [
  370.             'nombrear' => $totalar
  371.         ]);
  372.     }
  373.     /**
  374.      * @Route("/", name="home")
  375.      */
  376.     public function home(EntityManagerInterface $manager)
  377.     {
  378.         if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  379.             $ip $_SERVER['HTTP_CLIENT_IP'];
  380.         }
  381.         //whether ip is from the proxy  
  382.         elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  383.             $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
  384.         }
  385.         //whether ip is from the remote address  
  386.         else {
  387.             $ip $_SERVER['REMOTE_ADDR'];
  388.         } // L'adresse IP du visiteur
  389.         $date date('Y-m-d'); // La date d'aujourd'hui, sous la forme AAAA-MM-JJ
  390.         $visitor = new Visitor();
  391.         $visitor->setIp($ip);
  392.         $visitor->setDate(new \DateTime());
  393.         $manager->persist($visitor);
  394.         $manager->flush();
  395.         $repos $this->getDoctrine()->getRepository(Recommandation::class);
  396.         $total $repos->total();
  397.         $rep $this->getDoctrine()->getRepository(Avis::class);
  398.         $av $rep->av();
  399.         for ($i 2$i 10$i++) {
  400.             $totaldom[$i] = $repos->total_dom($i);
  401.             $total_com[$i] = $rep->total_com($i);
  402.             $total_avis[$i] = $rep->total_dom($i);
  403.         }
  404.         $histo = new LogCon();
  405.         $user $this->getUser();
  406.         $histo->setUser($user);
  407.         $histo->setType("Accueil");
  408.         $histo->setDate(new \DateTime());
  409.         $manager->persist($histo);
  410.         $manager->flush();
  411.         if (!$this->getUser()) {
  412.             return $this->render('rec/home.html.twig', [
  413.                 // 'der' => $lastRow,
  414.                 'nombre' => $total,
  415.                 'totaldom' => $totaldom,
  416.                 'total_com' => $total_com,
  417.                 'total_avis' => $total_avis,
  418.                 'av' => $av
  419.             ]);
  420.         } else {
  421.             if ($this->getUser()->getDomaine() == "Traducteur") {
  422.                 $repo $this->getDoctrine()->getRepository(Terme::class);
  423.                 $nombre count($repo->findAll());
  424.                 $repos $this->getDoctrine()->getRepository(Avis::class);
  425.                 $av count($repos->findAll());
  426.                 $av_ext count($repos->avis_ext('CESE'));
  427.                 $n_ext count($repo->findBy(['avis' => $repos->avis_ext('CESE')]));
  428.                 $org $repo->total_org();
  429.                 $av_int count($repos->findBy(['source' => 'CESE']));
  430.                 $n_int count($repo->findBy(['avis' => $repos->findBy(['source' => 'CESE'])]));
  431.                 return $this->render('accueil/home_trad.html.twig', [
  432.                     'nombre' => $nombre,
  433.                     'n_av' => $av,
  434.                     'n_av_ext' => $av_ext,
  435.                     'n_ext' => $n_ext,
  436.                     'org' => $org,
  437.                     'n_av_int' => $av_int,
  438.                     'n_int' => $n_int
  439.                 ]);
  440.             } else {
  441.                 return $this->render('rec/home.html.twig', [
  442.                     // 'der' => $lastRow,
  443.                     'nombre' => $total,
  444.                     'totaldom' => $totaldom,
  445.                     'total_com' => $total_com,
  446.                     'total_avis' => $total_avis,
  447.                     'av' => $av
  448.                 ]);
  449.             }
  450.         }
  451.     }
  452.     /**
  453.      * @Route("/rec/{id}", name="rec_show")
  454.      */
  455.     public function show($id)
  456.     {
  457.         return $this->render('rec/show.html.twig', [
  458.             'recommandation' => $recommandation
  459.         ]);
  460.     }
  461.     /**
  462.      * @Route("new", name="befor_create")
  463.      */
  464.     public function before()
  465.     {
  466.         $reposi $this->getDoctrine()->getRepository(Avis::class);
  467.         $Avis $reposi->findAll();
  468.         $repos $this->getDoctrine()->getRepository(Recommandation::class);
  469.         $total $repos->total();
  470.         return $this->render('rec/befor_create.html.twig', [
  471.             'Avis' => $Avis,
  472.             'nombre' => $total
  473.         ]);
  474.     }
  475.     /**
  476.      * @Route("new/ar", name="befor_create_ar")
  477.      */
  478.     public function before_ar()
  479.     {
  480.         $reposi $this->getDoctrine()->getRepository(AvisAr::class);
  481.         $Avis $reposi->findAll();
  482.         $repos $this->getDoctrine()->getRepository(RecommandationAr::class);
  483.         $total $repos->total();
  484.         return $this->render('rec/befor_create_ar.html.twig', [
  485.             'Avis' => $Avis,
  486.             'nombre' => $total
  487.         ]);
  488.     }
  489.     /**
  490.     * @Route("/rec/new/{id}", name="rec_create_many")
  491.     
  492.     */
  493.     public function forma(int $idRecommandation $recommandation nullRequest $requestEntityManagerInterface $manager)
  494.     {
  495.         $recommandation = new Recommandation();
  496.         $av false;
  497.         $repoo $this->getDoctrine()->getRepository(Avis::class);
  498.         $avExistt $repoo->findOneBy(['id' => $id]);
  499.         $avar $avExistt->getAr();
  500.         $recommandation->setAvisURL($avExistt);
  501.         $form $this->createForm(RecommandationType::class, $recommandation);
  502.         $form->add('Ar'RecommandationArType::class);
  503.         $form->handleRequest($request);
  504.         $message null;
  505.         if ($form->isSubmitted() && $form->isValid()) {
  506.             $repo $this->getDoctrine()->getRepository(Recommandation::class);
  507.             $recommandationExist $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
  508.             $recommandation->getAr()->setAvisUrl($avar);
  509.             $recommandation->getAr()->setDomainefr($avExistt->getDomaineId()->getIntitule());
  510.             if (!$recommandationExist) {
  511.                 $manager->persist($recommandation);
  512.                 $manager->flush();
  513.                 $message "La Recommandation est saisie avec succés";
  514.                 $histo = new Histo();
  515.                 $histo->setUser($this->getUser());
  516.                 $histo->setType("Ajout Recommandation");
  517.                 $histo->setDate(new \DateTime());
  518.                 $histo->setCommentaire("Ajout la recommandation \"" $recommandation->getRecommandation() . "\"/\"" $recommandation->getAr()->getRecommandation() . "\"  de l'avis \"" $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " $recommandation->getNPage() . "(fr) " $recommandation->getAr()->getNPage() . "(ar)");
  519.                 $manager->persist($histo);
  520.                 $manager->flush();
  521.             } else {
  522.                 $message "Cette Recommandation est déjà saisie";
  523.             }
  524.         }
  525.         return $this->render('rec/create.html.twig', [
  526.             'formRecommandation' => $form->createView(),
  527.             'editMode' => $recommandation->getId() !== null,
  528.             'av' => $av,
  529.             'ar' => $avExistt->getId(),
  530.             'titre' => $avExistt->getIntitule(),
  531.             'message' => $message,
  532.             'recommandation' => $recommandation
  533.             // 'url' => $url
  534.         ]);
  535.     }
  536.     /**
  537.     * @Route("/rec/new/{id}/ar", name="rec_create_many_ar")
  538.     
  539.     */
  540.     public function forma_ar(int $idRecommandation $recommandation nullRequest $requestEntityManagerInterface $manager)
  541.     {
  542.         $recommandation = new Recommandation();
  543.         $av false;
  544.         $repoo $this->getDoctrine()->getRepository(Avis::class);
  545.         $avExistt $repoo->findOneBy(['id' => $id]);
  546.         $avar $avExistt->getAr();
  547.         $recommandation->setAvisURL($avExistt);
  548.         $form $this->createForm(RecommandationType::class, $recommandation);
  549.         $form->add('Ar'RecommandationArType::class);
  550.         $form->handleRequest($request);
  551.         $message null;
  552.         if ($form->isSubmitted() && $form->isValid()) {
  553.             $repo $this->getDoctrine()->getRepository(Recommandation::class);
  554.             $recommandationExist $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
  555.             $user $this->getUser();
  556.             $recommandation->getAr()->setAvisUrl($avar);
  557.             $recommandation->getAr()->setDomainefr($avExistt->getDomaineId()->getIntitule());
  558.             if (!$recommandationExist) {
  559.                 $manager->persist($recommandation);
  560.                 $manager->flush();
  561.                 $message "La Recommandation est saisie avec succés";
  562.                 $histo = new Histo();
  563.                 $histo->setUser($this->getUser());
  564.                 $histo->setType("Ajout Recommandation");
  565.                 $histo->setDate(new \DateTime());
  566.                 $histo->setCommentaire("Ajout la recommandation \"" $recommandation->getAr()->getRecommandation() . "\" de l'avis \"" $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " $recommandation->getAr()->getNPage());
  567.                 $manager->persist($histo);
  568.                 $manager->flush();
  569.             } else {
  570.                 $message "Cette Recommandation est déjà saisie";
  571.             }
  572.         }
  573.         return $this->render('rec/create_ar.html.twig', [
  574.             'formRecommandation' => $form->createView(),
  575.             'editMode' => $recommandation->getId() !== null,
  576.             'av' => $av,
  577.             'ar' => $avExistt->getId(),
  578.             'titre' => $avExistt->getAr()->getIntitule(),
  579.             'message' => $message,
  580.             'recommandation' => $recommandation
  581.         ]);
  582.     }
  583.     /**
  584.      * @Route("/rec/{id}/delete", name="rec_delete")
  585.      */
  586.     public function delete(Request $requestEntityManagerInterface $managerint $id)
  587.     {
  588.         $histo = new Histo();
  589.         $repo $this->getDoctrine()->getRepository(Recommandation::class);
  590.         $recommandation $repo->findOneBy(['id' => $id]);
  591.         $repos $this->getDoctrine()->getRepository(RecommandationAr::class);
  592.         $recommandationAr $repos->findOneBy(['id' => $recommandation->getAr()->getId()]);
  593.         $message null;
  594.         $manager->remove($recommandation);
  595.         $manager->flush();
  596.         $manager->remove($recommandationAr);
  597.         $manager->flush();
  598.         $histo->setUser($this->getUser());
  599.         $histo->setType("Suppression Recommandation");
  600.         $histo->setDate(new \DateTime());
  601.         $histo->setCommentaire("Supprimer la recommandation \"" $recommandation->getRecommandation() . "\" de l'avis \"" $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " $recommandation->getNPage());
  602.         $manager->persist($histo);
  603.         $manager->flush();
  604.         return $this->redirectToRoute('rec_domaine', array('Domaine' => $recommandationAr->getDomainefr()));
  605.     }
  606. }