src/Controller/Lenord/MainLenordController.php line 475

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Lenord;
  3. use App\Entity\Cantons;
  4. use App\Entity\Commune;
  5. use App\Entity\Contact;
  6. use App\Entity\CustomForm;
  7. use App\Entity\Document;
  8. use App\Entity\Footer;
  9. use App\Entity\FooterSites;
  10. use App\Entity\FormulaireThematique;
  11. use App\Entity\Glossaire;
  12. use App\Entity\InscritNewsletter;
  13. use App\Entity\LogEs;
  14. use App\Entity\MailElu;
  15. use App\Entity\PageAccueil;
  16. use App\Entity\PageAccueilService;
  17. use App\Entity\Pages;
  18. use App\Entity\PageSatellite;
  19. use App\Entity\PagesLegales;
  20. use App\Entity\PolitiqueDepartementale;
  21. use App\Entity\Post;
  22. use App\Entity\Service;
  23. use App\Entity\TypeDocument;
  24. use App\Entity\User;
  25. use DateTime;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Doctrine\ORM\EntityManagerInterface;
  28. use App\Utilities\Feed;
  29. use App\Service\ElasticsearchService;
  30. use App\Service\EpingleService;
  31. use App\Service\OfficeMailService;
  32. use App\Service\WemapService;
  33. use App\Service\RssService;
  34. use App\Service\SendgridMailService;
  35. use App\Service\SeoService;
  36. use Symfony\Component\Routing\Annotation\Route;
  37. use Symfony\Component\HttpFoundation\JsonResponse;
  38. use Symfony\Component\HttpFoundation\Request;
  39. use Symfony\Component\HttpFoundation\Response;
  40. use Dompdf\Dompdf;
  41. use Dompdf\Options;
  42. /**
  43.  * @method User getUser()
  44.  */
  45. //#[Route(host: "lenord.local")]
  46. #[Route(host: "lenord.spontaneit.fr")]
  47. //#[Route(host: "lenord.fr")]
  48. //#[Route(host:"localhost")]
  49. class MainLenordController extends AbstractController
  50. {
  51.   protected mixed $params = [];
  52.   public function __construct(
  53.     private EntityManagerInterface $em,
  54.     private Feed $feedUtilities,
  55.     private ElasticsearchService $es_service,
  56.     private WemapService $wemap_service,
  57.     private RssService $rss_service,
  58.     private EpingleService $epingle_service,
  59.     private SendgridMailService $sendgrid_service,
  60.     private SeoService $seo_service
  61.   ) {
  62.     $this->params['title'] = "";
  63.     $this->params['meta_description'] = "";
  64.     $this->params['footer'] = $this->em->getRepository(Footer::class)->find(1);
  65.     $this->params['epingles'] = [];
  66.     $this->params['is_pdf'] = 0;
  67.     $this->params['is_preview'] = 0;
  68.     $this->params['breadcrumb'] = [];
  69.   }
  70.   
  71.   #[Route(path: '/test_email', name: 'lenord_test_email')]
  72.   public function lenord_test_email(OfficeMailService $mail_service){
  73.     dd($mail_service->testsend());
  74.   }
  75.   
  76.   #[Route(path: '/store_preferences', name: 'lenord_store_preferences')]
  77.   public function storeUserPreferences(Request $request): Response
  78.   {
  79.     $post = $request->request;
  80.     $function = $post->get('function');
  81.     $user = $this->getUser();
  82.     switch ($function) {
  83.       case 'store_dark_mode':
  84.         $user->setDarkMode((int)$post->get('dark_mode'));
  85.         $this->em->persist($user);
  86.         $this->em->flush();
  87.         break;
  88.       case 'store_font_size':
  89.         $user->setFontSize($post->get('font_size'));
  90.         $this->em->persist($user);
  91.         $this->em->flush();
  92.         break;
  93.       case 'store_font_family':
  94.         $user->setFontFamily($post->get('font_family'));
  95.         $this->em->persist($user);
  96.         $this->em->flush();
  97.         break;
  98.     }
  99.     return new JsonResponse(['success' => true]);
  100.   }
  101.   #[Route(path: '/compte-cree/{token}', name: 'user_activate')]
  102.   public function activateUser(string $token): Response
  103.   {
  104.     $user = $this->em->getRepository(User::class)->findOneBy(['token_activation' => $token]);
  105.     if ($user == null) {
  106.       $this->params['message'] = 'Compte déjà activé ou inexistant';
  107.       return $this->render('Nordinfo/Main/endformerror.html.twig', $this->params);
  108.     }
  109.     $user->setTokenActivation(null)
  110.       ->setActive(true);
  111.     $this->em->persist($user);
  112.     $this->em->flush();
  113.     $this->params['message'] = "Grâce à mon compte, <b>mes préférences</b> (lieux de vie, centres d'intérêt) et <b>mes paramètres personnels</b> seront conservés quel que soit le terminal de consultation (smartphone, tablette, ordinateur), de même pour mes contenus mis en favoris. Vous pouvez également <a href='/proposer-un-evenement'>proposer un événement</a> dans l’agenda.";
  114.     if ($user->getRole() == "vip") {
  115.       $this->params['message'] = "Grâce à mon compte, mes préférences (mes lieux de vie, mes centres d’intérêt) et mes paramètres personnels (affichage, favoris) seront conservés quel que soit mon terminal de consultation (smartphone, tablette, ordinateur). Je peux également <a href='/proposer-un-evenement'>proposer un événement</a> dans l’agenda. 
  116.       Mon profil premium me permet d'accéder à des contenus exclusifs ou en avant-première.
  117.       Ces contenus sont indiqués par un cadenas vert dans L'info, Vidéos et dans Mes actus.";
  118.     }
  119.     return $this->render('Nordinfo/Main/endregister.html.twig', $this->params);
  120.   }
  121.   #[Route(path: '/ajax/territory_lenord', name: 'ajax_territory_lenord')]
  122.   public function searchTerritoryLenord(Request $request): Response
  123.   {
  124.     $search = $request->request->get('search');
  125.     //$test = $this->em->getRepository(Cantons::class)->searchCommune($search);
  126.     $test = $this->em->getRepository(Commune::class)->findOneBy(array('commune' => $search));
  127.     if ($test == null) {
  128.       $response = ['error' => 'Aucun territoire trouvé'];
  129.     } else {
  130.       $response = ['error' => false, 't' => ['id' => $test->getTerritoire()->getId(), 'name' => $test->getTerritoire()->getDisplayName()]];
  131.     }
  132.     return new JsonResponse($response);
  133.   }
  134.   #[Route(path: '/', name: 'lenord_home')]
  135.   public function home(): Response
  136.   {
  137.     $this->params['title'] = "";
  138.     $this->params['meta_description'] = "Le site du Département du Nord présentant ses politiques, ses services, son institution et son actualité";
  139.     $this->params['home'] = $this->em->getRepository(PageAccueil::class)->find(1);
  140.     $this->params['strates'] = $this->getOrderStrates($this->params['home']);
  141.     $this->params['politiques'] = $this->em->getRepository(PolitiqueDepartementale::class)->findBy(['statut' => 5], ['ordre' => 'ASC']);
  142.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  143.     $this->params['pages'] = $this->em->getRepository(Pages::class)->getPages(0, 1);
  144.     $this->params['nordinfo_rss'] = null;
  145.     $this->params['rand_image'] = null;
  146.     if ($this->params['home']->getImageActive() == true && $this->params['home']->getImages()->count() > 0) {
  147.       $rand_image = random_int(0, $this->params['home']->getImages()->count() - 1);
  148.       $this->params['rand_image'] = $rand_image;
  149.     }
  150.     if ($this->params['home']->getNordinfoRss() != null) {
  151.       $this->params['nordinfo_rss'] = $this->rss_service->getArrayArticle($this->params['home']->getNordinfoRss());
  152.     }
  153.     $latestEpingle1 = $this->em->getRepository(Post::class)->getLatestEpingle1();
  154.     $latestTwoEpingles2 = $this->em->getRepository(Post::class)->getLatestTwoEpingles2();
  155.     $this->params['latest_epingle_1'] = $latestEpingle1;
  156.     $this->params['latest_two_epingles_2'] = $latestTwoEpingles2;
  157.     // Combine epingles with RSS
  158.     $epinglePosts = [];
  159.     if ($latestEpingle1) {
  160.       $epinglePosts[] = $latestEpingle1;
  161.     }
  162.     if ($latestTwoEpingles2) {
  163.       foreach ($latestTwoEpingles2 as $epingle) {
  164.         $epinglePosts[] = $epingle;
  165.       }
  166.     }
  167.     // Calculate how many RSS posts are needed to reach 3 total
  168.     $neededRssCount = max(0, 3 - count($epinglePosts));
  169.     $nordInfoPosts = [];
  170.     if ($this->params['home']->getNordinfoRss() != null) {
  171.       $allRssArticles = $this->rss_service->getArrayArticle($this->params['home']->getNordinfoRss());
  172.       if ($neededRssCount > 0 && $allRssArticles) {
  173.         $nordInfoPosts = array_slice($allRssArticles, 0, $neededRssCount);
  174.       }
  175.     }
  176.     $this->params['latest_epingle_1'] = $latestEpingle1;
  177.     $this->params['latest_two_epingles_2'] = $latestTwoEpingles2;
  178.     $this->params['nordinfo_rss'] = $nordInfoPosts; // RSS posts to fill the gap
  179.     
  180.     $this->params['home_service'] = $this->em->getRepository(PageAccueilService::class)->find(1);
  181.     $count_services_home = $this->params['home_service']->getServices()->count();
  182.     $this->params['services_forcomplete'] = [];
  183.     if ($count_services_home < 9) {
  184.       $this->params['services_forcomplete'] = $this->em->getRepository(Service::class)->findBy(['statut' => 5], ['view_count' => 'DESC'], 7);
  185.     }
  186.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  187.     $epingles_ = $this->epingle_service->getEpinglesSection('home_lenord');
  188.     foreach ($epingles_ as $epingle) {
  189.       array_push($this->params['epingles'], $epingle);
  190.     }
  191.     return $this->render('Lenord/Main/home.html.twig', $this->params);
  192.   }
  193.   #[Route(path: '/plan-du-site', name: 'lenord_plandusite')]
  194.   public function lenord_plandusite(Request $request): Response
  195.   {
  196.     $this->params['title'] = "Plan du site";
  197.     $this->params['meta_description'] = "Le plan du site du Département du Nord";
  198.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => $this->params['title']]];
  199.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  200.     $this->params['referer'] = $request->headers->get('referer');
  201.     $urls = [];
  202.     $urls['index']['parent']['url'] = $this->generateUrl('lenord_home');
  203.     $urls['index']['parent']['name'] = "Accueil";
  204.     $urls['politiques']['parent']['url'] = $this->generateUrl('lenord_nos_politiques');
  205.     $urls['politiques']['parent']['name'] = "Nos politiques";
  206.     $j = 0;
  207.     $politiques = $this->em->getRepository(PolitiqueDepartementale::class)->findBy(['statut' => 5]);
  208.     foreach ($politiques as $politique) {
  209.       $urls['politiques']['children'][$j]['url'] = $this->generateUrl('lenord_politique', ['alias_url' => $politique->getAliasUrl()]);
  210.       $urls['politiques']['children'][$j]['name'] = $politique->getTitre();
  211.       $j++;
  212.     }
  213.     $urls['institution']['parent']['url'] = $this->generateUrl('lenord_institutions');
  214.     $urls['institution']['parent']['name'] = "L'institution";
  215.     $i = 0;
  216.     $cmsPages = $this->em->getRepository(Pages::class)->getPages(0, 1);
  217.     foreach ($cmsPages as $item) {
  218.       $urls['institution']['children'][$i]['url'] = $this->generateUrl('lenord_pagecms', ['slug' => $item->getAliasUrl()]);
  219.       $urls['institution']['children'][$i]['name'] = $item->getTitre();
  220.       if ($item->getAliasUrl() == "les-conseillers-departementaux") {
  221.         //Elus
  222.         $h = 0;
  223.         $elus = $this->em->getRepository(Contact::class)->getContacts_(1);
  224.         foreach ($elus as $elu) {
  225.           $urls['institution']['children'][$i]['children'][$h]['url'] = $this->generateUrl('elus_lenord_detail', ['slug' => $elu->getSlug()]);
  226.           $urls['institution']['children'][$i]['children'][$h]['name'] = $elu->getFirstName() . ' ' . $elu->getLastName();
  227.           $h++;
  228.         }
  229.       }
  230.       $i++;
  231.     }
  232.     $urls['cartographie']['parent']['url'] = $this->generateUrl('cartographie');
  233.     $urls['cartographie']['parent']['name'] = "Cartographie";
  234.     $urls['documents']['parent']['url'] = $this->generateUrl('espacedoc');
  235.     $urls['documents']['parent']['name'] = "Espace documentaire";
  236.     $urls['support']['parent']['url'] = $this->generateUrl('lenord_support');
  237.     $urls['support']['parent']['name'] = "Contact";
  238.     $urls['glossaire']['parent']['url'] = $this->generateUrl('lenord_glossaire');
  239.     $urls['glossaire']['parent']['name'] = "Glossaire";
  240.     $urls['recherche']['parent']['url'] = $this->generateUrl('lenord_recherche');
  241.     $urls['recherche']['parent']['name'] = "Recherche";
  242.     $urls['infolettre']['parent']['url'] = $this->generateUrl('lenord_page_legale', ['slug' => 'infolettre']);
  243.     $urls['infolettre']['parent']['name'] = "Infolettre";
  244.     $urls['mentionlegale']['parent']['url'] = $this->generateUrl('lenord_page_legale', ['slug' => 'mentions-legales']);
  245.     $urls['mentionlegale']['parent']['name'] = "Mentions légales";
  246.     $urls['accessibilite']['parent']['url'] = $this->generateUrl('lenord_page_legale', ['slug' => 'accessibilite']);
  247.     $urls['accessibilite']['parent']['name'] = "Accessibilité";
  248.     $urls['donneespersonnelles']['parent']['url'] = $this->generateUrl('lenord_page_legale', ['slug' => 'donnees-personnelles']);
  249.     $urls['donneespersonnelles']['parent']['name'] = "Données personnelles";
  250.     $urls['presse']['parent']['url'] = $this->generateUrl('lenord_page_legale', ['slug' => 'presse']);
  251.     $urls['presse']['parent']['name'] = "Espace Presse";
  252.     $urls['schema']['parent']['url'] = $this->generateUrl('lenord_page_legale', ['slug' => 'schema-pluriannuel-accessibilite-numerique']);
  253.     $urls['schema']['parent']['name'] = "Schéma Pluriannuel d'Accessibilité Numérique 2024-2027";
  254.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  255.     $this->params['urls'] = $urls;
  256.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  257.     if ($request->get('function') == 'download_pdf') {
  258.       $this->params['is_pdf'] = 1;
  259.       $pdfOptions = new Options();
  260.       $pdfOptions->set('defaultFont', 'Arial');
  261.       $pdfOptions->setIsRemoteEnabled(true);
  262.       $dompdf = new Dompdf($pdfOptions);
  263.       $html = $this->renderView('Lenord/Main/plandusite.html.twig', $this->params);
  264.       $dompdf->loadHtml($html);
  265.       $dompdf->setPaper('A4', 'portrait');
  266.       $dompdf->render();
  267.       $output = $dompdf->output();
  268.       $filename = sprintf('le-nord-%s.pdf', $this->params['title']);
  269.       return new Response(
  270.         $output,
  271.         200,
  272.         [
  273.           'Content-Type' => 'application/pdf',
  274.           'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  275.         ]
  276.       );
  277.     } else {
  278.       return $this->render('Lenord/Main/plandusite.html.twig', $this->params);
  279.     }
  280.   }
  281.   #[Route(path: '/sitemap.xml', name: 'lenord_plandusite_xml')]
  282.   public function lenord_plandusite_xml(): Response
  283.   {
  284.     $domain = "https://lenord.fr";
  285.     $dom = new \DOMDocument('1.0', 'UTF-8');
  286.     $rss = $dom->createElement('urlset');
  287.     $rss->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
  288.     $rss_node = $dom->appendChild($rss);
  289.     $url = $dom->createElement('url');
  290.     $url_node = $rss_node->appendChild($url);
  291.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_home')));
  292.     $url = $dom->createElement('url');
  293.     $url_node = $rss_node->appendChild($url);
  294.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_nos_politiques')));
  295.     $j = 0;
  296.     $politiques = $this->em->getRepository(PolitiqueDepartementale::class)->findBy(['statut' => 5]);
  297.     foreach ($politiques as $politique) {
  298.       $url = $dom->createElement('url');
  299.       $url_node = $rss_node->appendChild($url);
  300.       $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_politique', ['alias_url' => $politique->getAliasUrl()])));
  301.       $j++;
  302.     }
  303.     $url = $dom->createElement('url');
  304.     $url_node = $rss_node->appendChild($url);
  305.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_institutions')));
  306.     $cmsPages = $this->em->getRepository(Pages::class)->getPages(0, 1);
  307.     foreach ($cmsPages as $item) {
  308.       $url = $dom->createElement('url');
  309.       $url_node = $rss_node->appendChild($url);
  310.       $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_pagecms', ['slug' => $item->getAliasUrl()])));
  311.     }
  312.     $url = $dom->createElement('url');
  313.     $url_node = $rss_node->appendChild($url);
  314.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('cartographie')));
  315.     $url = $dom->createElement('url');
  316.     $url_node = $rss_node->appendChild($url);
  317.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('espacedoc')));
  318.     $url = $dom->createElement('url');
  319.     $url_node = $rss_node->appendChild($url);
  320.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_support')));
  321.     $url = $dom->createElement('url');
  322.     $url_node = $rss_node->appendChild($url);
  323.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_glossaire')));
  324.     $url = $dom->createElement('url');
  325.     $url_node = $rss_node->appendChild($url);
  326.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_recherche')));
  327.     $url = $dom->createElement('url');
  328.     $url_node = $rss_node->appendChild($url);
  329.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_page_legale', ['slug' => 'infolettre'])));
  330.     $url = $dom->createElement('url');
  331.     $url_node = $rss_node->appendChild($url);
  332.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_page_legale', ['slug' => 'mentions-legales'])));
  333.     $url = $dom->createElement('url');
  334.     $url_node = $rss_node->appendChild($url);
  335.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_page_legale', ['slug' => 'accessibilite'])));
  336.     $url = $dom->createElement('url');
  337.     $url_node = $rss_node->appendChild($url);
  338.     $url_node->appendChild($dom->createElement('loc', $domain . $this->generateUrl('lenord_page_legale', ['slug' => 'presse'])));
  339.     //Elus
  340.     $elus = $this->em->getRepository(Contact::class)->getContacts_(1);
  341.     foreach ($elus as $elu) {
  342.       $this->generateUrl('elus_lenord_detail', ['slug' => $elu->getSlug()]);
  343.     }
  344.     $xml = $dom->saveXML();
  345.     $response = new Response($xml);
  346.     $response->headers->set('Content-Type', 'text/xml');
  347.     $response->headers->set('Access-Control-Allow-Origin', '*');
  348.     return $response;
  349.   }
  350.   private function getOrderStrates(mixed $home): mixed
  351.   {
  352.     $array_strate = [];
  353.     if ($home->getImageActive() == true) {
  354.       $array_strate[$home->getOrdreImage()] = 'image';
  355.     }
  356.     if ($home->getActuActive() == true) {
  357.       $array_strate[$home->getOrdreActu()] = 'actu';
  358.     }
  359.     if ($home->getActiveCitation() == true) {
  360.       $array_strate[$home->getOrdreCitation()] = 'citation';
  361.     }
  362.     if ($home->getPolitiqueActive() == true) {
  363.       $array_strate[$home->getOrdrePolitique()] = 'politique';
  364.     }
  365.     if ($home->getInstitutionActive() == true) {
  366.       $array_strate[$home->getOrdreInstitution()] = 'institution';
  367.     }
  368.     if ($home->getNordinfoActive() == true) {
  369.       $array_strate[$home->getOrdreNordinfo()] = 'nordinfo';
  370.     }
  371.     if ($home->getTestimonialActive() == true) {
  372.       $array_strate[$home->getOrdreTestimonial()] = 'testimonial';
  373.     }
  374.     if ($home->getMagazineActive() == true) {
  375.       $array_strate[$home->getOrdreMagazine()] = 'magazine';
  376.     }
  377.     if ($home->getContentActive() == true) {
  378.       $array_strate[$home->getOrdreEditable()] = 'editable';
  379.     }
  380.     if ($home->getContentActive2() == true) {
  381.       $array_strate[$home->getOrdreEditable2()] = 'editable2';
  382.     }
  383.     if ($home->getContentActive3() == true) {
  384.       $array_strate[$home->getOrdreEditable3()] = 'editable3';
  385.     }
  386.     if ($home->getContentActive4() == true) {
  387.       $array_strate[$home->getOrdreEditable4()] = 'editable4';
  388.     }
  389.     if ($home->getContacterPresident() == true) {
  390.       $array_strate[$home->getOrdrePresident()] = 'president';
  391.     }
  392.     if ($home->getServicesActive() == true) {
  393.       $array_strate[$home->getOrdreServices()] = 'services';
  394.     }
  395.     if ($home->getNordEvasionActive() == true) {
  396.       $array_strate[$home->getOrdreNordEvasion()] = 'evasion';
  397.     }
  398.     if ($home->getCartographieActive() == true) {
  399.       $array_strate[$home->getCartographieOrdre()] = 'cartographie';
  400.     }
  401.     if ($home->getMagazineActive() == true) {
  402.       $array_strate[$home->getOrdreMagazine()] = 'magazine';
  403.     }
  404.     if ($home->getContentActive() == true) {
  405.       $array_strate[$home->getOrdreEditable()] = 'html1';
  406.     }
  407.     if ($home->getContentActive2() == true) {
  408.       $array_strate[$home->getOrdreEditable2()] = 'html2';
  409.     }
  410.     if ($home->getContentActive3() == true) {
  411.       $array_strate[$home->getOrdreEditable3()] = 'html3';
  412.     }
  413.     if ($home->getContentActive4() == true) {
  414.       $array_strate[$home->getOrdreEditable4()] = 'html4';
  415.     }
  416.     ksort($array_strate);
  417.     return $array_strate;
  418.   }
  419.   #[Route(path: '/nos-politiques', name: 'lenord_nos_politiques')]
  420.   public function nospolitiques(Request $request): Response
  421.   {
  422.     $this->params['title'] = "Nos politiques";
  423.     $this->params['meta_description'] = "Présentation des politiques du Département du Nord : emploi, autonomie, enfance famille jeunesse, collèges...";
  424.     $this->params['politiques'] = $this->em->getRepository(PolitiqueDepartementale::class)->findBy(['statut' => 5], ['ordre' => 'ASC']);
  425.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  426.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  427.     $epingles_politiques = $this->epingle_service->getEpinglesSection('politique');
  428.     foreach ($epingles_politiques as $epingle) {
  429.       array_push($this->params['epingles'], $epingle);
  430.     }
  431.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Nos politiques']];
  432.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  433.     $this->params['referer'] = $request->headers->get('referer');
  434.     return $this->render('Lenord/Main/nospolitiques.html.twig', $this->params);
  435.   }
  436.   #[Route(path: '/l-institution', name: 'lenord_institutions')]
  437.   public function lenord_institutions(Request $request): Response
  438.   {
  439.     $this->params['title'] = "L'institution";
  440.     $this->params['meta_description'] = "Présentation de l'institution du Département du Nord : son fonctionnnement, ses élus, son budget et son histoire";
  441.     $this->params['pages'] = $this->em->getRepository(Pages::class)->getPages(0, 1);
  442.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  443.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  444.     $epingles_politiques = $this->epingle_service->getEpinglesSection('institution');
  445.     foreach ($epingles_politiques as $epingle) {
  446.       array_push($this->params['epingles'], $epingle);
  447.     }
  448.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'L\'institution']];
  449.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  450.     $this->params['referer'] = $request->headers->get('referer');
  451.     return $this->render('Lenord/Main/institutions.html.twig', $this->params);
  452.   }
  453.   #[Route(path: '/nos-politiques/{alias_url}', name: 'lenord_politique')]
  454.   public function politique(Request $request, string $alias_url): Response
  455.   {
  456.     $this->params['politique'] = $this->em->getRepository(PolitiqueDepartementale::class)->findOneBy(['alias_url' => $alias_url]);
  457.     $this->params['title'] = $this->params['politique']->getTitre() . " - Nos politiques";
  458.     $this->params['meta_description'] = $this->params['politique']->getChapo();
  459.     $this->params['content_post'] = $this->feedUtilities->jsonToHtml($this->params['politique']->getContent(), $request, $this->params['title']);
  460.     $this->params['nordinfo_rss'] = null;
  461.     $this->params['nordinfo_rss_description'] = null;
  462.     if ($this->params['politique']->getNordinfoRss() != null) {
  463.       $this->params['nordinfo_rss'] = $this->rss_service->getArrayArticle($this->params['politique']->getNordinfoRss());
  464.       $this->params['nordinfo_rss_description'] = $this->params['politique']->getNordinfoRss()->getDescription();
  465.     }
  466.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  467.     $epingles_politiques = $this->epingle_service->getEpinglesSection('politique');
  468.     foreach ($epingles_politiques as $epingle) {
  469.       array_push($this->params['epingles'], $epingle);
  470.     }
  471.     foreach ($this->params['politique']->getEpingles() as $e) {
  472.       if ($e->getActive() == true) {
  473.         array_push($this->params['epingles'], $e);
  474.       }
  475.     }
  476.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '/nos-politiques', 'titre' => 'Nos politiques'], ['alias' => '', 'titre' => $this->params['politique']->getTitre()]];
  477.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  478.     $this->params['openGraph'] = ["title" => $this->params['politique']->getTitre(), "url" => "https://lenord.fr/" . $alias_url, "image" => "https://lenord.fr/img/brandmaster/logo-le-nord.svg", "type" => "website", "description" => $this->params['content_post']];
  479.     $this->params['referer'] = $request->headers->get('referer');
  480.     $this->params['is_page_politique'] = true;
  481.     if ($request->get('function') == 'download_pdf') {
  482.       $this->params['is_pdf'] = 1;
  483.       $pdfOptions = new Options();
  484.       $pdfOptions->set('defaultFont', 'Arial');
  485.       $pdfOptions->setIsRemoteEnabled(true);
  486.       $dompdf = new Dompdf($pdfOptions);
  487.       $html = $this->renderView('Lenord/Main/politique.html.twig', $this->params);
  488.       $dompdf->loadHtml($html);
  489.       $dompdf->setPaper('A4', 'portrait');
  490.       $dompdf->render();
  491.       $output = $dompdf->output();
  492.       $filename = sprintf('le-nord-%s.pdf', $this->params['title']);
  493.       return new Response(
  494.         $output,
  495.         200,
  496.         [
  497.           'Content-Type' => 'application/pdf',
  498.           'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  499.         ]
  500.       );
  501.     } else {
  502.       return $this->render('Lenord/Main/politique.html.twig', $this->params);
  503.     }
  504.   }
  505.   #[Route(path: '/departement/lepresident', name: 'lenord_president')]
  506.   public function lenord_president(Request $request): Response
  507.   {
  508.     $this->params['title'] = "Le Président";
  509.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  510.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => $this->params['title']]];
  511.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  512.     $this->params['referer'] = $request->headers->get('referer');
  513.     if ($request->get('function') == 'download_pdf') {
  514.       $this->params['is_pdf'] = 1;
  515.       $pdfOptions = new Options();
  516.       $pdfOptions->set('defaultFont', 'Arial');
  517.       $pdfOptions->setIsRemoteEnabled(true);
  518.       $dompdf = new Dompdf($pdfOptions);
  519.       $html = $this->renderView('Lenord/Main/page.html.twig', $this->params);
  520.       $dompdf->loadHtml($html);
  521.       $dompdf->setPaper('A4', 'portrait');
  522.       $dompdf->render();
  523.       $output = $dompdf->output();
  524.       $filename = sprintf('le-nord-%s.pdf', $this->params['title']);
  525.       return new Response(
  526.         $output,
  527.         200,
  528.         [
  529.           'Content-Type' => 'application/pdf',
  530.           'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  531.         ]
  532.       );
  533.     } else {
  534.       return $this->render('Lenord/Main/page.html.twig', $this->params);
  535.     }
  536.   }
  537.   #[Route(path: '/glossaire', name: 'lenord_glossaire')]
  538.   public function glossaire(Request $request): Response
  539.   {
  540.     $this->params['title'] = "Glossaire";
  541.     $this->params['meta_description'] = "Le glossaire du site du Département du Nord : acronymes et définitions utiles";
  542.     $glossaire = $this->em->getRepository(Glossaire::class)->findBy([], ['terme' => 'ASC']);
  543.     $this->params['glossaires'] = $glossaire;
  544.     $this->params['letters'] = $this->em->getRepository(Glossaire::class)->getFirstLetters();
  545.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  546.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  547.     $epingles_ = $this->epingle_service->getEpinglesSection('glossaire_lenord');
  548.     foreach ($epingles_ as $epingle) {
  549.       array_push($this->params['epingles'], $epingle);
  550.     }
  551.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Glossaire']];
  552.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  553.     $this->params['referer'] = $request->headers->get('referer');
  554.     return $this->render('Lenord/Main/glossaire.html.twig', $this->params);
  555.   }
  556.   #[Route(path: '/espace-documentaire', name: 'espacedoc')]
  557.   public function espacedoc(Request $request): Response
  558.   {
  559.     $this->params['title'] = "Espace documentaire";
  560.     $this->params['meta_description'] = "Consulter et télécharger les documents officiels produits par le Département du Nord";
  561.     $this->params['types_document'] = $this->em->getRepository(TypeDocument::class)->findAll();
  562.     $page_number = $request->query->getInt('page', 1);
  563.     $items_per_page = 24;
  564.     $types = [];
  565.     $types_libelle = [];
  566.     if ($request->query->get('types') != null) {
  567.       //$array_fields = array('sousprofils.alias');
  568.       foreach ((array)$request->query->get('types') as $id) {
  569.         array_push($types, $id);
  570.         $t = $this->em->getRepository(TypeDocument::class)->find($id);
  571.         array_push($types_libelle, $t->getTitre());
  572.         $this->params['title'] .= ' ' . '"' . $t->getTitre() . '"';
  573.       }
  574.     }
  575.     $search = $request->query->get('search');
  576.     if ($search == "") {
  577.       $search = null;
  578.     }
  579.     if ($request->query->get('_items_per_page') != null) {
  580.       $items_per_page = $request->query->get('_items_per_page');
  581.     }
  582.     $this->params['filters'] = $types;
  583.     $this->params['types_libelle'] = $types_libelle;
  584.     $this->params['search'] = $search;
  585.     $this->params['pagination'] = $this->em->getRepository(Document::class)->getDocuments($page_number, $types, $search, $items_per_page);
  586.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  587.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  588.     $epingles_ = $this->epingle_service->getEpinglesSection('espace_documentaire');
  589.     foreach ($epingles_ as $epingle) {
  590.       array_push($this->params['epingles'], $epingle);
  591.     }
  592.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Espace documentaire']];
  593.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  594.     $this->params['referer'] = $request->headers->get('referer');
  595.     return $this->render('Lenord/Main/espacedoc.html.twig', $this->params);
  596.   }
  597.   #[Route(path: '/espace-documentaire/{slug}', name: 'document')]
  598.   public function document(Request $request, string $slug): Response
  599.   {
  600.     $this->params['document'] = $this->em->getRepository(Document::class)->findOneBy(['alias_url' => $slug]);
  601.     $this->params['title'] = $this->params['document']->getTitre() . " - Espace documentaire";
  602.     $this->params['meta_description'] = "Consulter et télécharger les documents officiels produits par le Département du Nord";
  603.     $this->params['content_post'] = $this->feedUtilities->jsonToHtml($this->params['document']->getContent(), $request, $this->params['title']);
  604.     $this->params['documents_lies'] = [];
  605.     if ((is_countable($this->params['document']->getDocumentsLies()) ? count($this->params['document']->getDocumentsLies()) : 0) < 3) {
  606.       $maxResult = 3 - (is_countable($this->params['document']->getDocumentsLies()) ? count($this->params['document']->getDocumentsLies()) : 0);
  607.       $types = [];
  608.       foreach ($this->params['document']->getTypes() as $ty) {
  609.         array_push($types, $ty->getId());
  610.       }
  611.       $this->params['documents_lies'] = $this->em->getRepository(Document::class)->getSameCategory($this->params['document']->getId(), $maxResult, $types);
  612.     }
  613.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  614.     foreach ($this->params['document']->getEpingles() as $e) {
  615.       if ($e->getActive() == 1) {
  616.         array_push($this->params['epingles'], $e);
  617.       }
  618.     }
  619.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '/espace-documentaire', 'titre' => 'Espace documentaire'], ['alias' => '', 'titre' => $this->params['document']->getTitre()]];
  620.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  621.     $this->params['referer'] = $request->headers->get('referer');
  622.     $this->params['is_page_document'] = true;
  623.     if ($request->get('function') == 'download_pdf') {
  624.       $this->params['is_pdf'] = 1;
  625.       $pdfOptions = new Options();
  626.       $pdfOptions->set('defaultFont', 'Arial');
  627.       $pdfOptions->setIsRemoteEnabled(true);
  628.       $dompdf = new Dompdf($pdfOptions);
  629.       $html = $this->renderView('Lenord/Main/document.html.twig', $this->params);
  630.       $dompdf->loadHtml($html);
  631.       $dompdf->setPaper('A4', 'portrait');
  632.       $dompdf->render();
  633.       $output = $dompdf->output();
  634.       $filename = sprintf('le-nord-%s.pdf', $this->params['title']);
  635.       return new Response(
  636.         $output,
  637.         200,
  638.         [
  639.           'Content-Type' => 'application/pdf',
  640.           'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  641.         ]
  642.       );
  643.     } else {
  644.       return $this->render('Lenord/Main/document.html.twig', $this->params);
  645.     }
  646.   }
  647.   #[Route(path: '/formulaire-de-contact', name: 'lenord_support')]
  648.   public function lenord_support(Request $request): Response
  649.   {
  650.     $this->params['title'] = "Formulaire de contact";
  651.     $this->params['meta_description'] = "Contacter le Département du Nord et ses services par courriel";
  652.     $this->params['referer'] = $request->headers->get('referer');
  653.     $this->params['caps'] = $this->getCaptcha();
  654.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  655.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Formulaire de contact']];
  656.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  657.     $this->params['thematiques'] = $this->em->getRepository(FormulaireThematique::class)->findBy(['bool_lenord' => 1], ['name' => 'ASC']);
  658.     return $this->render('Lenord/Main/support.html.twig', $this->params);
  659.   }
  660.   #[Route(path: '/formulaire-de-contact/{thematique}', name: 'lenord_support_thematique')]
  661.   public function lenord_support_thematique(Request $request, string $thematique): Response
  662.   {
  663.     $this->params['title'] = "Formulaire de contact";
  664.     $this->params['meta_description'] = "Contacter le Département du Nord et ses services par courriel";
  665.     $this->params['referer'] = $request->headers->get('referer');
  666.     $this->params['caps'] = $this->getCaptcha();
  667.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  668.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Formulaire de contact']];
  669.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  670.     $this->params['thematiques'] = $this->em->getRepository(FormulaireThematique::class)->findBy(['bool_lenord' => 1], ['name' => 'ASC']);
  671.     $this->params['chosen_thematique'] = $thematique;
  672.     return $this->render('Lenord/Main/support.html.twig', $this->params);
  673.   }
  674.   /*#[Route(path: '/formulaire-{slug}', name: 'custom_form_lenord', host: "lenord.fr")]
  675.   public function custom_form(string $slug): Response
  676.   {
  677.     $custom_form = $this->em->getRepository(CustomForm::class)->findOneBy(array('alias' => $slug));
  678.     $this->params['caps'] = $this->getCaptcha();
  679.     $this->params['form'] = $custom_form;
  680.     return $this->render('Lenord/Main/custom_form.html.twig', $this->params);
  681.   }*/
  682.   #[Route(path: '/send_form_custom/{alias}', name: 'send_form_custom_lenord', host: "lenord.fr")]
  683.   public function send_form_custom(Request $request, string $alias): Response
  684.   {
  685.     $post = $request->request;
  686.     $custom_form = $this->em->getRepository(CustomForm::class)->findOneBy(array('alias' => $alias));
  687.     $destinataires_sendgrid = [];
  688.     $objet = null;
  689.     $objet = "Votre message à " . $custom_form->getDestinataire() . " via le site du Département du Nord";
  690.     $emails = explode(";", (string) $custom_form->getEmail());
  691.     for ($i = 0; $i < count($emails); $i++) {
  692.       array_push($destinataires_sendgrid, $emails[$i]);
  693.     }
  694.     $message = $post->get('message');
  695.     //exp
  696.     //destinataire_
  697.     //objet_
  698.     //message_
  699.     //piece_jointe_
  700.     $fileName = null;
  701.     $auth_extension = ['png', 'jpg', 'jpeg', 'gif', 'pdf'];
  702.     $mime_authorized = ['application/pdf', 'image/jpg', 'image/jpeg', 'image/gif', 'image/png'];
  703.     $file = null;
  704.     $newname = uniqid();
  705.     if ($request->files != null && $request->files->get('file') != null) {
  706.       $file = $request->files->get('file');
  707.       $fileName = $file->getClientOriginalName();
  708.       $fileType = $file->getClientMimeType();
  709.       if (in_array($file->guessExtension(), $auth_extension) && in_array($fileType, $mime_authorized)) {
  710.         /*try {
  711.           $file->move($uploadDir, $newname.'.'.$file->guessExtension());
  712.           array_push($files, array(
  713.             'name' => $newname.'.'.$file->guessExtension(),
  714.             'type' => $fileType,
  715.             'data' => $fileData,
  716.           ));
  717.         } catch (FileException) {
  718.           $file = null;
  719.           return new JsonResponse(['error' => 'File could not be uploaded']);
  720.         }*/
  721.       } else {
  722.         $file = null;
  723.         return new JsonResponse(['error' => "Mauvais format d'image"]);
  724.       }
  725.     }
  726.     $date = new DateTime;
  727.     $content = "Le message suivant vient de vous être envoyé via le site du Département du Nord par " . $post->get('nom_prenom') .
  728.       " - Merci de répondre directement à " . $post->get('email') . " : " . "\n" . $post->get('message') . "\n\n" . "Nord, le Département est là - https://lenord.fr/";
  729.     $nom_dest = $custom_form->getDestinataire();
  730.     $content_exp = "Bonjour, votre message a été transmis à " . $nom_dest . "." . "\n\n" .
  731.       "Message : " . $post->get('message');
  732.     if ($fileName !== null) {
  733.       $content_exp .= "\n" . "Pièce jointe : " . $fileName;
  734.     }
  735.     $content_exp .= "\n\n" . "Nord, le Département est là - https://lenord.fr/";
  736.     //envoi mail
  737.     $result_ = $post->get('nb1') + $post->get('nb2');
  738.     if ($result_ == $post->get('captcha') && $post->get('raison') == null) {
  739.       try {
  740.         $this->sendgrid_service->send($destinataires_sendgrid, $content, "Message envoyé par " . $post->get('nom_prenom') . " via le site du Département du Nord", null, $file, false, $post->get('email'));
  741.         $this->sendgrid_service->send([$post->get('email')], $content_exp, $objet, null, $file, false);
  742.       } catch (\Exception) {
  743.         $this->params['message'] = 'Email erreur';
  744.         return $this->render('Lenord/Main/endformerror.html.twig', $this->params);
  745.       }
  746.     } else {
  747.       $this->params['message'] = 'Catcha erreur';
  748.       return $this->render('Lenord/Main/endformerror.html.twig', $this->params);
  749.     }
  750.     return $this->render('Lenord/Main/endform.html.twig', $this->params);
  751.   }
  752.   #[Route(path: '/confirmation', name: 'lenord_send_form')]
  753.   public function sendform(Request $request): Response
  754.   {
  755.     $post = $request->request;
  756.     $result_ = $post->get('nb1') + $post->get('nb2');
  757.     if ($result_ == $post->get('captcha')) {
  758.       $destinataires_sendgrid = [];
  759.       $message = $post->get('message');
  760.       //Thematique
  761.       $thematique = null;
  762.       if ($post->get('thematique') !== null) {
  763.         $formThematique = $this->em->getRepository(FormulaireThematique::class)->find($post->get('thematique'));
  764.         $thematique = $formThematique->getName();
  765.         $emails = explode(";", (string) $formThematique->getDestinataires());
  766.         for ($i = 0; $i < count($emails); $i++) {
  767.           array_push($destinataires_sendgrid, $emails[$i]);
  768.         }
  769.       } else {
  770.         $thematique = 'Message à un(e) élu(e) : ' . $request->request->get('dest_nom');
  771.         array_push($destinataires_sendgrid, $request->request->get('dest'));
  772.         $mail_elu = new MailElu;
  773.         $userIp = $request->getClientIp();
  774.         $mail_elu->setDate(new DateTime())
  775.           ->setElu($request->request->get('dest_nom'))
  776.           ->setContenu($message)
  777.           ->setIp($userIp)
  778.           ->setEmail($post->get('email'));
  779.         $this->em->persist($mail_elu);
  780.         $this->em->flush();
  781.       }
  782.       //exp
  783.       //destinataire_
  784.       //objet_
  785.       //message_
  786.       //piece_jointe_
  787.       $fileName = null;
  788.       $auth_extension = ['png', 'jpg', 'jpeg', 'gif', 'pdf'];
  789.       $mime_authorized = ['application/pdf', 'image/jpg', 'image/jpeg', 'image/gif', 'image/png'];
  790.       $file = null;
  791.       if ($request->files != null && $request->files->get('file') != null) {
  792.         $file = $request->files->get('file');
  793.         $fileName = $file->getClientOriginalName();
  794.         $fileType = $file->getClientMimeType();
  795.         if (in_array($file->guessExtension(), $auth_extension) && in_array($fileType, $mime_authorized)) {
  796.           /*try {
  797.           } catch (FileException) {
  798.             $file = null;
  799.             return new JsonResponse(['error' => 'File could not be uploaded']);
  800.           }*/
  801.         } else {
  802.           $file = null;
  803.           return new JsonResponse(['error' => "Mauvais format d'image"]);
  804.         }
  805.       }
  806.       $date = new DateTime();
  807.       $content = $this->renderView(
  808.         'Lenord/Mails/dest_signalement2.html.twig',
  809.         ['site' => 'lenord', 
  810.         'expediteur_email_' => ($post->get('prenom') != null && $post->get('nom') != null) ? $post->get('prenom') . ' ' . $post->get('nom') : $post->get('email'), 
  811.         'destinataire_' => "agent en charge du support aux usagers", 'objet_' => 'Nouveau message sur le site du Département du Nord - ' . $thematique . ' / ' . "ND" . $date->format('dmYHis'), 
  812.         'thematique' => $thematique, 'message_' => $message, 
  813.         'email' => $post->get('email'), 'piece_jointe_' => ($fileName != null) ? $fileName : "Aucune pièce jointe", 
  814.         'date' => "ND" . $date->format('dmYHis'), 'ville' => ($post->get('ville') !== null)?$post->get('ville'):null , 
  815.         'adresse' => ($post->get('adresse') !== null)?$post->get('adresse'):null,
  816.         'nom' => ($post->get('nom') !== null)?$post->get('nom'):null,
  817.         'prenom' => ($post->get('prenom') !== null)?$post->get('prenom'):null
  818.         
  819.         ]
  820.       );
  821.       $nom_dest = 'rédaction du Nord info';
  822.       if ($post->get('dest_nom') != null) {
  823.         $nom_dest = $post->get('dest_nom');
  824.       }
  825.       if ($post->get('thematique') === null) {
  826.         $thematique = 'Message à un(e) élu(e)';
  827.       }
  828.       $content_exp = $this->renderView(
  829.         'Lenord/Mails/exp_signalement2.html.twig',
  830.         ['site' => 'lenord', 'destinataire_' => $nom_dest, 'objet_' => 'Votre message sur le site du département du Nord - ' . $thematique . ' / ' . "ND" . $date->format('dmYHis'), 'email' => $post->get('email'), 'thematique' => $thematique, 'message_' => $message, 'piece_jointe_' => ($fileName != null) ? $fileName : "Aucune pièce jointe", 'date' => "ND" . $date->format('dmYHis')]
  831.       );
  832.       //envoi mail
  833.       //Newsletter
  834.       if ($post->get('newsletter') != null || $post->get('newsletter') === "") {
  835.         $ins = $this->em->getRepository(InscritNewsletter::class)->findOneBy(['email' => $post->get('email')]);
  836.         if ($ins == null) {
  837.           $ins = new InscritNewsletter;
  838.           $ins->setEmail($post->get('email'))
  839.             ->setPrenom($post->get('prenom'))
  840.             ->setNom($post->get('nom'))
  841.             ->setDate(new DateTime());
  842.           $this->em->persist($ins);
  843.           $this->em->flush();
  844.         }
  845.       }
  846.       try {
  847.         $this->sendgrid_service->send($destinataires_sendgrid, $content, 'Ce message vient de vous être envoyé sur le site du Département du Nord par ' . $post->get('email') . ' - ' . $thematique . ' / ' . "ND" . $date->format('dmYHis'), ['automate.nordinfo@lenord.fr'], $file);
  848.         $this->sendgrid_service->send([$post->get('email')], $content_exp, 'Votre message sur le site du département du Nord - ' . $thematique . ' / ' . "ND" . $date->format('dmYHis'), ['automate.nordinfo@lenord.fr'], $file);
  849.       } catch (\Exception $e) {
  850.         $this->params['message'] = 'Email erreur';
  851.         return $this->render('Lenord/Main/endformerror.html.twig', $this->params);
  852.       }
  853.     } else {
  854.       $this->params['message'] = 'Captcha erreur';
  855.       return $this->render('Lenord/Main/endformerror.html.twig', $this->params);
  856.     }
  857.     return $this->render('Lenord/Main/endform.html.twig', $this->params);
  858.   }
  859.   #[Route(path: '/infolettre', name: 'lenord_infolettre')]
  860.   public function infolettre(Request $request): Response
  861.   {
  862.     $this->params['referer'] = $request->headers->get('referer');
  863.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Infolettre']];
  864.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  865.     //epingle
  866.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  867.     return $this->render('Lenord/Main/infolettre.html.twig', $this->params);
  868.   }
  869.   #[Route(path: '/recherche', name: 'lenord_recherche')]
  870.   public function lenord_recherche(Request $request): Response
  871.   {
  872.     $this->params['results'] = null;
  873.     $this->params['title'] = 'Recherche "' . $request->query->get('search') . '"';
  874.     $this->params['meta_description'] = "Rechercher les contenus du Département du Nord : informations, actualités, services, documents...";
  875.     $this->params['checkservices'] = null;
  876.     $this->params['checkactualites'] = null;
  877.     $this->params['checkevenements'] = null;
  878.     $this->params['checkdocuments'] = null;
  879.     if ($request->query->get('checkservices') == "on") {
  880.       $this->params['checkservices'] = 'on';
  881.     } else {
  882.       $this->params['checkservices'] = 'off';
  883.     }
  884.     if ($request->query->get('checkactualites') == "on") {
  885.       $this->params['checkactualites'] = 'on';
  886.     } else {
  887.       $this->params['checkactualites'] = 'off';
  888.     }
  889.     if ($request->query->get('checkevenements') == "on") {
  890.       $this->params['checkevenements'] = 'on';
  891.     } else {
  892.       $this->params['checkevenements'] = 'off';
  893.     }
  894.     if ($request->query->get('checkdocuments') == "on") {
  895.       $this->params['checkdocuments'] = 'on';
  896.     } else {
  897.       $this->params['checkdocuments'] = 'off';
  898.     }
  899.     if ($request->query->get('search') != null) {
  900.       $search_fields = ['combined'];
  901.       $entity_type = 'all';
  902.       //checkservices, checkactualites, checkevenements, checkdocuments
  903.       if (
  904.         $request->query->get('checkservices') == "on" && $request->query->get('checkactualites') == "on"
  905.         && $request->query->get('checkevenements') == "on" && $request->query->get('checkdocuments') == "on"
  906.       ) {
  907.         $entity_type = 'all';
  908.       } else {
  909.         $entity_type = [];
  910.         if ($request->query->get('checkservices') == "on") {
  911.           $this->params['checkservices'] = 'on';
  912.           array_push($entity_type, 'service');
  913.         }
  914.         if ($request->query->get('checkactualites') == "on") {
  915.           $this->params['checkactualites'] = 'on';
  916.           array_push($entity_type, 'actualites');
  917.         }
  918.         if ($request->query->get('checkevenements') == "on") {
  919.           $this->params['checkevenements'] = 'on';
  920.           array_push($entity_type, 'evenements');
  921.         }
  922.         if ($request->query->get('checkdocuments') == "on") {
  923.           $this->params['checkdocuments'] = 'on';
  924.           array_push($entity_type, 'document');
  925.         }
  926.         //array_push($entity_type, 'glossaire');
  927.         array_push($entity_type, 'elu');
  928.         array_push($entity_type, 'pages');
  929.         array_push($entity_type, 'politique');
  930.         array_push($entity_type, 'commune');
  931.       }
  932.       $results = $this->es_service->searchDocuments('lenord', $search_fields, $request->query->get('search'), $entity_type, [], [], 50);
  933.       $this->params['results'] = $results;
  934.       //Save log
  935.       $logEs = new LogEs;
  936.       $logEs->setRecherche($request->query->get('search'))
  937.         ->setDate(new DateTime())
  938.         ->setSite("lenord");
  939.       $this->em->persist($logEs);
  940.       $this->em->flush();
  941.     }
  942.     $this->params['search'] = $request->query->get('search');
  943.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  944.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  945.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Recherche']];
  946.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  947.     $this->params['referer'] = $request->headers->get('referer');
  948.     return $this->render('Lenord/Main/search.html.twig', $this->params);
  949.   }
  950.   #[Route(path: '/404', name: 'error404')]
  951.   public function error404(): Response
  952.   {
  953.     $this->params['title'] = "Erreur";
  954.     return $this->render('Lenord/Main/erreur.html.twig', $this->params);
  955.   }
  956.   #[Route(path: '/cartographie', name: 'cartographie')]
  957.   public function cartographie(Request $request): Response
  958.   {
  959.     $this->params['title'] = "Cartographie";
  960.     $this->params['meta_description'] = "Localiser les établissements du Département du Nord";
  961.     $page_number = $request->query->getInt('page', 1);
  962.     $this->params['pois'] = $this->wemap_service->getAllPois(10, $page_number)->results;
  963.     if ($this->params['pois'] == false) {
  964.       return $this->pagelegales($request, 'error-404');
  965.     }
  966.     /*$this->params['pagination'] = $this->paginator->paginate(
  967.       $this->params['pois'],
  968.       $page_number,
  969.       10
  970.     );
  971.     $this->params['total'] = count($this->params['pois']);*/
  972.     $categories = $this->wemap_service->getCategories();
  973.     $categories = $categories->snippet->usetags->tags;
  974.     $array_territoires = [];
  975.     $array_etablissements = [];
  976.     $array_thematiques = [];
  977.     $array_besoins = [];
  978.     //dd($categories);
  979.     $i = 0;
  980.     $search  = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ');
  981.     $replace = array('A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y');
  982.     foreach ($categories as $category) {
  983.       if (property_exists($category, "category")) {
  984.         if ($category->category == "type-detablissement") {
  985.           array_push($array_etablissements, ['sort' => str_replace($search, $replace, $category->name), 'name' => $category->name, 'slug' => $category->slug]);
  986.         } else if ($category->name == "Tous types") {
  987.           array_push($array_thematiques, ['sort' => str_replace($search, $replace, $category->name), 'name' => $category->category, 'slug' => $category->category]);
  988.         } else if ($category->category == "territoire") {
  989.           array_push($array_territoires, ['sort' => str_replace($search, $replace, $category->name), 'name' => $category->name, 'slug' => $category->slug]);
  990.         } else {
  991.           array_push($array_besoins, ['sort' => str_replace($search, $replace, $category->name), 'name' => $category->name, 'slug' => $category->slug, 'parent' => $category->category]);
  992.         }
  993.       } else if ($i >= 56 && $i <= 62) {
  994.         //array_push($array_territoires, ['sort'=> str_replace($search, $replace, $category->name), 'name' => $category->name, 'slug' => $category->slug]);
  995.       }
  996.       $i++;
  997.     }
  998.     /*// you can use array_column() instead of the above code
  999.     $volume  = array_column($data, 'volume');
  1000.     $edition = array_column($data, 'edition');
  1001.     // Sort the data with volume descending, edition ascending
  1002.     // Add $data as the last parameter, to sort by the common key
  1003.     array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
  1004.     */
  1005.     $territories_column = array_column($array_territoires, 'sort');
  1006.     $etablissements_column = array_column($array_etablissements, 'sort');
  1007.     $thematiques_column = array_column($array_thematiques, 'sort');
  1008.     $besoins_column = array_column($array_besoins, 'sort');
  1009.     array_multisort($territories_column, SORT_ASC | SORT_LOCALE_STRING, $array_territoires);
  1010.     array_multisort($etablissements_column, SORT_ASC | SORT_LOCALE_STRING, $array_etablissements);
  1011.     array_multisort($thematiques_column, SORT_ASC | SORT_LOCALE_STRING, $array_thematiques);
  1012.     array_multisort($besoins_column, SORT_ASC | SORT_LOCALE_STRING, $array_besoins);
  1013.     $this->params['array_territoires'] = $array_territoires;
  1014.     $this->params['array_etablissements'] = $array_etablissements;
  1015.     $this->params['array_thematiques'] = $array_thematiques;
  1016.     $this->params['array_besoins'] = $array_besoins;
  1017.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  1018.     //Epingle
  1019.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  1020.     $epingles_ = $this->epingle_service->getEpinglesSection('cartographie');
  1021.     foreach ($epingles_ as $epingle) {
  1022.       array_push($this->params['epingles'], $epingle);
  1023.     }
  1024.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => 'Cartographie']];
  1025.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  1026.     $this->params['referer'] = $request->headers->get('referer');
  1027.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  1028.     return $this->render('Lenord/Main/cartographie.html.twig', $this->params);
  1029.   }
  1030.   #[Route(path: '/cartographie-simplifiee', name: 'cartographie_simplifie')]
  1031.   public function cartographie_simplifie(Request $request): Response
  1032.   {
  1033.     $page_number = $request->query->getInt('page', 1);
  1034.     $this->params['pois'] = $this->wemap_service->getAllPois(10, $page_number)->results;
  1035.     $this->params['total'] = $this->wemap_service->getAllPois(10, $page_number)->count;
  1036.     $this->params['categories'] = $this->wemap_service->getCategories();
  1037.     $this->params['categories'] = $this->params['categories']->snippet->usetags->tags;
  1038.     $this->params['previous'] = null;
  1039.     if ($page_number > 1) {
  1040.       $this->params['previous'] = $page_number - 1;
  1041.     }
  1042.     $this->params['current_page'] = $page_number;
  1043.     $this->params['totalPage'] = null;
  1044.     $quotient = intdiv($this->params['total'], 10);
  1045.     $reste = $this->params['total'] % 10;
  1046.     if ($reste > 0) {
  1047.       $quotient++;
  1048.     }
  1049.     $this->params['totalPage'] = $quotient;
  1050.     $this->params['next'] = null;
  1051.     if ($page_number !== $quotient) {
  1052.       $this->params['next'] = $page_number + 1;
  1053.     }
  1054.     //Current page + 5 et - 5 ?
  1055.     $this->params['pagesInRange'] = [];
  1056.     $range_max = $page_number + 5;
  1057.     $range_min = $page_number - 5;
  1058.     for ($i = $range_min; $i <= $range_max; $i++) {
  1059.       if ($i > 0 && $i < $this->params['totalPage']) {
  1060.         array_push($this->params['pagesInRange'], $i);
  1061.       }
  1062.     }
  1063.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(true);
  1064.     return $this->render('Lenord/Main/cartographie_simplifie.html.twig', $this->params);
  1065.   }
  1066.   #[Route(path: '/l-institution/les-conseillers-departementaux/recherche', name: 'lenord_search_contact')]
  1067.   public function search_contacts(Request $request): Response
  1068.   {
  1069.     return $this->lenord_pagecmsges($request, 'les-conseillers-departementaux');
  1070.   }
  1071.   #[Route(path: '/l-institution/les-conseillers-departementaux/{slug}', name: 'elus_lenord_detail')]
  1072.   public function detail_elu(Request $request, string $slug): Response
  1073.   {
  1074.     $contact = $this->em->getRepository(Contact::class)->getContact_($slug);
  1075.     $this->params['contact'] = $contact;
  1076.     $posts = [];
  1077.     $count_post = 0;
  1078.     foreach ($contact->getPosts1() as $pp) {
  1079.       if ($count_post >= 3) {
  1080.         break;
  1081.       }
  1082.       array_push($posts, $pp);
  1083.       $count_post++;
  1084.     }
  1085.     if ($count_post < 3) {
  1086.       foreach ($contact->getPosts2() as $pp) {
  1087.         if ($count_post >= 3) {
  1088.           break;
  1089.         }
  1090.         array_push($posts, $pp);
  1091.         $count_post++;
  1092.       }
  1093.     }
  1094.     if ($count_post < 3) {
  1095.       foreach ($contact->getPosts3() as $pp) {
  1096.         if ($count_post >= 3) {
  1097.           break;
  1098.         }
  1099.         array_push($posts, $pp);
  1100.         $count_post++;
  1101.       }
  1102.     }
  1103.     $this->params['title'] = $contact->getFirstName() . ' ' . $contact->getLastName() . " - Elu";
  1104.     $this->params['meta_description'] = "Elus";
  1105.     $this->params['breadcrumb'] = [
  1106.       ['alias' => '/', 'titre' => 'Accueil'],
  1107.       ['alias' => '/l-institution', 'titre' => 'L\'institution'],
  1108.       ['alias' => '/l-institution/les-conseillers-departementaux', 'titre' => 'Les conseillers départementaux'],
  1109.       ['alias' => '', 'titre' => $contact->getFirstName() . ' ' . $contact->getLastName()]
  1110.     ];
  1111.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  1112.     $this->params['contact_posts'] = $posts;
  1113.     $this->params['referer'] = $request->headers->get('referer');
  1114.     $this->params['caps'] = $this->getCaptcha();
  1115.     //epingle
  1116.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  1117.     if ($request->get('function') == 'download_pdf') {
  1118.       $this->params['is_pdf'] = 1;
  1119.       $pdfOptions = new Options();
  1120.       $pdfOptions->set('defaultFont', 'Arial');
  1121.       $pdfOptions->setIsRemoteEnabled(true);
  1122.       $dompdf = new Dompdf($pdfOptions);
  1123.       $html = $this->renderView('Lenord/Main/elu.html.twig', $this->params);
  1124.       $dompdf->loadHtml($html);
  1125.       $dompdf->setPaper('A4', 'portrait');
  1126.       $dompdf->render();
  1127.       $output = $dompdf->output();
  1128.       $filename = sprintf('nord-info-%s.pdf', $contact->getFirstName());
  1129.       return new Response(
  1130.         $output,
  1131.         200,
  1132.         [
  1133.           'Content-Type' => 'application/pdf',
  1134.           'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  1135.         ]
  1136.       );
  1137.     } else {
  1138.       return $this->render('Lenord/Main/elu.html.twig', $this->params);
  1139.     }
  1140.   }
  1141.   #[Route(path: '/l-institution/{slug}', name: 'lenord_pagecms')]
  1142.   public function lenord_pagecmsges(Request $request, string $slug): Response
  1143.   {
  1144.     $result = [];
  1145.     $pageEntity = $this->em->getRepository(Pages::class)->findOneBy(['alias_url' => $slug, 'actif' => 1, 'lenord' => 1]);
  1146.     if ($pageEntity) {
  1147.       $this->params['page'] = $pageEntity;
  1148.       $this->params['meta_description'] = $this->params['page']->getMetaDescription();
  1149.       $this->params['title'] = $this->params['page']->getTitre() . " - L'institution";
  1150.       if ($this->params['page']->getId() === 9) {
  1151.         $this->params['title'] = $this->params['page']->getTitre();
  1152.       }
  1153.       $content_post = null;
  1154.       if ($this->params['page']->getContent() !== null) {
  1155.         $content_post = $this->feedUtilities->jsonToHtml($this->params['page']->getContent(), $request, $this->params['title']);
  1156.       }
  1157.       $this->params['content_post'] = $content_post;
  1158.       $this->params['nordinfo_rss'] = [];
  1159.       if ($this->params['page']->getNordinfoRss() !== null) {
  1160.         $this->params['nordinfo_rss'] = $this->rss_service->getArrayArticle($this->params['page']->getNordinfoRss());
  1161.         $this->params['nordinfo_rss_description'] = $this->params['page']->getNordinfoRss()->getDescription();
  1162.       } else {
  1163.         $this->params['nordinfo_rss_description'] = null;
  1164.       }
  1165.       $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  1166.       foreach ($this->params['page']->getEpingles() as $e) {
  1167.         if ($e->getActive() === true) {
  1168.           $this->params['epingles'][] = $e;
  1169.         }
  1170.       }
  1171.       $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '/l-institution', 'titre' => 'L\'institution'], ['alias' => '', 'titre' => $this->params['page']->getTitre()]];
  1172.       $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  1173.       $this->params['openGraph'] = ["title" => $this->params['page']->getTitre(), "url" => "https://lenord.fr/" . $slug, "image" => "https://lenord.fr/img/brandmaster/logo-le-nord.svg", "type" => "website", "description" => $this->params['content_post']];
  1174.       $this->params['referer'] = $request->headers->get('referer');
  1175.       $this->params['is_page_institution'] = true;
  1176.       $this->params['isElus'] = false;
  1177.       if ($slug === 'les-conseillers-departementaux') {
  1178.         //lister les elus
  1179.         $this->params['isElus'] = true;
  1180.         $this->params['cantons'] = $this->em->getRepository(Cantons::class)->findBy([], ['canton' => 'ASC']);
  1181.         $search = null;
  1182.         $search_id = null;
  1183.         $filter_title = null;
  1184.         $this->params['is_search'] = 0;
  1185.         if ($request->request->get('function') === 'ajax_search_contacts') {
  1186.           if ($request->request->get('canton_id') !== null) {
  1187.             $search = null;
  1188.             $search_id = $request->request->get('canton_id');
  1189.             $this->params['is_search'] = 1;
  1190.             $canton = $this->em->getRepository(Cantons::class)->find($request->request->get('canton_id'));
  1191.             $filter_title = ' résultats pour "' . $canton?->getCanton() . '"';
  1192.           } else if ($request->request->get('search') !== "") {
  1193.             $search = $request->request->get('search');
  1194.             $search_id = null;
  1195.             $this->params['is_search'] = 1;
  1196.             $filter_title = ' résultats pour "' . $search . '"';
  1197.           }
  1198.         } else {
  1199.           if ($request->query->get('canton_id') !== null) {
  1200.             $search = null;
  1201.             $search_id = $request->query->get('canton_id');
  1202.             $this->params['is_search'] = 1;
  1203.             $canton = $this->em->getRepository(Cantons::class)->find($request->query->get('canton_id'));
  1204.             $filter_title = ' résultats pour "' . $canton?->getCanton() . '"';
  1205.           } else if ($request->query->get('search') != "") {
  1206.             $search = $request->query->get("search");
  1207.             $search_id = null;
  1208.             $this->params['is_search'] = 1;
  1209.             $filter_title = ' résultats pour "' . $search . '"';
  1210.           }
  1211.         }
  1212.         if ($request->request->get('function') === 'ajax_search_contacts_reset') {
  1213.           $search = null;
  1214.           $search_id = null;
  1215.         }
  1216.         $this->params['contacts'] = $this->em->getRepository(Contact::class)->getContacts_(1, $search, $search_id);
  1217.         $this->params['filter_title'] = ($filter_title !== null) ? (is_countable($this->params['contacts']) ? count($this->params['contacts']) : 0) . $filter_title : null;
  1218.         if ($request->request->get('function') === 'ajax_search_contacts' || $request->request->get('function') === 'ajax_search_contacts_reset') {
  1219.           $result['html'] = $this->render('/Nordinfo/Main/ajax/contacts_list.html.twig', $this->params)->getContent();
  1220.           $result['filter_title'] = $this->params['filter_title'];
  1221.           return new JsonResponse($result);
  1222.         }
  1223.       }
  1224.       if ($request->get('function') === 'download_pdf') {
  1225.         $this->params['is_pdf'] = 1;
  1226.         $pdfOptions = new Options();
  1227.         $pdfOptions->set('defaultFont', 'Arial');
  1228.         $pdfOptions->setIsRemoteEnabled(true);
  1229.         $dompdf = new Dompdf($pdfOptions);
  1230.         $html = $this->renderView('Lenord/Main/page.html.twig', $this->params);
  1231.         $dompdf->loadHtml($html);
  1232.         $dompdf->setPaper('A4', 'portrait');
  1233.         $dompdf->render();
  1234.         $output = $dompdf->output();
  1235.         $filename = sprintf('le-nord-%s.pdf', $this->params['title']);
  1236.         return new Response(
  1237.           $output,
  1238.           200,
  1239.           [
  1240.             'Content-Type' => 'application/pdf',
  1241.             'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  1242.           ]
  1243.         );
  1244.       }
  1245.       return $this->render('Lenord/Main/page.html.twig', $this->params);
  1246.     }
  1247.     throw $this->createNotFoundException('La page demandée n\'existe pas.');
  1248.   }
  1249.   #[Route(path: '/{slug}', name: 'lenord_page_legale')]
  1250.   public function pagesatellite(Request $request, string $slug): Response
  1251.   {
  1252.     $this->params['slug'] = $slug;
  1253.     $this->params['referer'] = $request->headers->get('referer');
  1254.     $this->params['politique'] = $this->em->getRepository(PageSatellite::class)->findOneBy(['alias_url' => $slug]);
  1255.     if ($this->params['politique'] == null) {
  1256.       return $this->pagelegales($request, $slug);
  1257.     }
  1258.     $this->params['title'] = $this->params['politique']->getTitre();
  1259.     $this->params['meta_description'] = $this->params['politique']->getChapo();
  1260.     $this->params['content_post'] = $this->feedUtilities->jsonToHtml($this->params['politique']->getContent(), $request, $this->params['title']);
  1261.     $this->params['nordinfo_rss'] = null;
  1262.     $this->params['nordinfo_rss_description'] = null;
  1263.     if ($this->params['politique']->getNordinfoRss() != null) {
  1264.       $this->params['nordinfo_rss'] = $this->rss_service->getArrayArticle($this->params['politique']->getNordinfoRss());
  1265.       $this->params['nordinfo_rss_description'] = $this->params['politique']->getNordinfoRss()->getDescription();
  1266.     }
  1267.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  1268.     /*$epingles_politiques = $this->epingle_service->getEpinglesSection('politique');
  1269.     foreach ($epingles_politiques as $epingle) {
  1270.       array_push($this->params['epingles'], $epingle);
  1271.     }*/
  1272.     foreach ($this->params['politique']->getEpingles() as $e) {
  1273.       if ($e->getActive() == true) {
  1274.         array_push($this->params['epingles'], $e);
  1275.       }
  1276.     }
  1277.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => $this->params['politique']->getTitre()]];
  1278.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  1279.     $this->params['openGraph'] = ["title" => $this->params['politique']->getTitre(), "url" => "https://lenord.fr/" . $slug, "image" => "https://lenord.fr/img/brandmaster/logo-le-nord.svg", "type" => "website", "description" => $this->params['content_post']];
  1280.     $this->params['referer'] = $request->headers->get('referer');
  1281.     $this->params['is_page_politique'] = false;
  1282.     if ($request->get('function') == 'download_pdf') {
  1283.       $this->params['is_pdf'] = 1;
  1284.       $pdfOptions = new Options();
  1285.       $pdfOptions->set('defaultFont', 'Arial');
  1286.       $pdfOptions->setIsRemoteEnabled(true);
  1287.       $dompdf = new Dompdf($pdfOptions);
  1288.       $html = $this->renderView('Lenord/Main/politique.html.twig', $this->params);
  1289.       $dompdf->loadHtml($html);
  1290.       $dompdf->setPaper('A4', 'portrait');
  1291.       $dompdf->render();
  1292.       $output = $dompdf->output();
  1293.       $filename = sprintf('le-nord-%s.pdf', $this->params['title']);
  1294.       return new Response(
  1295.         $output,
  1296.         200,
  1297.         [
  1298.           'Content-Type' => 'application/pdf',
  1299.           'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  1300.         ]
  1301.       );
  1302.     } else {
  1303.       return $this->render('Lenord/Main/politique.html.twig', $this->params);
  1304.     }
  1305.   }
  1306.   public function pagelegales(Request $request, string $slug): Response
  1307.   {
  1308.     $this->params['referer'] = $request->headers->get('referer');
  1309.     $post = $this->em->getRepository(PagesLegales::class)->findOneBy(['slug' => $slug, 'actif' => 1]);
  1310.     if (!$post) {
  1311.       throw $this->createNotFoundException('La page demandée n\'existe pas.');
  1312.     }
  1313.     $this->params['post'] = $post;
  1314.     $this->params['meta_description'] = "La page " . $this->params['post']->getTitre() . " du Département du Nord";
  1315.     $this->params['title'] = $this->params['post']->getTitre();
  1316.     $this->params['epingles'] = $this->epingle_service->getEpingles('lenord');
  1317.     $epingles_ = $this->epingle_service->getEpinglesSection('legales_lenord');
  1318.     foreach ($epingles_ as $epingle) {
  1319.       array_push($this->params['epingles'], $epingle);
  1320.     }
  1321.     $this->params['breadcrumb'] = [['alias' => '/', 'titre' => 'Accueil'], ['alias' => '', 'titre' => $this->params['title']]];
  1322.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES | JSON_HEX_APOS);
  1323.     if ($request->get('function') === 'download_pdf') {
  1324.       $this->params['is_pdf'] = 1;
  1325.       $pdfOptions = new Options();
  1326.       $pdfOptions->set('defaultFont', 'Arial');
  1327.       $pdfOptions->setIsRemoteEnabled(true);
  1328.       $dompdf = new Dompdf($pdfOptions);
  1329.       $html = $this->renderView('Lenord/Main/detail_page_legale.html.twig', $this->params);
  1330.       $dompdf->loadHtml($html);
  1331.       $dompdf->setPaper('A4', 'portrait');
  1332.       $dompdf->render();
  1333.       $output = $dompdf->output();
  1334.       $filename = sprintf('le-nord-%s.pdf', $this->params['post']->getTitre());
  1335.       return new Response(
  1336.         $output,
  1337.         200,
  1338.         [
  1339.           'Content-Type' => 'application/pdf',
  1340.           'Content-Disposition' => sprintf('attachment; filename="%s"', "$filename"),
  1341.         ]
  1342.       );
  1343.     } else {
  1344.       return $this->render('Lenord/Main/detail_page_legale.html.twig', $this->params);
  1345.     }
  1346.   }
  1347.   #[Route(path: '/ajax/getServicesAll', name: 'services_ajax_getServicesAllLenNord')]
  1348.   public function getServicesAll(Request $request): Response
  1349.   {
  1350.     $services = $this->em->getRepository(Service::class)->getServicesByGrandprofil($request->request->get('alias'));
  1351.     return new JsonResponse(['datas' => $services]);
  1352.   }
  1353.   private function getCaptcha(): mixed
  1354.   {
  1355.     $captchaCh = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  1356.     $captchaLe = ["zéro", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix"];
  1357.     $testcap = array_merge($captchaCh, $captchaLe);
  1358.     $rnd = array_rand($testcap, 2);
  1359.     $i1 = $rnd[0];
  1360.     if ($rnd[0] >= 11) {
  1361.       $i1 = $rnd[0] - 11;
  1362.     }
  1363.     $i2 = $rnd[1];
  1364.     if ($rnd[1] >= 11) {
  1365.       $i2 = $rnd[1] - 11;
  1366.     }
  1367.     $capp = ["valeur1" => ["libelle" => $testcap[$rnd[0]], "valeur" => $captchaCh[$i1]], "valeur2" => ["libelle" => $testcap[$rnd[1]], "valeur" => $captchaCh[$i2]]];
  1368.     return $capp;
  1369.   }
  1370. }