src/Controller/Nordinfo/MainController.php line 2631

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Nordinfo;
  3. use App\Entity\Cantons;
  4. use App\Entity\Commune;
  5. use App\Entity\Contact;
  6. use App\Entity\ContactRequest;
  7. use App\Entity\CustomForm;
  8. use App\Entity\EventType;
  9. use App\Entity\FileImport;
  10. use App\Entity\Footer;
  11. use App\Entity\FooterSites;
  12. use App\Entity\FormulaireThematique;
  13. use App\Entity\Glossaire;
  14. use App\Entity\Service;
  15. use DateTime;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use App\Entity\Pages;
  18. use App\Entity\Post;
  19. use Exception;
  20. use PhpOffice\PhpSpreadsheet\IOFactory;
  21. use SendGrid\Mail\TypeException;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. use Symfony\Component\HttpFoundation\RedirectResponse;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\JsonResponse;
  26. use Doctrine\ORM\EntityManagerInterface;
  27. use App\Entity\Organization;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use App\Entity\PostCommentaires;
  30. use App\Entity\Ics;
  31. use App\Entity\InscritNewsletter;
  32. use App\Entity\Lieu;
  33. use App\Entity\LogEs;
  34. use App\Entity\MailElu;
  35. use App\Entity\MenuLibelle;
  36. use App\Entity\PagesLegales;
  37. use App\Entity\PostReponses;
  38. use App\Entity\PostType;
  39. use App\Entity\RssArticle;
  40. use App\Entity\RssEvent;
  41. use App\Entity\Statut;
  42. use App\Entity\Tags;
  43. use App\Entity\TargetPublic;
  44. use App\Entity\Territory;
  45. use App\Entity\Topic;
  46. use App\Entity\TypeOrganisation;
  47. use App\Entity\TypeSupport;
  48. use App\Utilities\Feed;
  49. use Dompdf\Dompdf;
  50. use Dompdf\Options;
  51. use App\Entity\User;
  52. use App\Service\AgendaService;
  53. use App\Service\ElasticsearchService;
  54. use App\Service\EpingleService;
  55. use App\Service\MailService;
  56. use App\Service\SchemaService;
  57. use App\Service\RssService;
  58. use App\Service\SendgridMailService;
  59. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  60. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  61. use Symfony\Component\Routing\Annotation\Route;
  62. use Symfony\Component\Routing\RouterInterface;
  63. use App\Utilities\NewFeed;
  64. /**
  65.  * @method User getUser()
  66.  */
  67. #[Route(host"nordinfo.spontaneit.fr")]
  68. //#[Route(host: "info.lenord.fr")]
  69. class MainController extends AbstractController
  70. {
  71.   protected mixed $params = [];
  72.   protected mixed $arr_intranet = ['admin''superadmin''redacteur''agent'];
  73.   public function __construct(
  74.     protected EntityManagerInterface    $em,
  75.     private UserPasswordHasherInterface $hasher,
  76.     private Feed $feedUtilities,
  77.     private MailService $mail_service,
  78.     private SchemaService $schema_service,
  79.     private RssService $rss_service,
  80.     private EpingleService $epingle_service,
  81.     private SendgridMailService $sendgrid_service,
  82.     private AgendaService $agenda_service,
  83.     private ElasticsearchService $es_service,
  84.     private RouterInterface $router,
  85.     private NewFeed $new_feed_utilities,
  86.   ) {
  87.     $this->params['admin'] = false;
  88.     $this->params['actus'] = false;
  89.     $this->params['breadcrumb'] = [];
  90.     $this->params['is_pdf'] = 0;
  91.     $this->params['is_preview'] = 0;
  92.     $this->params['meta_desc'] = "Retrouvez toute l'actualité du Département du Nord sur Nord info - Reportages, initiatives locales, agenda culturel, dossiers thématiques, vidéos, réseaux sociaux,... Nord info, le Département est là !";
  93.     $this->params['items_offset'] = 50;
  94.     $this->params['initial_limit'] = 50;
  95.     $this->params['total_limit'] = 300;
  96.     $this->getMenusTop();
  97.     $this->getMenusProfile();
  98.     $this->params['epingles'] = [];
  99.     $this->params['footer'] = $this->em->getRepository(Footer::class)->find(1);
  100.   }
  101.   #[Route(path'/'name'index')]
  102.   public function index(): RedirectResponse
  103.   {
  104.     return $this->redirect($this->generateUrl('info'));
  105.   }
  106.   #[Route(path'/glossaire'name'nordinfo_glossaire')]
  107.   public function glossaire(Request $request): response
  108.   {
  109.     $this->params['title'] = "Glossaire";
  110.     $this->params['meta_description'] = "Le glossaire du site du Département du Nord : acronymes et définitions utiles";
  111.     $glossaire $this->em->getRepository(Glossaire::class)->findBy([], ['terme' => 'ASC']);
  112.     $this->params['glossaires'] = $glossaire;
  113.     $this->params['letters'] = $this->em->getRepository(Glossaire::class)->getFirstLetters();
  114.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => 'Glossaire']];
  115.     //$this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES|JSON_HEX_APOS);
  116.     $this->params['referer'] = $request->headers->get('referer');
  117.     return $this->render('Nordinfo/Main/glossaire.html.twig'$this->params);
  118.   }
  119.   #[Route(path'/le-departement'name'departement')]
  120.   public function departement(Request $request): Response
  121.   {
  122.     $this->params['env'] = getenv('APP_ENV');
  123.     $this->params['referer'] = $request->headers->get('referer');
  124.     $this->params['title'] = "Comprendre le département";
  125.     $this->params['posts'] = $this->em->getRepository(Pages::class)->getPages(1);
  126.     $this->params['type_organisations'] = $this->em->getRepository(TypeOrganisation::class)->findAll();
  127.     //epingle
  128.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  129.     $epingles_ $this->epingle_service->getEpinglesSection('ledepartement');
  130.     foreach ($epingles_ as $epingle) {
  131.       array_push($this->params['epingles'], $epingle);
  132.     }
  133.     return $this->render('Nordinfo/Main/comprendredepartement.html.twig'$this->params);
  134.   }
  135.   #[Route(path'/api/post_get_content/{id}'name'api_get_content')]
  136.   public function post_get_content(Request $requestint $id): Response
  137.   {
  138.     $post $this->em->getRepository(Post::class)->find($id);
  139.     $content null;
  140.     if ($post->getContent() != null) {
  141.       $content $this->feedUtilities->jsonToHtml($post->getContent(), $request);
  142.     }
  143.     return new JsonResponse(['content' => $content]);
  144.   }
  145.   #[Route(path'/wemap_test'name'wemap_test')]
  146.   public function wemap_test(): Response
  147.   {
  148.     //$this->params['pois'] = $this->wemap_service->getAllPois()->results;
  149.     return $this->render('Nordinfo/Main/demo-post.html.twig'$this->params);
  150.   }
  151.   #[Route(path'/xml/events2evasion.xml'name'get_events_nordevasion')]
  152.   public function get_events_nordevasion(Request $request): Response
  153.   {
  154.     $response = new Response($this->rss_service->getXmlNordevasion($this->router$request->getHost()));
  155.     $response->headers->set('Content-Type''text/xml');
  156.     $response->headers->set('Access-Control-Allow-Origin''*');
  157.     return $response;
  158.   }
  159.   #[Route(path'/rss/{alias}'name'rss_article')]
  160.   public function rssarticle(string $alias): Response
  161.   {
  162.     $rssarticle $this->em->getRepository(RssArticle::class)->findOneBy(['alias' => $alias]);
  163.     $response = new Response($this->rss_service->getXmlArticle($rssarticle));
  164.     $response->headers->set('Content-Type''text/xml');
  165.     $response->headers->set('Access-Control-Allow-Origin''*');
  166.     return $response;
  167.   }
  168.   #[Route(path'/rss-event/{alias}'name'rss_event')]
  169.   public function rssevent(string $alias): Response
  170.   {
  171.     $rssarticle $this->em->getRepository(RssEvent::class)->findOneBy(['alias' => $alias]);
  172.     $response = new Response($this->rss_service->getXmlEvent($rssarticle));
  173.     $response->headers->set('Content-Type''text/xml');
  174.     $response->headers->set('Access-Control-Allow-Origin''*');
  175.     return $response;
  176.   }
  177.   /**
  178.    * @throws \PhpOffice\PhpSpreadsheet\Exception
  179.    * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
  180.    */
  181.   public function import_event(): void
  182.   {
  183.     ini_set('memory_limit''-1');
  184.     ini_set('max_execution_time''3000');
  185.     $path $this->get('kernel')->getRootDir() . '/../';
  186.     $file $path 'RDV-nature-pour-Nord-info.xlsx_5e5e5bb5b9ca6.xlsx';
  187.     $fileType IOFactory::identify($file);
  188.     $l 0;
  189.     $reader IOFactory::createReader($fileType);
  190.     $spreadsheet $reader->load($file);
  191.     $datas $spreadsheet->getSheet(0)->toArray(nulltruetruetrue);
  192.     $type $this->em->getRepository(EventType::class)->find(8);
  193.     $topic $this->em->getRepository(Topic::class)->find(9);
  194.     $status $this->em->getRepository(Statut::class)->find(1);
  195.     $post_type $this->em->getRepository(PostType::class)->find(8);
  196.     $date = new DateTime();
  197.     foreach ($datas as $d) {
  198.       $l++;
  199.       if ($l 1) {
  200.         $territory $this->em->getRepository(Territory::class)->findOneBy(['display_name' => $d['K']]);
  201.         $post = new Post;
  202.         $post
  203.           ->setType($post_type)
  204.           ->setTitle($d['A'])
  205.           ->setSubtitle($d['B'])
  206.           ->setDateDebut($d['C'])
  207.           ->setDateFin($d['D'])
  208.           ->setHoraires($d['E'])
  209.           ->setTarifs($d['F'])
  210.           ->setLieu($d['H'])
  211.           ->addEventType($type)
  212.           ->setVille($d['I'])
  213.           ->addTopic($topic)
  214.           ->setOrganizedBy($d['L'])
  215.           ->setContent($d['M'])
  216.           ->setStatus($status)
  217.           ->setCreatedAt($date->format('d/m/Y'))
  218.           ->setOrganisation4($d['N']);
  219.         if ($territory != null) {
  220.           $post->addTerritory($territory);
  221.         }
  222.         $this->em->persist($post);
  223.       }
  224.     }
  225.     $this->em->flush();
  226.   }
  227.   /*private function xmlToArray(\SimpleXMLElement $xml): mixed
  228.   {
  229.     $parser = function (\SimpleXMLElement $xml, array $collection = []) use (&$parser) {
  230.       $nodes = $xml->children();
  231.       $attributes = $xml->attributes();
  232.       if (0 !== ($attributes === null ? 0 : count($attributes))) {
  233.         foreach ($attributes as $attrName => $attrValue) {
  234.           $collection['attributes'][$attrName] = strval($attrValue);
  235.         }
  236.       }
  237.       if (0 === $nodes->count()) {
  238.         $collection['value'] = strval($xml);
  239.         return $collection;
  240.       }
  241.       foreach ($nodes as $nodeName => $nodeValue) {
  242.         if (($nodeValue->xpath('../' . $nodeName) === null ? 0 : count($nodeValue->xpath('../' . $nodeName))) < 2) {
  243.           $collection[$nodeName] = $parser($nodeValue);
  244.           continue;
  245.         }
  246.         $collection[$nodeName][] = $parser($nodeValue);
  247.       }
  248.       return $collection;
  249.     };
  250.     return [
  251.       $xml->getName() => $parser($xml)
  252.     ];
  253.   }*/
  254.   #[Route(path'/console2020/traitement'name'traitement')]
  255.   public function traitement(Request $request): RedirectResponse
  256.   {
  257.     $get $request->query;
  258.     $myFile $this->em->getRepository(FileImport::class)
  259.       ->find($get->get('id'));
  260.     $path $this->get('kernel')->getRootDir() . "/../public/upload/imports/";
  261.     $inputFileName $path $myFile->getFilename();
  262.     $string file_get_contents($inputFileName);
  263.     if ($string === false) {
  264.       dd('error');
  265.     }
  266.     $json json_decode($stringnull512JSON_THROW_ON_ERROR);
  267.     foreach ($json->posts as $actu) {
  268.       $post = new Post;
  269.       $user_cr $this->em->getRepository(User::class)->find(38);
  270.       $public $this->em->getRepository(TargetPublic::class)->find(4);
  271.       $type $this->em->getRepository(PostType::class)->find(8);
  272.       $status $this->em->getRepository(Statut::class)->find(5);
  273.       $contenu null;
  274.       $description null;
  275.       $content null;
  276.       (property_exists($actu'titre') == true) ? $post->setTitle($actu->titre) : $post->setTitle(null);
  277.       (property_exists($actu'description') == true) ? $description $actu->description $description null;
  278.       (property_exists($actu'contenu') == true) ? $content $actu->contenu $content null;
  279.       (property_exists($actu'illustration') == true) ? $post->setIllustrationdetailName($actu->illustration) : $post->setIllustrationdetailName(null);
  280.       (property_exists($actu'illustration') == true) ? $post->setIllustrationfilName($actu->illustration) : $post->setIllustrationfilName(null);
  281.       $description str_replace('</h2><BR/>''</h2>', (string)$description);
  282.       $description str_replace('<br></br>''<br>'$description);
  283.       $description str_replace('<br /> <br />''<br>'$description);
  284.       $description str_replace('<br></br>''<br>'$description);
  285.       $description str_replace('<BR></BR>''<br>'$description);
  286.       $description str_replace('<b><b>''<b>'$description);
  287.       $description str_replace('</b> </b>''</b>'$description);
  288.       $description str_replace('<strong>''<b>'$description);
  289.       $description str_replace('</strong>''</b>'$description);
  290.       $description str_replace('<div class="wysiwyg wysiwyg">'' '$description);
  291.       $description str_replace('<div class="wysiwyg classic">'' '$description);
  292.       $description str_replace('<div>'' '$description);
  293.       $description str_replace('</div>'' '$description);
  294.       $description str_replace('style="text-align: center "'' '$description);
  295.       $description str_replace('style="text-decoration: underline "'' '$description);
  296.       $description str_replace('style="border: 1px solid black "'' '$description);
  297.       $description str_replace('id="paragraphe0" class="titreContenu"'' '$description);
  298.       $description str_replace('style="color: #000000 "'' '$description);
  299.       $description str_replace('<p> </p>'' '$description);
  300.       $description str_replace('id="document" class="document"'' '$description);
  301.       $description str_replace('color: #xxxxxx'' '$description);
  302.       $description str_replace('<strong> </strong>'' '$description);
  303.       $description str_replace('class="font-weight-bold"'' '$description);
  304.       $description str_replace('<p style="text-align: center "> </p>'' '$description);
  305.       $description str_replace('<h2></h2>'' '$description);
  306.       $description str_replace('<em></em>'' '$description);
  307.       $description str_replace('<img></img>'' '$description);
  308.       $description str_replace('<span></span>'' '$description);
  309.       $content str_replace('</h2><BR/>''</h2>', (string)$content);
  310.       $content str_replace('<br></br>''<br>'$content);
  311.       $content str_replace('<br /> <br />''<br>'$content);
  312.       $content str_replace('<br></br>''<br>'$content);
  313.       $content str_replace('<BR></BR>''<br>'$content);
  314.       $content str_replace('<b><b>''<b>'$content);
  315.       $content str_replace('</b> </b>''</b>'$content);
  316.       $content str_replace('<strong>''<b>'$content);
  317.       $content str_replace('</strong>''</b>'$content);
  318.       $content str_replace('<div class="wysiwyg wysiwyg">'' '$content);
  319.       $content str_replace('<div class="wysiwyg classic">'' '$content);
  320.       $content str_replace('<div>'' '$content);
  321.       $content str_replace('</div>'' '$content);
  322.       $content str_replace('style="text-align: center "'' '$content);
  323.       $content str_replace('style="text-decoration: underline "'' '$content);
  324.       $content str_replace('style="border: 1px solid black "'' '$content);
  325.       $content str_replace('id="paragraphe0" class="titreContenu"'' '$content);
  326.       $content str_replace('style="color: #000000 "'' '$content);
  327.       $content str_replace('<p> </p>'' '$content);
  328.       $content str_replace('id="document" class="document"'' '$content);
  329.       $content str_replace('color: #xxxxxx'' '$content);
  330.       $content str_replace('<strong> </strong>'' '$content);
  331.       $content str_replace('class="font-weight-bold"'' '$content);
  332.       $content str_replace('<p style="text-align: center "> </p>'' '$content);
  333.       $content str_replace('<h2></h2>'' '$content);
  334.       $content str_replace('<em></em>'' '$content);
  335.       $content str_replace('<img></img>'' '$content);
  336.       $content str_replace('<span></span>'' '$content);
  337.       $post->setShortDescription($description);
  338.       $post->setContent($content);
  339.       $topic $this->em->getRepository(Topic::class)->find(12);
  340.       $post
  341.         ->setLink1("Retrouvez le détail de cet article en cliquant sur ce lien")
  342.         ->setUrl1("https://contact.lenord.fr/contact/" $actu->_id)
  343.         ->addTopic($topic)
  344.         ->setEpingle1(false)
  345.         ->setEpingle2(false)
  346.         ->setCreatedBy($user_cr)
  347.         ->addTargetpublic($public)
  348.         ->setType($type)
  349.         ->setCreatedAt($actu->datePublication)
  350.         ->setDateDebut($actu->datePublication)
  351.         ->setUpdatedAt($actu->datePublication)
  352.         ->setStatus($status)
  353.         ->setSlug($this->get('url_service')->formatAlias($actu->titre));
  354.       $this->em->persist($post);
  355.       $myFile->setTraite(true)
  356.         ->setDate(new DateTime);
  357.       $this->em->persist($myFile);
  358.     }
  359.     $this->em->flush();
  360.     return $this->redirectToRoute('easyadmin', [
  361.       'action' => 'list',
  362.       'entity' => $request->query->get('entity')
  363.     ]);
  364.   }
  365.   #[Route(path'/favoris'name'favoris')]
  366.   public function favoris(Request $request): mixed
  367.   {
  368.     $this->params['title'] = "Favoris";
  369.     $this->params['tagbar'] = false;
  370.     $this->params['posts'] = $this->getFavoris($request);
  371.     $this->params['items_total'] = sizeof($this->params['posts']);
  372.     $this->params['show_date_bar'] = 0;
  373.     $this->params['is_favorites_page'] = 1;
  374.     $this->params['referer'] = $request->headers->get('referer');
  375.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'Mes Favoris');
  376.     if ($this->params['initial_limit'] != 0) {
  377.       array_splice($this->params['posts'], $this->params['initial_limit'], (is_countable($this->params['posts']) ? count($this->params['posts']) : 0) - 1);
  378.     }
  379.     //Epingle
  380.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  381.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  382.   }
  383.   private function getFavoris(Request $request): mixed
  384.   {
  385.     $post_ids = [];
  386.     $user $this->getUser();
  387.     if ($user !== null) {
  388.       foreach ($user->getFavoris() as $favori) {
  389.         array_push($post_ids, (int)$favori->getId());
  390.       }
  391.     } else {
  392.       $posts explode(','$request->cookies->get('favorite'));
  393.       foreach ($posts as $index => $value) {
  394.         array_push($post_ids, (int)$value);
  395.       }
  396.     }
  397.     //epingle
  398.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  399.     return $this->em->getRepository(Post::class)->myFavorite(array_values($post_ids));
  400.   }
  401.   #[Route(path'/commenter/{token}'name'commenter')]
  402.   public function commenter(Request $requeststring $token): Response
  403.   {
  404.     $tab = [];
  405.     $content $request->request->get('content');
  406.     $params $request->request;
  407.     $commentaire $this->em->getRepository(PostCommentaires::class)->findOneBy(['token' => $token]);
  408.     $post $commentaire->getPost();
  409.     $post->setCommentCount($post->getCommentCount() + 1);
  410.     $this->em->persist($post);
  411.     $valide $params->get('validationCheck');
  412.     $commentaire
  413.       ->setValide(($valide != null) ? true false)
  414.       ->setDateComment(new DateTime)
  415.       ->setContent($content);
  416.     $this->em->persist($commentaire);
  417.     $this->em->flush();
  418.     $this->params['post'] = $post;
  419.     $content_post null;
  420.     if ($post->getContent() != null) {
  421.       $content_post $this->feedUtilities->jsonToHtml($post->getContent(), $request);
  422.     }
  423.     $this->params['content_post'] = $content_post;
  424.     //Mail
  425.     $expediteur = [];
  426.     $tab['address'] = ['email' => $commentaire->getAuteur(), 'name' => $commentaire->getAuteur()];
  427.     array_push($expediteur$tab);
  428.     $date = new DateTime;
  429.     $content_mail $this->renderView(
  430.       'Nordinfo/Mails/commentaire.html.twig',
  431.       ['titre_article' => $post->getTitle(), 'date_jour' => $date->format('d/m/Y'), 'heure_jour' => $date->format('H:i'), 'url_article' => 'https://info.lenord.fr/' $post->getSlug(), 'message' => $content]
  432.     );
  433.     $this->sendgrid_service->send([$commentaire->getAuteur()], $content_mail"Merci pour votre commentaire");
  434.     //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $commentaire->getAuteur(), $content_mail, "Merci pour votre commentaire");
  435.     //mail auteur du post
  436.     $dest = [];
  437.     $tab['address'] = ['email' => $post->getCreatedBy()->getEmail(), 'name' => $post->getCreatedBy()->getEmail()];
  438.     array_push($dest$tab);
  439.     $content_mail_post $this->renderView(
  440.       'Nordinfo/Mails/commentaire_dest.html.twig',
  441.       ['titre_article' => $post->getTitle(), 'date_jour' => $date->format('d/m/Y'), 'heure_jour' => $date->format('H:i'), 'url_article' => 'https://info.lenord.fr/' $post->getSlug(), 'message' => $content]
  442.     );
  443.     $this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr''Nord info contact'$post->getCreatedBy()->getEmail(), $content_mail_post"Merci pour votre commentaire");
  444.     $this->params['com'] = $commentaire;
  445.     $this->params['message'] = "Merci, votre commentaire a bien été transmis à l'auteur de l'article.";
  446.     return $this->render('Nordinfo/Main/endcommentaire.html.twig'$this->params);
  447.   }
  448.   #[Route(path'/error'name'error')]
  449.   public function error(Request $request): Response
  450.   {
  451.     return $this->render('bundles/TwigBundle/Exception/error404.html.twig'$this->params);
  452.   }
  453.   #[Route(path'/comment/{token}'name'comment_post')]
  454.   public function commentPost(Request $requeststring $token): Response
  455.   {
  456.     $comm $this->em->getRepository(PostCommentaires::class)->findOneBy(['token' => $token]);
  457.     if ($comm == null) {
  458.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  459.     }
  460.     $date = new DateTime;
  461.     if ($date $comm->getDate()) {
  462.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  463.     }
  464.     $this->params['post'] = $post $comm->getPost();
  465.     $content_post null;
  466.     if ($post->getContent() != null) {
  467.       $content_post $this->feedUtilities->jsonToHtml($post->getContent(), $request);
  468.     }
  469.     $this->params['content_post'] = $content_post;
  470.     $this->params['com'] = $comm;
  471.     return $this->render('Nordinfo/Main/feedback.html.twig'$this->params);
  472.   }
  473.   #[Route(path'/save'name'save_only')]
  474.   public function saveonly(Request $request): Response
  475.   {
  476.     $form_parameters null;
  477.     if ($request->query->get('article') != null) {
  478.       $form_parameters $request->query->get('article');
  479.     } else if ($request->query->get('postevent') != null) {
  480.       $form_parameters $request->query->get('postevent');
  481.     }
  482.     $post $this->em->getRepository(Post::class)->find($request->query->get('id'));
  483.     $querybuilder $this->em->createQueryBuilder()
  484.       ->update()
  485.       ->from(Post::class, 'post')
  486.       ->where('post.id = :id')
  487.       ->setParameter('id'$request->query->get('id'));
  488.     foreach ((array)$form_parameters as $index => $value) {
  489.       if ($index == 'topics') {
  490.         $post->getTopics()->clear();
  491.         foreach ($value as $id) {
  492.           $topic $this->em->getRepository(Topic::class)->find($id);
  493.           $post->addTopic($topic);
  494.         }
  495.       } else if ($index == 'territories') {
  496.         $post->getTerritories()->clear();
  497.         foreach ($value as $id) {
  498.           $topic $this->em->getRepository(Territory::class)->find($id);
  499.           $post->addTerritory($topic);
  500.         }
  501.       } else if ($index == 'targetpublics') {
  502.         $post->getTargetpublics()->clear();
  503.         foreach ($value as $id) {
  504.           $topic $this->em->getRepository(TargetPublic::class)->find($id);
  505.           $post->addTargetpublic($topic);
  506.         }
  507.       } else if ($index != '_token') {
  508.         $querybuilder $this->setValue($querybuilder$index$value);
  509.       }
  510.     }
  511.     $querybuilder->getQuery()
  512.       ->getSingleScalarResult();
  513.     $this->em->persist($post);
  514.     $this->em->flush();
  515.     return new Response('ok');
  516.   }
  517.   private function setValue(mixed $querybuildermixed $indexmixed $value): mixed
  518.   {
  519.     //Many to many relations
  520.     $querybuilder->set('post.' $index':' $index)
  521.       ->setParameter(':' $index, ($value == "") ? null $value);
  522.     return $querybuilder;
  523.   }
  524.   /**
  525.    * @throws TypeException
  526.    */
  527.   #[Route(path'/form-event'name'send_form_event')]
  528.   public function sendformEvent(Request $request): Response
  529.   {
  530.     $post $request->request;
  531.     $result_ $post->get('nb1') + $post->get('nb2');
  532.     if ($result_ == $post->get('captcha') && $post->get('raison') == null) {
  533.       $event_type $this->em->getRepository(EventType::class)->find($post->get('type'));
  534.       $date_debut date_create_from_format('d/m/Y'$post->get('date_debut'));
  535.       $date_fin date_create_from_format('d/m/Y'$post->get('date_fin'));
  536.       $auth_extension = ['png''jpg''jpeg''gif''pdf'];
  537.       $mime_authorized = ['application/pdf''image/jpg''image/jpeg''image/gif''image/png'];
  538.       $file null;
  539.       $fileName null;
  540.       if ($request->files->get('image') != null) {
  541.         $file $request->files->get('image');
  542.         $fileType $file->getClientMimeType();
  543.         $originalFilename pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  544.         $safeFilename transliterator_transliterate('Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()'$originalFilename);
  545.         $fileName $safeFilename '-' uniqid(''true) . '.' $file->guessExtension();
  546.         $uploadDir $this->getParameter('kernel.project_dir') . '/public/upload/images/';
  547.         if (in_array($fileType$mime_authorizedtrue) && in_array($file->guessExtension(), $auth_extensiontrue)) {
  548.           try {
  549.             $target $uploadDir $fileName;
  550.             copy($file->getRealPath(), $target);
  551.           } catch (FileException) {
  552.             $file null;
  553.             $this->params['message'] = 'File could not be uploaded';
  554.             return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  555.           }
  556.         } else {
  557.           $file null;
  558.           $this->params['message'] = "Mauvais format d'image";
  559.           return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  560.         }
  561.       }
  562.       $destinataires_sendgrid = [];
  563.       $dests "olivier.carpentier@spontaneit.fr;nordinfo@lenord.fr;agenda.nordinfo@lenord.fr";
  564.       if ($post->get('dest') != null) {
  565.         $dests .= ";" $post->get('dest');
  566.       }
  567.       $param_d explode(';'$dests);
  568.       foreach ($param_d as $value) {
  569.         $destinataires_sendgrid[] = $value;
  570.       }
  571.       $m_horaires = ($post->get('horaires') != null) ? '<br><b>Horaires :</b> ' $post->get('horaires') : '';
  572.       $m_tarifs = ($post->get('tarifs') != null) ? '<br><b>Tarifs :</b> ' $post->get('tarifs') : '';
  573.       $m_email = ($post->get('email') != null) ? '<br><b>Adresse courriel pour informations complémentaires et/ou réservation :</b> ' $post->get('email') : '';
  574.       $m_adresse = ($post->get('adresse') != null) ? '<br><b>Adresse :</b> ' $post->get('adresse') : '';
  575.       $m_telephone = ($post->get('telephone') != null) ? '<br><b>Contact téléphonique pour informations complémentaires et/ou réservation :</b> ' $post->get('telephone') : '';
  576.       $m_lien1 = ($post->get('lien1') != null) ? '<br><b>Lien utile 1 :</b> ' $post->get('lien1') : '';
  577.       $m_lien2 = ($post->get('lien2') != null) ? '<br><b>Lien utile 2 :</b> ' $post->get('lien2') : '';
  578.       $message =
  579.         '<b>Organisateur :</b> ' $post->get('organisateur')
  580.         . "<br><b>Email de l'organisateur :</b> " $post->get('email_organisateur')
  581.         . "<br><b>Titre de l'évènement :</b> " $post->get('titre')
  582.         . '<br><b>Type de manifestation :</b> ' $event_type?->getDisplayName()
  583.         . '<br><b>Lieu (Salle, lieu dit, Bâtiment) :</b> ' $post->get('lieu')
  584.         . $m_adresse
  585.         '<br><b>Code postal :</b> ' $post->get('code_postal')
  586.         . '<br><b>Ville :</b> ' $post->get('ville')
  587.         . '<br><b>Date de début :</b> ' $date_debut->format('d/m/Y')
  588.         . '<br><b>Date de fin :</b> ' $date_fin->format('d/m/Y')
  589.         . $m_horaires
  590.         $m_tarifs
  591.         '<br><b>Présentation :</b> ' $post->get('presentation')
  592.         . $m_email
  593.         $m_telephone
  594.         $m_lien1
  595.         $m_lien2;
  596.       $content_mail $this->renderView(
  597.         'Nordinfo/Mails/proposerevent_exp2.html.twig',
  598.         ['titre' => $post->get('titre'), 'message' => $message'nom_fichier' => $fileName]
  599.       );
  600.       $this->sendgrid_service->send([$post->get('email_organisateur')], $content_mail"Merci pour votre évènement"null$file);
  601.       $content_mail $this->renderView(
  602.         'Nordinfo/Mails/proposerevent_dest2.html.twig',
  603.         ['titre' => $post->get('titre'), 'message' => $message'nom_fichier' => $fileName]
  604.       );
  605.       $this->sendgrid_service->send($destinataires_sendgrid$content_mail"Nouvelle proposition d'évènement"null$file);
  606.       //event en base
  607.       $post_type $this->em->getRepository(PostType::class)->find(3);
  608.       $status $this->em->getRepository(Statut::class)->find(1);
  609.       $auteur $this->em->getRepository(User::class)->find(30);
  610.       $public $this->em->getRepository(TargetPublic::class)->find(1);
  611.       $event = new Post;
  612.       $now time();
  613.       $description $post->get('presentation');
  614.       $description str_replace('"''\\"'$description);
  615.       $description nl2br($description);
  616.       $description str_replace(["\r""\n"], ''$description);
  617.       $contentJson '{"time":' $now ',"blocks":[{"type":"paragraph","data":{"text":"' $description '"}}';
  618.       if ($post->get('email') != null) {
  619.         $contentJson .= ', {"type":"paragraph","data":{"text":"Adresse courriel pour informations complémentaires et/ou réservation : <a href=\"mailto:' $post->get('email') . '\">' $post->get('email') . '</a>"}}],"version":"2.15.0"}';
  620.       } else {
  621.         $contentJson .= '],"version":"2.15.0"}';
  622.       }
  623.       $lieu = ($post->get('adresse') != null) ? $post->get('adresse') : null;
  624.       $lieu .= ($lieu != null) ? ', ' null;
  625.       $lieu .= $post->get('lieu');
  626.       $json '{"modeDates":"range","datesRange":{"dateStart":"' $post->get('date_debut') . '","dateFinish":"' $post->get('date_fin') . '","dates":[],"modeHours":"simple","hoursDetails":[],"hoursSimple":[{"hour1":"' $post->get('heure_debut') . '","hour2":"' $post->get('heure_fin') . '","hour3":"","hour4":""}]},"dateSingle":{"dates":[""],"hoursSimple":[{"hour1":"","hour2":"","hour3":"","hour4":""}]},"datesMultiple":{"dates":[""],"modeHours":"details","hoursDetails":[],"hoursSimple":[{"hour1":"","hour2":"","hour3":"","hour4":""}]}}';
  627.       $commune $this->em->getRepository(Commune::class)->findOneBy(['commune' => $post->get('ville')]);
  628.       if ($commune !== null) {
  629.         $event->addTerritory($commune->getTerritoire());
  630.       }
  631.       //LIEU
  632.       $str_adresse $post->get('adresse') . ', ' $post->get('code_postal') . ', ' $post->get('ville');
  633.       $lieu_new $this->em->getRepository(Lieu::class)->findOneBy(['adresse' => $str_adresse]);
  634.       if ($lieu_new == null) {
  635.         $lieu_new = new Lieu;
  636.         $lieu_new->setName($post->get('lieu'))
  637.           ->setAdresse($str_adresse)
  638.           ->setCodepostal($post->get('code_postal'));
  639.         $this->em->persist($lieu_new);
  640.         $this->em->flush();
  641.       }
  642.       $event->setTitle($post->get('titre'))
  643.         ->setIllustrationfilName($fileName)
  644.         ->setLieuNew($lieu_new)
  645.         ->setType($post_type)
  646.         ->addEventType($event_type)
  647.         ->addTargetPublic($public)
  648.         ->setOrganisation4($post->get('adresse') . ' ' $post->get('code_postal') . ' ' $post->get('lieu'))
  649.         ->setHoraires($post->get('horaires'))
  650.         ->setTarifs($post->get('tarifs'))
  651.         ->setOrganizedBy($post->get('organisateur'))
  652.         ->setCommentaires("Organisateur de l'évènement = " $post->get('email_organisateur') . ($post->get('email') !== null) ? ', Contact et réservation= ' $post->get('email') . '\n' ' COPIE DE LA DESCRIPTION:' $description null)
  653.         ->setUrl1($post->get('lien1'))
  654.         ->setLink1($post->get('lien1'))
  655.         ->setUrl2($post->get('lien2'))
  656.         ->setLink2($post->get('lien2'))
  657.         ->setStatus($status)
  658.         ->setCreatedBy($auteur)
  659.         ->setContent($contentJson)
  660.         ->setLieu($lieu)
  661.         ->setVille($post->get('ville'))
  662.         ->setDateDebut($date_debut->format('d/m/Y'))
  663.         ->setDateFin($date_fin->format('d/m/Y'))
  664.         ->setJson($json)
  665.         ->setEpingle1(false)
  666.         ->setEpingle2(false)
  667.         ->setDefautFil(false);
  668.       $this->em->persist($event);
  669.       $this->em->flush();
  670.     } else {
  671.       $this->params['message'] = 'Captcha erreur';
  672.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  673.     }
  674.     return $this->render('Nordinfo/Main/endform.html.twig'$this->params);
  675.   }
  676.   #[Route(path'/confirmation'name'send_form')]
  677.   public function sendform(Request $request): Response
  678.   {
  679.     $destinataires_sendgrid = [];
  680.     $post $request->request;
  681.     $formThematique $this->em->getRepository(FormulaireThematique::class)->find($post->get('objet'));
  682.     $message $post->get('message');
  683.     if ($formThematique !== null) {
  684.       $objet $formThematique->getName();
  685.       $emails explode(";", (string) $formThematique->getDestinataires());
  686.       foreach ($emails as $iValue) {
  687.         $destinataires_sendgrid[] = $iValue;
  688.       }
  689.     } else {
  690.       $objet 'Message à un(e) élu(e) : ' $request->request->get('dest_nom');
  691.       if (str_contains($request->request->get('dest'), ";") == true) {
  692.         $ex explode(";"$request->request->get('dest'));
  693.         foreach ($ex as $iValue) {
  694.           $destinataires_sendgrid[] = $iValue;
  695.         }
  696.       } else {
  697.         $destinataires_sendgrid[] = $request->request->get('dest');
  698.       }
  699.       $mail_elu = new MailElu;
  700.       $userIp $request->getClientIp();
  701.       $mail_elu->setDate(new DateTime())
  702.         ->setElu($request->request->get('dest_nom'))
  703.         ->setContenu($message)
  704.         ->setIp($userIp)
  705.         ->setEmail($post->get('email'));
  706.       $this->em->persist($mail_elu);
  707.       $this->em->flush();
  708.     }
  709.     $fileName null;
  710.     $auth_extension = ['png''jpg''jpeg''gif''pdf'];
  711.     $mime_authorized = ['application/pdf''image/jpg''image/jpeg''image/gif''image/png'];
  712.     $file null;
  713.     $newname uniqid(''true);
  714.     if ($request->files != null && $request->files->get('file') != null) {
  715.       $file $request->files->get('file');
  716.       $fileName $file->getClientOriginalName();
  717.       $fileType $file->getClientMimeType();
  718.       if (in_array($file->guessExtension(), $auth_extensiontrue) && in_array($fileType$mime_authorizedtrue)) {
  719.         /*try {
  720.           $file->move($uploadDir, $newname.'.'.$file->guessExtension());
  721.           array_push($files, array(
  722.             'name' => $newname.'.'.$file->guessExtension(),
  723.             'type' => $fileType,
  724.             'data' => $fileData,
  725.           ));
  726.         } catch (FileException) {
  727.           $file = null;
  728.           return new JsonResponse(['error' => 'File could not be uploaded']);
  729.         }*/
  730.       } else {
  731.         $file null;
  732.         return new JsonResponse(['error' => "Mauvais format d'image"]);
  733.       }
  734.     }
  735.     $date = new DateTime;
  736.     $content $this->renderView(
  737.       'Nordinfo/Mails/dest_signalement2.html.twig',
  738.       ['expediteur_email_' => $post->get('email'), 'destinataire_' => "agent en charge du support aux usagers"'objet_' => $objet'message_' => $message'piece_jointe_' => ($fileName != null) ? $fileName "Aucune pièce jointe"'date' => "NI" $date->format('dmYHis')]
  739.     );
  740.     $nom_dest 'rédaction du Nord info';
  741.     $content_exp $this->renderView(
  742.       'Nordinfo/Mails/exp_signalement2.html.twig',
  743.       ['destinataire_' => $nom_dest'objet_' => $objet'message_' => $message'piece_jointe_' => ($fileName != null) ? $fileName "Aucune pièce jointe"'date' => "NI" $date->format('dmYHis')]
  744.     );
  745.     if ($post->get('newsletter') != null) {
  746.       $ins $this->em->getRepository(InscritNewsletter::class)->findOneBy(['email' => $post->get('email')]);
  747.       if ($ins == null) {
  748.         $ins = new InscritNewsletter;
  749.         $ins->setEmail($post->get('email'))
  750.           ->setPrenom($post->get('prenom'))
  751.           ->setNom($post->get('nom'))
  752.           ->setDate(new DateTime());
  753.         $this->em->persist($ins);
  754.         $this->em->flush();
  755.       }
  756.     }
  757.     $result_ $post->get('nb1') + $post->get('nb2');
  758.     if ($result_ == $post->get('captcha') && $post->get('raison') == null) {
  759.       try {
  760.         //$this->sendMail($content, 'Demande de contact depuis nordinfo : ' . $objet, $destinataires, $files);
  761.         //FILES!
  762.         $this->sendgrid_service->send($destinataires_sendgrid$content'Demande de contact depuis Nord Info : ' $objet ' / ' 'NI' $date->format('dmYHis'), ['automate.nordinfo@lenord.fr'], $file);
  763.         $this->sendgrid_service->send([$post->get('email')], $content_exp"Votre message sur Nord info " $objet " / " "NI" $date->format('dmYHis'), ['automate.nordinfo@lenord.fr'], $file);
  764.       } catch (Exception) {
  765.         $this->params['message'] = 'Email erreur';
  766.         return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  767.       }
  768.     }
  769.     return $this->render('Nordinfo/Main/endform.html.twig'$this->params);
  770.   }
  771.   private function getMenusTop(): void
  772.   {
  773.     $this->params['menusTop'] = $this->em->getRepository(MenuLibelle::class)->findBy(['ordre' => 0]);
  774.   }
  775.   private function getMenusProfile(): void
  776.   {
  777.     $this->params['menusprofile'] = $this->em->getRepository(MenuLibelle::class)
  778.       ->getMenuProfile();
  779.   }
  780.   #[Route(path'/ajax/sondage'name'ajax_count_sondage')]
  781.   public function countResponseSondage(Request $request): Response
  782.   {
  783.     $response $this->em->getRepository(PostReponses::class)->find($request->request->get('response_id'));
  784.     $response->setCount($response->getCount() + 1);
  785.     $this->em->persist($response);
  786.     $this->em->flush();
  787.     $total_vote $this->em->getRepository(PostReponses::class)->getTotalVote($request->request->get('sondage_id'))['total'];
  788.     $responses $this->em->getRepository(PostReponses::class)->getSondageResponses($request->request->get('sondage_id'));
  789.     $votes = [];
  790.     foreach ($responses as $resp) {
  791.       array_push($votes, ['texte' => $resp->getTexte(), 'pourcent' => ($resp->getCount() == 0) ? number_format(($resp->getCount() / $total_vote) * 1002)]);
  792.     }
  793.     return new JsonResponse(['sondage' => $request->request->get('sondage_id'), 'total' => $total_vote'votes' => $votes'valide' => $response->getValide()]);
  794.   }
  795.   public function getPublic(): mixed
  796.   {
  797.     $public false;
  798.     if ($this->getUser() != null) {
  799.       if ($this->getUser()->getRole() === 'vip') {
  800.         $public 'vip';
  801.       } else if ($this->getUser()->getRole() === 'presse') {
  802.         $public 'presse';
  803.       } else if ($this->getUser()->getRole() === 'agent') {
  804.         $public 'agent';
  805.       } else if ($this->getUser()->getRole() === 'admin' || $this->getUser()->getRole() === 'superadmin' || $this->getUser()->getRole() === 'redacteur') {
  806.         $public 'tous';
  807.       }
  808.     }
  809.     return $public;
  810.   }
  811.   #[Route(path'/tag/{tag}'name'search_tag')]
  812.   public function search_tag(Request $requeststring $tag): Response
  813.   {
  814.     $this->params['referer'] = $request->headers->get('referer');
  815.     $this->params['tag'] = $tag;
  816.     $tagName $tag// original string from route
  817.     $tagEntity $this->em->getRepository(Tags::class)->findOneBy(['motcle' => $tagName]);
  818.     $exp = [];
  819.     $this->params['posts'] = [];
  820.     if ($tagEntity && $tagEntity->getExpressions()) {
  821.       $exp explode(';', (string)$tagEntity->getExpressions());
  822.       $postsFromTag $this->em->getRepository(Post::class)->getPostsFromTag($tagEntity->getId());
  823.       $this->params['posts'] = $postsFromTag;
  824.     }
  825.     $public $this->getPublic();
  826.     if (count($exp) > 0) {
  827.       foreach ($exp as $hashtag) {
  828.         $posts $this->em->getRepository(Post::class)
  829.           ->getCustomSearchPost($hashtagfalse$publictrue);
  830.         $this->params['posts'] = array_merge($this->params['posts'], $posts);
  831.       }
  832.     }
  833.     $uniquePosts = [];
  834.     $seenIds = [];
  835.     foreach ($this->params['posts'] as $post) {
  836.       $postId $post->getId();
  837.       if (!in_array($postId$seenIdstrue)) {
  838.         $seenIds[] = $postId;
  839.         $uniquePosts[] = $post;
  840.       }
  841.     }
  842.     usort($uniquePosts, static function ($a$b) {
  843.       return $b->getCreatedAt() <=> $a->getCreatedAt();
  844.     });
  845.     $this->params['posts'] = $uniquePosts;
  846.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  847.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  848.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  849.     $this->params['posts_count'] = count($this->params['posts']);
  850.     $this->params['text_plus_button'] = 'PLUS DE RÉSULTATS';
  851.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  852.     return $this->render('Nordinfo/Main/search_tags.html.twig'$this->params);
  853.   }
  854.   #[Route(path'/recherche_elastic'name'recherche_elastic')]
  855.   public function recherche_elastic(Request $request): Response
  856.   {
  857.     $this->params['referer'] = $request->headers->get('referer');
  858.     $this->params['search'] = $request->query->get('search');
  859.     $intranet false;
  860.     if ($this->getUser() != null) {
  861.       $intranet true;
  862.     }
  863.     if ($request->query->get('search') != null) {
  864.       //Save log
  865.       $logEs = new LogEs;
  866.       $logEs->setRecherche($request->query->get('search'))
  867.         ->setDate(new DateTime())
  868.         ->setSite("info");
  869.       $this->em->persist($logEs);
  870.       $this->em->flush();
  871.     }
  872.     $public $this->getPublic();
  873.     $search_conditions = ['intranet' => $intranet'public' => $public];
  874.     $search_fields = ['combined'];
  875.     $results $this->es_service->searchDocuments('nordinfo'$search_fields$request->query->get('search'), null, [], [], 200false$search_conditions);
  876.     $this->params['results'] = $results;
  877.     return $this->render('Nordinfo/Main/search_elastic.html.twig'$this->params);
  878.   }
  879.   #[Route(path'/recherche'name'search_words'priority10)]
  880.   public function search_words(Request $request): Response
  881.   {
  882.     $this->params['referer'] = $request->headers->get('referer');
  883.     $this->params['search'] = $request->query->get('search');
  884.     $intranet false;
  885.     if ($this->getUser() != null) {
  886.       $intranet true;
  887.     }
  888.     if ($request->query->get('search') != null) {
  889.       //Save log
  890.       $logEs = new LogEs;
  891.       $logEs->setRecherche($request->query->get('search'))
  892.         ->setDate(new DateTime())
  893.         ->setSite("info");
  894.       $this->em->persist($logEs);
  895.       $this->em->flush();
  896.     }
  897.     $public $this->getPublic();
  898.     $posts $this->em->getRepository(Post::class)->getCustomSearchPost($request->query->get('search'), $intranet$public);
  899.     $posts iterator_to_array($posts);
  900.     $posts array_slice($posts0400);
  901.     foreach ($posts as &$post) {
  902.       $post['couleurTexte'] = $post['couleur_texte'];
  903.       if ($post['couleur_texte']) {
  904.         $post['couleurTexte']['codeHexa'] = $post['couleur_texte']['code_hexa'];
  905.         $post['couleurTexte']['codeHexaDark'] = $post['couleur_texte']['code_hexa_dark'];
  906.       }
  907.       if ($post['couleur']) {
  908.         $post['couleur']['codeHexa'] = $post['couleur']['code_hexa'];
  909.         $post['couleur']['codeHexaDark'] = $post['couleur']['code_hexa_dark'];
  910.       }
  911.     }
  912.     unset($post);
  913.     $posts $this->new_feed_utilities->checkboxes_get_description($posts$request);
  914.     $posts $this->new_feed_utilities->social_posts_padding($posts$request);
  915.     $posts $this->new_feed_utilities->focus_pub_img_dimensions($posts$request);
  916.     $posts $this->new_feed_utilities->social_posts_detect_links($posts);
  917.     $this->params['posts'] = $this->agenda_service->parseAgendaEvents($posts);
  918.     $this->params['posts_count'] = count($this->params['posts']);
  919.     $this->params['text_plus_button'] = 'PLUS DE RÉSULTATS';
  920.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  921.     return $this->render('Nordinfo/Main/search_words.html.twig'$this->params);
  922.   }
  923.   #[Route(path'/liste-des-articles'name'liste_articles')]
  924.   public function listearticles(Request $request): Response
  925.   {
  926.     $this->params['referer'] = $request->headers->get('referer');
  927.     $this->params['list_type'] = 'info';
  928.     $this->params['title'] = "L'info";
  929.     $this->params['tagbar'] = false;
  930.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts([1], nullnull);
  931.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  932.     $this->params['items_total'] = sizeof($this->params['posts']);
  933.     $this->params['show_date_bar'] = 0;
  934.     $this->params['show_nav'] = 'false';
  935.     if ($this->params['initial_limit'] != 0) {
  936.       array_splice($this->params['posts'], $this->params['initial_limit'], (is_countable($this->params['posts']) ? count($this->params['posts']) : 0) - 1);
  937.     }
  938.     //epingle
  939.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  940.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  941.   }
  942.   #[Route(path'/liste-des-videos'name'liste_videos')]
  943.   public function listevideos(Request $request): Response
  944.   {
  945.     $this->params['referer'] = $request->headers->get('referer');
  946.     $this->params['list_type'] = 'info';
  947.     $this->params['title'] = "L'info";
  948.     $this->params['tagbar'] = false;
  949.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts([4], nullnull);
  950.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  951.     $this->params['items_total'] = sizeof($this->params['posts']);
  952.     $this->params['show_date_bar'] = 0;
  953.     $this->params['show_nav'] = 'false';
  954.     if ($this->params['initial_limit'] != 0) {
  955.       array_splice($this->params['posts'], $this->params['initial_limit'], (is_countable($this->params['posts']) ? count($this->params['posts']) : 0) - 1);
  956.     }
  957.     //epingle
  958.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  959.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  960.   }
  961.   #[Route(path'/info'name'info')]
  962.   public function info(Request $request): Response
  963.   {
  964.     $private false;
  965.     $this->params['private'] = false;
  966.     if ($this->getUser() != null) {
  967.       $function $request->query->get('function');
  968.       if ($function === 'private_only') {
  969.         $private true;
  970.         $this->params['private'] = true;
  971.       }
  972.     }
  973.     $this->params['referer'] = $request->headers->get('referer');
  974.     $this->params['show_date_bar'] = 1;
  975.     $this->params['actus'] = true;
  976.     $this->params['list_type'] = 'actus';
  977.     $this->params['title'] = 'L’info';
  978.     $dateday = new DateTime;
  979.     $dateday->modify('+7 day');
  980.     $this->params['date_day'] = $dateday;
  981.     $this->params['tags'] = $this->em->getRepository(Tags::class)->getActiveTags();
  982.     $this->params['items_total'] = 0;
  983.     $type_posts = [1245679];
  984.     if ($this->getUser() != null && in_array($this->getUser()->getRole(), $this->arr_intranettrue)) {
  985.       $type_posts[] = 8;
  986.     }
  987.     $territory_ids $this->getTerritoryIds($request);
  988.     $topic_ids $this->getTopicIds($request);
  989.     $this->params['cookie_territories'] = $this->getTerritories($request);
  990.     $this->params['cookie_topics'] = $this->getTopics($request);
  991.     
  992.     $this->params['topics'] = $this->em->getRepository(Topic::class)->getAll();
  993.     $checkTopics = [];
  994.     if ($this->getUser() != null) {
  995.       foreach ($this->getUser()->getThematiques() as $topic) {
  996.         $checkTopics[] = $topic->getId();
  997.       }
  998.     } else if ($request->cookies->get('topics') != null) {
  999.       $checkTopics explode(','$request->cookies->get('topics'));
  1000.     }
  1001.     $this->params['checkTopics'] = $checkTopics;
  1002.     $checkTerritories = [];
  1003.     if ($this->getUser() != null) {
  1004.       foreach ($this->getUser()->getTerritoires() as $territoire) {
  1005.         $checkTerritories[] = $territoire->getId();
  1006.       }
  1007.     } else if ($request->cookies->get('territories') != null) {
  1008.       $checkTerritories explode(','$request->cookies->get('territories'));
  1009.     }
  1010.     $territories $this->em->getRepository(Territory::class)->getListeTerritories();
  1011.     $this->params['territories'] = $territories;
  1012.     $this->params['checkTerritories'] = $checkTerritories;
  1013.     $public $this->getPublic();
  1014.     if ($private === true && $public === 'tous') {
  1015.       $territory_ids null;
  1016.       $topic_ids null;
  1017.     }
  1018.     $latestEpingle1 $this->em->getRepository(Post::class)->getLatestEpingle1($territory_ids$topic_ids);
  1019.     $latestTwoEpingles2 $this->em->getRepository(Post::class)->getLatestTwoEpingles2($territory_ids$topic_ids);
  1020.     $this->params['latest_epingle_1'] = $latestEpingle1;
  1021.     $this->params['latest_two_epingles_2'] = $latestTwoEpingles2;
  1022.     $posts $this->em->getRepository(Post::class)
  1023.       ->getCustomPosts(
  1024.         $type_posts,
  1025.         false,
  1026.         null,
  1027.         $territory_ids,
  1028.         $topic_ids,
  1029.         true,
  1030.         'DESC',
  1031.         $this->params['initial_limit'],
  1032.         0,
  1033.         false,
  1034.         null,
  1035.         null,
  1036.         false,
  1037.         $public,
  1038.         false,
  1039.         $private
  1040.       );
  1041.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)
  1042.       ->getCustomPosts(
  1043.         $type_posts,
  1044.         false,
  1045.         null,
  1046.         $territory_ids,
  1047.         $topic_ids,
  1048.         true,
  1049.         'DESC',
  1050.         null,
  1051.         0,
  1052.         true,
  1053.         null,
  1054.         null,
  1055.         false,
  1056.         $public,
  1057.         false,
  1058.         $private
  1059.       );
  1060.     $this->params['posts'] = $posts;
  1061.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1062.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1063.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1064.     $this->params['show_nav'] = 'true';
  1065.     $this->params['text_plus_button'] = 'PLUS D\'ACTU';
  1066.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1067.     $epingles_ $this->epingle_service->getEpinglesSection('mesinfos');
  1068.     foreach ($epingles_ as $epingle) {
  1069.       $this->params['epingles'][] = $epingle;
  1070.     }
  1071.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1072.     return $this->render('Nordinfo/Main/actus.html.twig'$this->params);
  1073.   }
  1074.   #[Route(path'/creation-de-compte'name'registration')]
  1075.   public function registration(): Response
  1076.   {
  1077.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'créer un compte');
  1078.     $this->params['caps'] = $this->getCaptcha();
  1079.     //epingle
  1080.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1081.     return $this->render('Nordinfo/Main/registration.html.twig'$this->params);
  1082.   }
  1083.   #[Route(path'/compte-supprime'name'remove_account')]
  1084.   public function removeAccount(Request $request): Response
  1085.   {
  1086.     $post $request->request;
  1087.     $user $this->getUser();
  1088.     $passwordValid $this->hasher->hashPassword($user$post->get('password'));
  1089.     //epingle
  1090.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1091.     if ($passwordValid && $post->get('checkboxConfirmDelete') != null) {
  1092.       //    if ($passwordValid && $post->get('check') == 'SUPPRIMER') {
  1093.       $destinataire = [];
  1094.       array_push($destinataire, ['email' => $user->getEmail(), 'name' => $user->getEmail()]);
  1095.       $content_mail $this->renderView(
  1096.         'Nordinfo/Mails/removeAccount.html.twig',
  1097.         ['email' => $user->getEmail(), 'nom' => $user->getPrenom() . ' ' $user->getNom()]
  1098.       );
  1099.       $this->em->remove($user);
  1100.       $this->em->flush();
  1101.       $this->sendgrid_service->send([$user->getEmail()], $content_mail"Confirmation de suppression");
  1102.       //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Confirmation de suppression');
  1103.       return $this->render('Nordinfo/Main/endremove.html.twig'$this->params);
  1104.     } else {
  1105.       $this->params['message'] = "Une erreur s'est produite";
  1106.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1107.     }
  1108.   }
  1109.   #[Route(path'/lien-activation/{token}'name'send_activation_again')]
  1110.   public function sendActivation(Request $requeststring $token): Response
  1111.   {
  1112.     $user $this->em->getRepository(User::class)->findOneBy(['token_activation' => $token]);
  1113.     //epingle
  1114.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1115.     if ($user == null) {
  1116.       $this->params['message'] = 'Compte déjà activé ou inexistant';
  1117.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1118.     }
  1119.     //Mail
  1120.     $destinataire = [];
  1121.     array_push($destinataire, ['email' => $user->getEmail(), 'name' => $user->getEmail()]);
  1122.     $date = new DateTime;
  1123.     $url $url $this->generateUrl('user_activate', ['token' => $token]);
  1124.     $content_mail $this->renderView(
  1125.       'Nordinfo/Mails/registration.html.twig',
  1126.       ['url_activation' => 'https://' $request->getHost() . $url]
  1127.     );
  1128.     $this->sendgrid_service->send([$user->getEmail()], $content_mail"Accusé de création de compte");
  1129.     //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Accusé de création de compte');
  1130.     return $this->render('Nordinfo/Main/endform.html.twig'$this->params);
  1131.   }
  1132.   #[Route(path'/send_registration'name'send_registration')]
  1133.   public function send_registration(Request $request): Response
  1134.   {
  1135.     $post $request->request;
  1136.     $caps $this->getCaptcha();
  1137.     //$array_search($post->get('nb1'))
  1138.     $result_ $post->get('nb1') + $post->get('nb2');
  1139.     if ($result_ == $post->get('captcha')) {
  1140.       if ($this->em->getRepository(User::class)->findOneBy(['email' => $post->get('email')]) == null) {
  1141.         //rechercher si adresse @lenord.fa-r-project//droit => agent sinon droit => public
  1142.         $role 'public';
  1143.         $ex_email explode("@"$post->get('email'));
  1144.         if ($ex_email[1] == 'lenord.fr') {
  1145.           $role 'agent';
  1146.         }
  1147.         $token hash('md5'$post->get('email') . uniqid());
  1148.         $this->params['token'] = $token;
  1149.         $user = new User;
  1150.         $hpass $this->hasher->hashPassword($user$post->get('pass'));
  1151.         $user->setEmail($post->get('email'))
  1152.           ->setFirstName($post->get('first_name'))
  1153.           ->setLastName($post->get('last_name'))
  1154.           ->setPassword($hpass)
  1155.           ->setRole($role)
  1156.           ->setActive(false)
  1157.           ->setTokenActivation($token);
  1158.         $this->em->persist($user);
  1159.         $this->em->flush();
  1160.         //email
  1161.         //Mail
  1162.         $destinataire = [];
  1163.         array_push($destinataire, ['email' => $post->get('email'), 'name' => $post->get('email')]);
  1164.         $date = new DateTime;
  1165.         $url $url $this->generateUrl('user_activate', ['token' => $token]);
  1166.         $content_mail $this->renderView(
  1167.           'Nordinfo/Mails/registration.html.twig',
  1168.           ['url_activation' => 'https://' $request->getHost() . $url]
  1169.         );
  1170.         $this->sendgrid_service->send([$post->get('email')], $content_mail"Accusé de création de compte");
  1171.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Accusé de création de compte');
  1172.       } else {
  1173.         $this->params['noenveloppe'] = true;
  1174.         $this->params['message'] = 'Un compte existe déja avec cette adresse, merci de revérifier votre saisie. Si vous avez oublié votre mot de passe, vous pouvez solliciter sa réinitialisation via <a href="/oubli-mot-de-passe">cette page</a>';
  1175.         return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1176.       }
  1177.     } else {
  1178.       $this->params['message'] = 'Captcha erreur';
  1179.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1180.     }
  1181.     return $this->render('Nordinfo/Main/endregister1.html.twig'$this->params);
  1182.   }
  1183.   public function direct(Request $request): Response
  1184.   {
  1185.     $this->params['referer'] = $request->headers->get('referer');
  1186.     $this->params['list_type'] = 'direct';
  1187.     $this->params['title'] = 'En direct';
  1188.     $this->params['tagbar'] = false;
  1189.     $this->params['items_offset'] = 20;
  1190.     $this->params['initial_limit'] = 20;
  1191.     $post_types = [579];
  1192.     $public $this->getPublic();
  1193.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1194.       $post_types,
  1195.       null,
  1196.       'direct',
  1197.       null,
  1198.       null,
  1199.       false,
  1200.       'DESC',
  1201.       $this->params['initial_limit'],
  1202.       0,
  1203.       null,
  1204.       null,
  1205.       false,
  1206.       $public
  1207.     );
  1208.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1209.       $post_types,
  1210.       null,
  1211.       'direct',
  1212.       null,
  1213.       null,
  1214.       false,
  1215.       'DESC',
  1216.       null,
  1217.       0,
  1218.       true,
  1219.       null,
  1220.       null,
  1221.       false,
  1222.       $public
  1223.     );
  1224.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1225.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1226.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1227.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1228.     $this->params['show_nav'] = 'true';
  1229.     $this->params['show_date_bar'] = true;
  1230.     $this->params['text_plus_button'] = 'PLUS DE POSTS';
  1231.     //epingle
  1232.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1233.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1234.   }
  1235.   #[Route(path'/nos-reseaux'name'reseaux')]
  1236.   public function reseaux(): Response
  1237.   {
  1238.     //epingle
  1239.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1240.     return $this->render('Nordinfo/Main/reseaux.html.twig'$this->params);
  1241.   }
  1242.   /**
  1243.    * @throws \JsonException
  1244.    */
  1245.   #[Route(path'/agenda'name'agenda')]
  1246.   public function agenda(Request $request): Response
  1247.   {
  1248.     /**
  1249.      * BE CAREFUL!
  1250.      * THE CODE THAT HAS TO DO WITH RETRIEVING ITEMS, HAS TO BE ALSO CLONED INSIDE THE AjaxController.php
  1251.      */
  1252.     $this->params['referer'] = $request->headers->get('referer');
  1253.     $date_param $request->query->get('date');
  1254.     $query_date2 null;
  1255.     $query_date_from false;
  1256.     if (!isset($date_param) || trim($date_param) === '') {
  1257.       $query_date = new DateTime();
  1258.       $query_date_from true;
  1259.     } else if ($date_param === 'today') {
  1260.       $query_date = new DateTime();
  1261.     } else if ($date_param === 'weekend') {
  1262.       $query_date = new DateTime('Saturday');
  1263.       $query_date2 = new DateTime('Sunday');
  1264.     } else {
  1265.       $query_date_from true;
  1266.       $query_date date_create_from_format('d/m/Y'$date_param);
  1267.       if (!$query_date) {
  1268.         $query_date date_create_from_format('Y-m-d'$date_param);
  1269.       }
  1270.       $outputDate $query_date->format('d F Y');
  1271.       $outputDate str_replace(
  1272.         array('January''February''March''April''May''June''July''August''September''October''November''December'),
  1273.         array('Janvier''Février''Mars''Avril''Mai''Juin''Juillet''Août''Septembre''Octobre''Novembre''Décembre'),
  1274.         $outputDate
  1275.       );
  1276.       $this->params['show_date_bar_agenda'] = $outputDate;
  1277.     }
  1278.     $this->params['list_type'] = 'agenda';
  1279.     $this->params['title'] = 'Agenda';
  1280.     $this->params['tagbar'] = false;
  1281.     $this->params['cookie_search'] = true;
  1282.     $territory_ids $this->getTerritoryIds($request);
  1283.     $this->params['cookie_territories'] = $this->getTerritories($request);
  1284.     $this->params['cookie_topics'] = $this->getTopics($request);
  1285.     
  1286.     $this->params['topics'] = $this->em->getRepository(Topic::class)->getAll();
  1287.     $checkTopics = [];
  1288.     if ($this->getUser() != null) {
  1289.       foreach ($this->getUser()->getThematiques() as $topic) {
  1290.         $checkTopics[] = $topic->getId();
  1291.       }
  1292.     } else if ($request->cookies->get('topics') != null) {
  1293.       $checkTopics explode(','$request->cookies->get('topics'));
  1294.     }
  1295.     $this->params['checkTopics'] = $checkTopics;
  1296.     $checkTerritories = [];
  1297.     if ($this->getUser() != null) {
  1298.       foreach ($this->getUser()->getTerritoires() as $territoire) {
  1299.         $checkTerritories[] = $territoire->getId();
  1300.       }
  1301.     } else if ($request->cookies->get('territories') != null) {
  1302.       $checkTerritories explode(','$request->cookies->get('territories'));
  1303.     }
  1304.     $territories $this->em->getRepository(Territory::class)->getListeTerritories();
  1305.     $this->params['territories'] = $territories;
  1306.     $this->params['checkTerritories'] = $checkTerritories;
  1307.     $public $this->getPublic();
  1308.     $posts $this->em->getRepository(Post::class)->getCustomArrayPosts(
  1309.       [3679],
  1310.       true,
  1311.       'agenda',
  1312.       $territory_ids,
  1313.       null,
  1314.       false,
  1315.       $this->params['total_limit'],
  1316.       0,
  1317.       false,
  1318.       $query_date,
  1319.       $query_date2,
  1320.       $query_date_from,
  1321.       $public
  1322.     );
  1323.     $posts iterator_to_array($posts);
  1324.     $posts $this->new_feed_utilities->checkboxes_get_description($posts$request);
  1325.     $posts $this->new_feed_utilities->social_posts_padding($posts$request);
  1326.     $posts $this->new_feed_utilities->focus_pub_img_dimensions($posts$request);
  1327.     $posts $this->new_feed_utilities->social_posts_detect_links($posts);
  1328.     $postsProcessed $this->agenda_service->parseAgendaEvents($posts$query_date$query_date2true$date_param);
  1329.     $this->params['items_total'] = count($postsProcessed);
  1330.     $this->params['posts'] = array_slice($postsProcessed0$this->params['initial_limit']);
  1331.     foreach ($this->params['posts'] as &$post) {
  1332.       $post['couleurTexte'] = $post['couleur_texte'];
  1333.       if ($post['couleur_texte']) {
  1334.         $post['couleurTexte']['codeHexa'] = $post['couleur_texte']['code_hexa'];
  1335.         $post['couleurTexte']['codeHexaDark'] = $post['couleur_texte']['code_hexa_dark'];
  1336.       }
  1337.       if ($post['couleur']) {
  1338.         $post['couleur']['codeHexa'] = $post['couleur']['code_hexa'];
  1339.         $post['couleur']['codeHexaDark'] = $post['couleur']['code_hexa_dark'];
  1340.       }
  1341.     }
  1342.     unset($post);
  1343.     
  1344.     $this->params['show_agenda_filters'] = 1;
  1345.     $this->params['show_nav'] = 'true';
  1346.     $this->params['text_plus_button'] = 'PLUS D\'ÉVÈNEMENTS';
  1347.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1348.     $epingles_ $this->epingle_service->getEpinglesSection('agenda');
  1349.     foreach ($epingles_ as $epingle) {
  1350.       $this->params['epingles'][] = $epingle;
  1351.     }
  1352.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1353.     return $this->render('Nordinfo/Main/agenda.html.twig'$this->params);
  1354.   }
  1355.   #[Route(path'/infolettre'name'infolettre')]
  1356.   public function infolettre(Request $request): Response
  1357.   {
  1358.     $this->params['referer'] = $request->headers->get('referer');
  1359.     $this->params['breadcrumb'] = $this->setBreadCrumb(null"Infolettre");
  1360.     //epingle
  1361.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1362.     return $this->render('Nordinfo/Main/infolettre.html.twig'$this->params);
  1363.   }
  1364.   #[Route(path'/videos'name'videos')]
  1365.   public function videos(Request $request): Response
  1366.   {
  1367.     $this->params['referer'] = $request->headers->get('referer');
  1368.     $this->params['list_type'] = 'videos';
  1369.     $this->params['title'] = 'Vidéos';
  1370.     $this->params['tagbar'] = false;
  1371.     $this->params['show_date_bar'] = 1;
  1372.     $posts_types = [4679];
  1373.     $public $this->getPublic();
  1374.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1375.       $posts_types,
  1376.       null,
  1377.       'videos',
  1378.       null,
  1379.       null,
  1380.       false,
  1381.       'DESC',
  1382.       $this->params['initial_limit'],
  1383.       0,
  1384.       false,
  1385.       null,
  1386.       null,
  1387.       false,
  1388.       $public
  1389.     );
  1390.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1391.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1392.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1393.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1394.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1395.       $posts_types,
  1396.       null,
  1397.       'videos',
  1398.       null,
  1399.       null,
  1400.       false,
  1401.       'DESC',
  1402.       null,
  1403.       0,
  1404.       true,
  1405.       null,
  1406.       null,
  1407.       false,
  1408.       $public
  1409.     );
  1410.     $this->params['show_nav'] = 'true';
  1411.     $this->params['text_plus_button'] = 'PLUS DE VIDEOS';
  1412.     //epingle
  1413.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1414.     $epingles_ $this->epingle_service->getEpinglesSection('videos');
  1415.     foreach ($epingles_ as $epingle) {
  1416.       array_push($this->params['epingles'], $epingle);
  1417.     }
  1418.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1419.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1420.   }
  1421.   #[Route(path'/podcasts'name'podcasts')]
  1422.   public function podcasts(Request $request): Response
  1423.   {
  1424.     $this->params['referer'] = $request->headers->get('referer');
  1425.     $this->params['list_type'] = 'podcasts';
  1426.     $this->params['title'] = 'Podcasts';
  1427.     $this->params['tagbar'] = false;
  1428.     $this->params['show_date_bar'] = 1;
  1429.     $posts_types = [10];
  1430.     $public $this->getPublic();
  1431.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1432.       $posts_types,
  1433.       null,
  1434.       'podcasts',
  1435.       null,
  1436.       null,
  1437.       false,
  1438.       'DESC',
  1439.       $this->params['initial_limit'],
  1440.       0,
  1441.       false,
  1442.       null,
  1443.       null,
  1444.       false,
  1445.       $public
  1446.     );
  1447.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1448.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1449.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1450.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1451.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1452.       $posts_types,
  1453.       null,
  1454.       'podcasts',
  1455.       null,
  1456.       null,
  1457.       false,
  1458.       'DESC',
  1459.       null,
  1460.       0,
  1461.       true,
  1462.       null,
  1463.       null,
  1464.       false,
  1465.       $public
  1466.     );
  1467.     $this->params['show_nav'] = 'true';
  1468.     $this->params['text_plus_button'] = 'PLUS DE PODCASTS';
  1469.     //epingle
  1470.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1471.     $epingles_ $this->epingle_service->getEpinglesSection('videos');
  1472.     foreach ($epingles_ as $epingle) {
  1473.       $this->params['epingles'][] = $epingle;
  1474.     }
  1475.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1476.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1477.   }
  1478.   #[Route(path'/dossiers'name'dossiers')]
  1479.   public function dossiers(Request $request): Response
  1480.   {
  1481.     $this->params['referer'] = $request->headers->get('referer');
  1482.     $this->params['list_type'] = 'dossiers';
  1483.     $this->params['title'] = 'Dossiers';
  1484.     $this->params['tagbar'] = false;
  1485.     $this->params['show_date_bar'] = 1;
  1486.     $posts_types = [2];
  1487.     $public $this->getPublic();
  1488.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1489.       $posts_types,
  1490.       null,
  1491.       'dossiers',
  1492.       null,
  1493.       null,
  1494.       false,
  1495.       'DESC',
  1496.       $this->params['initial_limit'],
  1497.       0,
  1498.       false,
  1499.       null,
  1500.       null,
  1501.       false,
  1502.       $public
  1503.     );
  1504.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1505.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1506.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1507.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1508.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1509.       $posts_types,
  1510.       null,
  1511.       'dossiers',
  1512.       null,
  1513.       null,
  1514.       false,
  1515.       'DESC',
  1516.       null,
  1517.       0,
  1518.       true,
  1519.       null,
  1520.       null,
  1521.       false,
  1522.       $public
  1523.     );
  1524.     $this->params['show_nav'] = 'true';
  1525.     $this->params['text_plus_button'] = 'PLUS DE DOSSIERS';
  1526.     //epingle
  1527.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1528.     $epingles_ $this->epingle_service->getEpinglesSection('videos');
  1529.     foreach ($epingles_ as $epingle) {
  1530.       $this->params['epingles'][] = $epingle;
  1531.     }
  1532.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1533.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1534.   }
  1535.   #[Route(path'/video-{slug}'name'video_detail')]
  1536.   public function video_detail_post(Request $requeststring $slug): Response
  1537.   {
  1538.     return $this->detail_post($request$slug);
  1539.   }
  1540.   private function cmp($a$b)
  1541.   {
  1542.     return strcmp((string)$a->getOrderFolder(), (string)$b->getOrderFolder());
  1543.   }
  1544.   protected function isFavoritev2($post_id$user$request): bool
  1545.   {
  1546.     $favorite false;
  1547.     $user $this->getUser();
  1548.     if ($user !== null) {
  1549.       foreach ($user->getFavoris() as $favori) {
  1550.         if ($post_id == $favori->getId()) {
  1551.           $favorite true;
  1552.           break;
  1553.         }
  1554.       }
  1555.     } else {
  1556.       if ($request->cookies->get('favorite') != null) {
  1557.         if (in_array($post_idexplode(',', (string)$request->cookies->get('favorite'))) == true) {
  1558.           $favorite true;
  1559.         }
  1560.       }
  1561.     }
  1562.     return $favorite;
  1563.   }
  1564.   protected function isFavorite(mixed $postmixed $userRequest $request): bool
  1565.   {
  1566.     $favorite false;
  1567.     $user $this->getUser();
  1568.     if ($user !== null) {
  1569.       foreach ($user->getFavoris() as $favori) {
  1570.         if ($post->getId() == $favori->getId()) {
  1571.           $favorite true;
  1572.           break;
  1573.         }
  1574.       }
  1575.     } else {
  1576.       if ($request->cookies->get('favorite') != null) {
  1577.         if (in_array($post->getId(), explode(',', (string)$request->cookies->get('favorite'))) == true) {
  1578.           $favorite true;
  1579.         }
  1580.       }
  1581.     }
  1582.     return $favorite;
  1583.   }
  1584.   protected function getRelatedPosts(mixed $post): array
  1585.   {
  1586.     $number 0;
  1587.     $relateds = [];
  1588.     $relatedPost1 $post->getRelatedPost1();
  1589.     if ($relatedPost1 === null) {
  1590.       $number 1;
  1591.     } else if ($relatedPost1->getStatus()->getId() === 5) {
  1592.       $relateds[] = $post->getRelatedPost1();
  1593.     }
  1594.     $relatedPost2 $post->getRelatedPost2();
  1595.     if ($relatedPost2 === null) {
  1596.       $number 2;
  1597.     } else if ($relatedPost2->getStatus()->getId() === 5) {
  1598.       $relateds[] = $post->getRelatedPost2();
  1599.     }
  1600.     $relatedPost3 $post->getRelatedPost3();
  1601.     if ($relatedPost3 === null) {
  1602.       $number 3;
  1603.     } else if ($relatedPost3->getStatus()->getId() === 5) {
  1604.       $relateds[] = $post->getRelatedPost3();
  1605.     }
  1606.     $type_id $post->getType()->getId();
  1607.     $topics_id = [];
  1608.     foreach ($post->getTopics() as $topic) {
  1609.       $topics_id[] = $topic->getId();
  1610.     }
  1611.     $territories_id = [];
  1612.     foreach ($post->getTerritories() as $territory) {
  1613.       $territories_id[] = $territory->getId();
  1614.     }
  1615.     $posts $this->em->getRepository(Post::class)->getRelatedPost($number$type_id$topics_id$territories_id$post->getId());
  1616.     foreach ($posts as $p) {
  1617.       if (count($relateds) === 4) {
  1618.         break;
  1619.       }
  1620.       if ($p->getSlug() !== null) {
  1621.         $relateds[] = $p;
  1622.       }
  1623.     }
  1624.     return $relateds;
  1625.   }
  1626.   protected function setBreadCrumb(mixed $post nullmixed $page_title nullmixed $departement falsemixed $liste null): mixed
  1627.   {
  1628.     $breadcrumb = [];
  1629.     array_push($breadcrumb, ['alias' => $this->generateUrl('index'), 'titre' => 'Accueil']);
  1630.     if ($post != null) {
  1631.       switch ($post->getType()->getType()) {
  1632.         case 'article':
  1633.         case 'sondage':
  1634.         case 'folder':
  1635.         case 'pub':
  1636.           array_push($breadcrumb, ['alias' => $this->generateUrl('info'), 'titre' => "L'info"]);
  1637.           break;
  1638.         case 'event':
  1639.           array_push($breadcrumb, ['alias' => $this->generateUrl('agenda'), 'titre' => "Agenda"]);
  1640.           break;
  1641.         case 'video':
  1642.           array_push($breadcrumb, ['alias' => $this->generateUrl('videos'), 'titre' => "Vidéos"]);
  1643.           break;
  1644.         case 'socialpost':
  1645.           array_push($breadcrumb, ['alias' => $this->generateUrl('direct'), 'titre' => 'En direct']);
  1646.           break;
  1647.       }
  1648.       array_push($breadcrumb, ['alias' => '''titre' => $post->getTitle()]);
  1649.     }
  1650.     if ($page_title != null && $departement == false) {
  1651.       array_push($breadcrumb, ['alias' => '''titre' => $page_title]);
  1652.     } else if ($page_title != null && $departement == true && $liste == null) {
  1653.       array_push($breadcrumb, ['alias' => $this->generateUrl('departement'), 'titre' => 'le Département']);
  1654.       array_push($breadcrumb, ['alias' => '''titre' => $page_title]);
  1655.     } else if ($page_title != null && $departement == true && $liste != null) {
  1656.       array_push($breadcrumb, ['alias' => $this->generateUrl('departement'), 'titre' => 'le Département']);
  1657.       if ($liste == 'elus') {
  1658.         array_push($breadcrumb, ['alias' => $this->generateUrl('contacts'), 'titre' => 'contacts et élus']);
  1659.       } else {
  1660.         array_push($breadcrumb, ['alias' => $this->generateUrl(
  1661.           'organisations',
  1662.           ['type' => $liste]
  1663.         ), 'titre' => $liste]);
  1664.       }
  1665.       array_push($breadcrumb, ['alias' => '''titre' => $page_title]);
  1666.     }
  1667.     return $breadcrumb;
  1668.   }
  1669.   protected function getTerritories(Request $request): mixed
  1670.   {
  1671.     $cookie_territories = [];
  1672.     $territories = [];
  1673.     $user $this->getUser();
  1674.     if ($user !== null) {
  1675.       foreach ($user->getTerritoires() as $territoire) {
  1676.         $territories[] = (int)$territoire->getId();
  1677.       }
  1678.     } else {
  1679.       if ($request->cookies->get('territories') != null) {
  1680.         $territories explode(','$request->cookies->get('territories'));
  1681.       }
  1682.     }
  1683.     foreach ($territories as $territory_id) {
  1684.       $terr $this->em->getRepository(Territory::class)->find($territory_id);
  1685.       $cookie_territories[] = $terr?->getDisplayName();
  1686.     }
  1687.     return $cookie_territories;
  1688.   }
  1689.   protected function getTerritoryIds(Request $request): mixed
  1690.   {
  1691.     $territories = [];
  1692.     $user $this->getUser();
  1693.     if ($user !== null) {
  1694.       foreach ($user->getTerritoires() as $territoire) {
  1695.         $territories[] = (int)$territoire->getId();
  1696.       }
  1697.     } else {
  1698.       if ($request->cookies->get('territories') != null) {
  1699.         $territories explode(','$request->cookies->get('territories'));
  1700.       }
  1701.     }
  1702.     return $territories;
  1703.   }
  1704.   protected function getTopics(Request $request): mixed
  1705.   {
  1706.     $cookie_topics = [];
  1707.     $topics = [];
  1708.     $user $this->getUser();
  1709.     if ($user !== null) {
  1710.       foreach ($user->getThematiques() as $topic) {
  1711.         $topics[] = (int)$topic->getId();
  1712.       }
  1713.     } else {
  1714.       if ($request->cookies->get('topics') != null) {
  1715.         $topics explode(','$request->cookies->get('topics'));
  1716.       }
  1717.     }
  1718.     foreach ($topics as $topic_id) {
  1719.       $terr $this->em->getRepository(Topic::class)->find($topic_id);
  1720.       $cookie_topics[] = ($terr != null) ? $terr->getDisplayName() : 'error';
  1721.     }
  1722.     return $cookie_topics;
  1723.   }
  1724.   protected function getTopicIds(Request $request): mixed
  1725.   {
  1726.     $topics = [];
  1727.     $user $this->getUser();
  1728.     if ($user !== null) {
  1729.       foreach ($user->getThematiques() as $topic) {
  1730.         $topics[] = (int)$topic->getId();
  1731.       }
  1732.     } else {
  1733.       if ($request->cookies->get('topics') != null) {
  1734.         $topics explode(','$request->cookies->get('topics'));
  1735.       }
  1736.     }
  1737.     return $topics;
  1738.   }
  1739.   #[Route(path'/contact/{slug}'name'contact_detail')]
  1740.   public function detail_contact(Request $requeststring $slug): Response
  1741.   {
  1742.     $contact $this->em->getRepository(Contact::class)->getContact_($slug);
  1743.     $this->params['contact'] = $contact;
  1744.     $posts = [];
  1745.     $count_post 0;
  1746.     foreach ($contact->getPosts1() as $pp) {
  1747.       if ($count_post >= 3) {
  1748.         break;
  1749.       }
  1750.       $posts[] = $pp;
  1751.       $count_post++;
  1752.     }
  1753.     if ($count_post 3) {
  1754.       foreach ($contact->getPosts2() as $pp) {
  1755.         if ($count_post >= 3) {
  1756.           break;
  1757.         }
  1758.         $posts[] = $pp;
  1759.         $count_post++;
  1760.       }
  1761.     }
  1762.     if ($count_post 3) {
  1763.       foreach ($contact->getPosts3() as $pp) {
  1764.         if ($count_post >= 3) {
  1765.           break;
  1766.         }
  1767.         $posts[] = $pp;
  1768.         $count_post++;
  1769.       }
  1770.     }
  1771.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$contact->getFirstName() . ' ' $contact->getLastName(), true'elus');
  1772.     $this->params['contact_posts'] = $posts;
  1773.     $this->params['referer'] = $request->headers->get('referer');
  1774.     $this->params['caps'] = $this->getCaptcha();
  1775.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1776.     if ($request->get('function') == 'download_pdf') {
  1777.       $this->params['is_pdf'] = 1;
  1778.       $pdfOptions = new Options();
  1779.       $pdfOptions->set('defaultFont''Arial');
  1780.       $pdfOptions->setIsRemoteEnabled(true);
  1781.       $dompdf = new Dompdf($pdfOptions);
  1782.       $html $this->renderView('Nordinfo/Main/detail_contact.html.twig'$this->params);
  1783.       $dompdf->loadHtml($html);
  1784.       $dompdf->setPaper('A4''portrait');
  1785.       $dompdf->render();
  1786.       $output $dompdf->output();
  1787.       $filename sprintf('nord-info-%s.pdf'$contact->getFirstName());
  1788.       return new Response(
  1789.         $output,
  1790.         200,
  1791.         [
  1792.           'Content-Type' => 'application/pdf',
  1793.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  1794.         ]
  1795.       );
  1796.     } else {
  1797.       return $this->render('Nordinfo/Main/detail_contact.html.twig'$this->params);
  1798.     }
  1799.   }
  1800.   #[Route(path'/organisation/{id}'name'organisation_detail')]
  1801.   public function detail_organisation(Request $requestmixed $id): mixed
  1802.   {
  1803.     $organisation $this->em->getRepository(Organization::class)->getOrganisation($id);
  1804.     $this->params['organisation'] = $organisation;
  1805.     $this->params['referer'] = $request->headers->get('referer');
  1806.     $type null;
  1807.     $type_id $organisation->getTypeOrganisation()->getId();
  1808.     /*switch ($type_id) {
  1809.       case 1:
  1810.         $type = 'colleges';
  1811.         break;
  1812.       case 2:
  1813.         $type = 'secteur-social';
  1814.         break;
  1815.       case 3:
  1816.       case 4:
  1817.         $type = 'espaces-naturels-sensibles';
  1818.         break;
  1819.     }*/
  1820.     $type $organisation->getTypeOrganisation()->getName();
  1821.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$organisation->getTitle(), true$type);
  1822.     $related_posts = [];
  1823.     $ids_done = [];
  1824.     foreach ($organisation->getPosts1() as $post) {
  1825.       if (($post->getStatus()->getId() === 5) && !in_array($post->getId(), $ids_donetrue)) {
  1826.         $related_posts[] = $post;
  1827.         $ids_done[] = $post->getId();
  1828.       }
  1829.     }
  1830.     foreach ($organisation->getPosts2() as $post) {
  1831.       if (($post->getStatus()->getId() === 5) && !in_array($post->getId(), $ids_donetrue)) {
  1832.         $related_posts[] = $post;
  1833.         $ids_done[] = $post->getId();
  1834.       }
  1835.     }
  1836.     foreach ($organisation->getPosts3() as $post) {
  1837.       if (($post->getStatus()->getId() === 5) && !in_array($post->getId(), $ids_donetrue)) {
  1838.         $related_posts[] = $post;
  1839.         $ids_done[] = $post->getId();
  1840.       }
  1841.     }
  1842.     $this->params['related_posts'] = $related_posts;
  1843.     $this->params['caps'] = $this->getCaptcha();
  1844.     //epingle
  1845.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1846.     return $this->render('Nordinfo/Main/detail_organisation.html.twig'$this->params);
  1847.   }
  1848.   #[Route(path'/le-departement/{slug}'name'page')]
  1849.   public function page(Request $requeststring $slug): Response
  1850.   {
  1851.     $this->params['referer'] = $request->headers->get('referer');
  1852.     $post $this->em->getRepository(Pages::class)->findOneBy(['alias_url' => $slug'actif' => 1'nordinfo' => 1]);
  1853.     if (!$post) {
  1854.         throw $this->createNotFoundException('La page demandée n\'existe pas.');
  1855.     }
  1856.     $this->params['post'] = $post;
  1857.     $content_post null;
  1858.     if ($this->params['post']->getContent() != null) {
  1859.       $content_post $this->feedUtilities->jsonToHtml($this->params['post']->getContent(), $request$this->params['post']->getTitre());
  1860.     }
  1861.     $this->params['content_post'] = $content_post;
  1862.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$this->params['post']->getTitre(), true);
  1863.     //epingle
  1864.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1865.     return $this->render('Nordinfo/Main/detail_page.html.twig'$this->params);
  1866.   }
  1867.   #[Route(path'/post-testing/{id}'name'post_testing')]
  1868.   public function postTesting(Request $requestmixed $id): Response
  1869.   {
  1870.     $post $this->em
  1871.       ->getRepository(Post::class)
  1872.       ->find($id);
  1873.     $contentJson $post->getContent();
  1874.     $html $this->feedUtilities->jsonToHtml($contentJson$request);
  1875.     return $this->render('Nordinfo/Main/demo-post.html.twig', ['page_content' => $html]);
  1876.   }
  1877.   #[Route(path'/elements'name'elements')]
  1878.   public function elements(): Response
  1879.   {
  1880.     return $this->render('Nordinfo/Main/elements.html.twig'$this->params);
  1881.   }
  1882.   #[Route(path'/thematiques'name'topics')]
  1883.   public function topics(Request $request): Response
  1884.   {
  1885.     $this->params['referer'] = $request->headers->get('referer');
  1886.     $this->params['topics'] = $this->em->getRepository(Topic::class)->getAll();
  1887.     $checkTopics = [];
  1888.     if ($this->getUser() != null) {
  1889.       foreach ($this->getUser()->getThematiques() as $topic) {
  1890.         $checkTopics[] = $topic->getId();
  1891.       }
  1892.     } else if ($request->cookies->get('topics') != null) {
  1893.       $checkTopics explode(','$request->cookies->get('topics'));
  1894.     }
  1895.     $this->params['checkTopics'] = $checkTopics;
  1896.     $this->params['show_nav'] = 'false';
  1897.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'vos thématiques');
  1898.     //epingle
  1899.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1900.     return $this->render('Nordinfo/Main/topics.html.twig'$this->params);
  1901.   }
  1902.   #[Route(path'/vos-lieux'name'vos_lieux')]
  1903.   public function vos_lieux(Request $request): Response
  1904.   {
  1905.     $this->params['referer'] = $request->headers->get('referer');
  1906.     $checkTerritories = [];
  1907.     if ($this->getUser() != null) {
  1908.       foreach ($this->getUser()->getTerritoires() as $territoire) {
  1909.         $checkTerritories[] = $territoire->getId();
  1910.       }
  1911.     } else if ($request->cookies->get('territories') != null) {
  1912.       $checkTerritories explode(','$request->cookies->get('territories'));
  1913.     }
  1914.     $territories $this->em->getRepository(Territory::class)->getListeTerritories();
  1915.     $this->params['territories'] = $territories;
  1916.     $this->params['checkTerritories'] = $checkTerritories;
  1917.     $this->params['show_nav'] = 'false';
  1918.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'Vos lieux de vie');
  1919.     //epingle
  1920.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1921.     return $this->render('Nordinfo/Main/vos_lieux.html.twig'$this->params);
  1922.   }
  1923.   #[Route(path'/mon-compte'name'mon_compte')]
  1924.   public function monCompte(Request $request)
  1925.   {
  1926.     if ($this->getUser() == null) {
  1927.       return $this->redirect('login');
  1928.     }
  1929.     $this->params['referer'] = $request->headers->get('referer');
  1930.     $this->params['show_nav'] = 'false';
  1931.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'Mon Compte');
  1932.     $this->params['cookie_territories'] = $this->getTerritories($request);
  1933.     $this->params['cookie_topics'] = $this->getTopics($request);
  1934.     $this->params['posts_favoris'] = $this->getFavoris($request);
  1935.     $this->params['items_total_favoris'] = sizeof($this->params['posts_favoris']);
  1936.     //epingle
  1937.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1938.     return $this->render('Nordinfo/Main/profile.html.twig'$this->params);
  1939.   }
  1940.   private function getCaptcha(): mixed
  1941.   {
  1942.     $captchaCh = [012345678910];
  1943.     $captchaLe = ["zéro""un""deux""trois""quatre""cinq""six""sept""huit""neuf""dix"];
  1944.     $testcap array_merge($captchaCh$captchaLe);
  1945.     $rnd array_rand($testcap2);
  1946.     $i1 $rnd[0];
  1947.     if ($rnd[0] >= 11) {
  1948.       $i1 $rnd[0] - 11;
  1949.     }
  1950.     $i2 $rnd[1];
  1951.     if ($rnd[1] >= 11) {
  1952.       $i2 $rnd[1] - 11;
  1953.     }
  1954.     $capp = ["valeur1" => ["libelle" => $testcap[$rnd[0]], "valeur" => $captchaCh[$i1]], "valeur2" => ["libelle" => $testcap[$rnd[1]], "valeur" => $captchaCh[$i2]]];
  1955.     return $capp;
  1956.   }
  1957.   #[Route(path'/proposer-un-evenement'name'proposer_event')]
  1958.   public function proposerEvent(Request $request): Response
  1959.   {
  1960.     $this->params['referer'] = $request->headers->get('referer');
  1961.     $this->params['types'] = $this->em->getRepository(EventType::class)->findAll();
  1962.     $communes $this->em->getRepository(Cantons::class)->getCommunes();
  1963.     $villes = [];
  1964.     foreach ($communes as $cc) {
  1965.       $villes array_merge(array_map('trim'explode(',', (string)$cc['communes'])), $villes);
  1966.     }
  1967.     asort($villes);
  1968.     $this->params['villes'] = $villes;
  1969.     $this->params['caps'] = $this->getCaptcha();
  1970.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1971.     return $this->render('Nordinfo/Main/proposerevent.html.twig'$this->params);
  1972.   }
  1973.   #[Route(path'/support'name'signaler')]
  1974.   public function signaler(Request $request): Response
  1975.   {
  1976.     $this->params['referer'] = $request->headers->get('referer');
  1977.     $this->params['types_support'] = $this->em->getRepository(TypeSupport::class)->findAll();
  1978.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'contact');
  1979.     $this->params['objet'] = null;
  1980.     if ($request->query->get('objet') != null) {
  1981.       $this->params['objet'] = 4;
  1982.     }
  1983.     $this->params['caps'] = $this->getCaptcha();
  1984.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1985.     $this->params['thematiques'] = $this->em->getRepository(FormulaireThematique::class)->findBy(['bool_info' => 1], ['name' => 'ASC']);
  1986.     return $this->render('Nordinfo/Main/signaler.html.twig'$this->params);
  1987.   }
  1988.   #[Route(path'/organisations/{type}'name'search_organisation')]
  1989.   public function searchorganisations(Request $request$type): Response
  1990.   {
  1991.     return $this->organisations($request$type);
  1992.   }
  1993.   #[Route(path'/search-organisations/{type}'name'organisations')]
  1994.   public function organisations(Request $request$type): Response
  1995.   {
  1996.     $this->params['type_'] = $type;
  1997.     $to $this->em->getRepository(TypeOrganisation::class)->findOneByName($type);
  1998.     $this->params['title'] = $to->getTitreListe();
  1999.     $id_type $to->getId();
  2000.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'liste des organisations'true);
  2001.     $this->params['referer'] = $request->headers->get('referer');
  2002.     $filter_title null;
  2003.     $search $request->query->get('search');
  2004.     $search_id null;
  2005.     $this->params['is_search'] = 0;
  2006.     $uri_path parse_url($request->getUri(), PHP_URL_PATH);
  2007.     $uri_segments explode('/'$uri_path);
  2008.     $uri_segment_filter urldecode($uri_segments[2]);
  2009.     if ($request->query->get('territoire_id') != "") {
  2010.       $search null;
  2011.       $search_id $request->query->get('territoire_id');
  2012.       $territory $this->em->getRepository(Territory::class)->find($request->query->get('territoire_id'));
  2013.       $filter_title 'Résultats pour ' $territory->getDisplayName();
  2014.       $this->params['is_search'] = 1;
  2015.     } else if ($uri_segment_filter != '') {
  2016.       $search_id null;
  2017.       $filter_title ' résultats pour "' $uri_segment_filter '"';
  2018.       $this->params['is_search'] = 1;
  2019.     }
  2020.     $this->params['contacts'] = $this->em->getRepository(Organization::class)->getOrganisations_($id_type$search$search_id);
  2021.     $this->params['territoires'] = $this->em->getRepository(Territory::class)->findAll();
  2022.     $this->params['filter_title'] = ($filter_title != null) ? (is_countable($this->params['contacts']) ? count($this->params['contacts']) : 0) . $filter_title null;
  2023.     //epingle
  2024.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2025.     return $this->render('Nordinfo/Main/organisations.html.twig'$this->params);
  2026.   }
  2027.   #[Route(path'/search-contacts'name'search_contact')]
  2028.   public function search_contacts(Request $request): Response
  2029.   {
  2030.     return $this->contacts($request);
  2031.   }
  2032.   #[Route(path'/contacts'name'contacts')]
  2033.   public function contacts(Request $request): Response
  2034.   {
  2035.     $this->params['referer'] = $request->headers->get('referer');
  2036.     $this->params['cantons'] = $this->em->getRepository(Cantons::class)->findAll();
  2037.     $search null;
  2038.     $search_id null;
  2039.     $filter_title null;
  2040.     $this->params['is_search'] = 0;
  2041.     if ($request->query->get('canton_id') != "") {
  2042.       $search null;
  2043.       $search_id $request->query->get('canton_id');
  2044.       $this->params['is_search'] = 1;
  2045.       $canton $this->em->getRepository(Cantons::class)->find($request->query->get('canton_id'));
  2046.       $filter_title ' résultats pour "' $canton->getCanton() . '"';
  2047.     } else if ($request->query->get('search') != "") {
  2048.       $search $request->query->get("search");
  2049.       $search_id null;
  2050.       $this->params['is_search'] = 1;
  2051.       $filter_title ' résultats pour "' $search '"';
  2052.     }
  2053.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'contacts et élus'true);
  2054.     $this->params['contacts'] = $this->em->getRepository(Contact::class)->getContacts_(1$search$search_id);
  2055.     $this->params['filter_title'] = ($filter_title != null) ? (is_countable($this->params['contacts']) ? count($this->params['contacts']) : 0) . $filter_title null;
  2056.     //epingle
  2057.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2058.     return $this->render('Nordinfo/Main/contacts.html.twig'$this->params);
  2059.   }
  2060.   #[Route(path'/apercu-feedback'name'feedback')]
  2061.   public function feedback(Request $request): Response
  2062.   {
  2063.     $this->params['referer'] = $request->headers->get('referer');
  2064.     return $this->render('Nordinfo/Main/feedback.html.twig'$this->params);
  2065.   }
  2066.   #[Route(path'/inviter-a-commenter/{id}'name'invite_comment_post')]
  2067.   public function inviteToComment(mixed $id): Response
  2068.   {
  2069.     $this->params['post'] = $this->em->getRepository(Post::class)->find($id);
  2070.     $this->params['id'] = $id;
  2071.     $this->params['users_agent'] = $this->em->getRepository(User::class)->getUsersComment();
  2072.     return $this->render('Admin/comment_invite.html.twig'$this->params);
  2073.   }
  2074.   #[Route(path'/send-invite-comment/{id}'name'send_invitation_comment')]
  2075.   public function sendInviteToComment(Request $request$id): RedirectResponse
  2076.   {
  2077.     $user $this->getUser();
  2078.     $post $request->request;
  2079.     //Mail
  2080.     $date date_create_from_format('d/m/Y'$post->get('date'));
  2081.     //Interne
  2082.     if ($post->get('emails_interne') != null && !empty($post->get('emails_interne'))) {
  2083.       foreach ((array)$post->get('emails_interne') as $user_id) {
  2084.         $user $this->em->getRepository(User::class)->find($user_id);
  2085.         $destinataire = [];
  2086.         array_push($destinataire, ['email' => $user->getEmail(), 'name' => $user->getEmail()]);
  2087.         //Envoi email
  2088.         $article $this->em->getRepository(Post::class)->find($id);
  2089.         $token base64_encode(random_bytes(60));
  2090.         $token str_replace(["+""/"], '_'$token);
  2091.         $doit_valider $post->get('doit_valider');
  2092.         $com = new PostCommentaires;
  2093.         $com
  2094.           ->setPost($article)
  2095.           ->setDate($date)
  2096.           ->setAuteur($user->getEmail())
  2097.           ->setToken($token)
  2098.           ->setDoitValider(($doit_valider != null) ? $doit_valider false)
  2099.           ->setValide(false);
  2100.         $this->em->persist($com);
  2101.         //date url titre 
  2102.         $url $this->generateUrl('comment_post', ['token' => $token]);
  2103.         $content_mail $this->renderView(
  2104.           'Nordinfo/Mails/commentaire_invite.html.twig',
  2105.           ['texte_email' => $post->get('texte_email'), 'image' => $article->getIllustrationfilName(), 'titre' => $article->getTitle(), 'date' => $date'url' => 'https://' $request->getHost() . $url]
  2106.         );
  2107.         $this->sendgrid_service->send([$user->getEmail()], $content_mail"Nordinfo : Invitation à commenter");
  2108.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Nordinfo : Invitation à commenter');
  2109.       }
  2110.     }
  2111.     //Externe
  2112.     if ($post->get('emails') != null) {
  2113.       $dests explode(';'$post->get('emails'));
  2114.       foreach ($dests as $str) {
  2115.         $destinataire = [];
  2116.         array_push($destinataire, ['email' => $str'name' => $str]);
  2117.         //Envoi email
  2118.         $article $this->em->getRepository(Post::class)->find($id);
  2119.         $token base64_encode(random_bytes(60));
  2120.         $token str_replace(["+""/"], '_'$token);
  2121.         $doit_valider $post->get('doit_valider');
  2122.         $com = new PostCommentaires;
  2123.         $com
  2124.           ->setPost($article)
  2125.           ->setDate($date)
  2126.           ->setAuteur($str)
  2127.           ->setToken($token)
  2128.           ->setDoitValider(($doit_valider != null) ? $doit_valider false)
  2129.           ->setValide(false);
  2130.         $this->em->persist($com);
  2131.         //date url titre 
  2132.         $url $this->generateUrl('comment_post', ['token' => $token]);
  2133.         $content_mail $this->renderView(
  2134.           'Nordinfo/Mails/commentaire_invite.html.twig',
  2135.           ['texte_email' => $post->get('texte_email'), 'image' => $article->getIllustrationfilName(), 'titre' => $article->getTitle(), 'date' => $date'url' => 'https://' $request->getHost() . $url]
  2136.         );
  2137.         $this->sendgrid_service->send([$str], $content_mail"Nordinfo : Invitation à commenter");
  2138.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Nordinfo : Invitation à commenter');
  2139.       }
  2140.     }
  2141.     $this->em->flush();
  2142.     $url '/console2020/?entity=Article&action=list';
  2143.     return $this->redirect($url);
  2144.   }
  2145.   public function importXls(): void
  2146.   {
  2147.     $path $this->get('kernel')->getRootDir() . '/../';
  2148.     $file $path 'mdie.xls';
  2149.     $fileType IOFactory::identify($file);
  2150.     $l 0;
  2151.     $reader IOFactory::createReader($fileType);
  2152.     $spreadsheet $reader->load($file);
  2153.     $datas $spreadsheet->getSheet(0)->toArray(nulltruetruetrue);
  2154.     foreach ($datas as $d) {
  2155.       $l++;
  2156.       if ($l 1) {
  2157.         if ($d['C'] == "") {
  2158.           break;
  2159.         }
  2160.         $type $this->em->getRepository(TypeOrganisation::class)->find(6);
  2161.         $territory $this->em->getRepository(Territory::class)->find($d['K']);
  2162.         $organisation = new Organization;
  2163.         $organisation->setTitle($d['C'])
  2164.           ->setSubtitle($d['D'])
  2165.           ->setEmail($d['M'])
  2166.           ->setPhone($d['N'])
  2167.           ->setAcceo($d['O'])
  2168.           ->setCodePostal($d['J'])
  2169.           ->setRue($d['H'])
  2170.           ->setVille($d['I'])
  2171.           ->setTypeOrganisation($type)
  2172.           ->setTerritory($territory);
  2173.         $this->em->persist($organisation);
  2174.       }
  2175.       echo $l '\r\n';
  2176.     }
  2177.     $this->em->flush();
  2178.   }
  2179.   /*
  2180.   #[Route(path: '/console2020/ckfinder', name: 'ckfinder')]
  2181.   public function ckfinder(): Response
  2182.   {
  2183.     return $this->render('/Main/ckfinder.html.twig');
  2184.   }
  2185.   */
  2186.   #[Route(path'/ics'name'ics_download')]
  2187.   public function downloadics(Request $request): Response
  2188.   {
  2189.     $post $request->request;
  2190.     $date_start date_create_from_format('d/m/Y'$post->get('date_start'))->setTime(1000);
  2191.     $date_end date_create_from_format('d/m/Y'$post->get('date_end'))->setTime(1800);
  2192.     $ics = new ICS(['location' => $post->get('location'), 'description' => $post->get('description'), 'dtstart' => $date_start'dtend' => $date_end'summary' => $post->get('summary'), 'url' => $post->get('url')]);
  2193.     $filename $post->get('summary') . '.ics';
  2194.     $response = new Response($ics->to_string());
  2195.     $response->headers->set('charset''utf-8');
  2196.     $response->headers->set('Content-Type''text/calendar');
  2197.     $response->headers->set('Content-Disposition''attachment');
  2198.     $response->headers->set('filename'$filename);
  2199.     return $response;
  2200.   }
  2201.   #[Route(path'/sitemap'name'sitemap')]
  2202.   public function sitemap(Request $request): Response
  2203.   {
  2204.     $urls = [];
  2205.     $this->params['page_title'] = "Plan du site";
  2206.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2207.     $this->params['referer'] = $request->headers->get('referer');
  2208.     $urls['index']['parent']['url'] = $this->generateUrl('index');
  2209.     $urls['index']['parent']['name'] = "Accueil";
  2210.     $j 0;
  2211.     $urls['fil']['parent']['url'] = "";
  2212.     $urls['fil']['parent']['name'] = "Actus";
  2213.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('info');
  2214.     $urls['fil']['children'][$j]['name'] = "Mes actus";
  2215.     $j++;
  2216.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('info');
  2217.     $urls['fil']['children'][$j]['name'] = "L'info";
  2218.     $j++;
  2219.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('agenda');
  2220.     $urls['fil']['children'][$j]['name'] = "Agenda";
  2221.     $j++;
  2222.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('videos');
  2223.     $urls['fil']['children'][$j]['name'] = "Vidéos";
  2224.     $urls['custom']['parent']['url'] = "";
  2225.     $urls['custom']['parent']['name'] = "Personnalisation";
  2226.     $j 0;
  2227.     $urls['custom']['children'][$j]['url'] = $this->generateUrl('favoris');;
  2228.     $urls['custom']['children'][$j]['name'] = "Favoris";
  2229.     $j++;
  2230.     $urls['custom']['children'][$j]['url'] = $this->generateUrl('vos_lieux');;
  2231.     $urls['custom']['children'][$j]['name'] = "Mes lieux de vie";
  2232.     $j++;
  2233.     $urls['custom']['children'][$j]['url'] = $this->generateUrl('topics');;
  2234.     $urls['custom']['children'][$j]['name'] = "Mes centres d'intérêt";
  2235.     $urls['departement']['parent']['url'] = $this->generateUrl('departement');
  2236.     $urls['departement']['parent']['name'] = "Le département";
  2237.     $j 0;
  2238.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('page', ['slug' => "le-territoire"]);
  2239.     $urls['departement']['children'][$j]['name'] = "Le territoire";
  2240.     $j++;
  2241.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('page', ['slug' => "les-competences"]);
  2242.     $urls['departement']['children'][$j]['name'] = "Les compétences";
  2243.     $j++;
  2244.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('page', ['slug' => "le-conseil-departemental"]);
  2245.     $urls['departement']['children'][$j]['name'] = "L'institution";
  2246.     $j++;
  2247.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('contacts');
  2248.     $urls['departement']['children'][$j]['name'] = "Les cantons et leurs élus";
  2249.     $j++;
  2250.     $types $this->em->getRepository(TypeOrganisation::class)->findAll();
  2251.     foreach ($types as $type) {
  2252.       $urls['departement']['children'][$j]['url'] = $this->generateUrl('organisations', ['type' => $type->getName()]);
  2253.       $urls['departement']['children'][$j]['name'] = $type->getTitreListe();
  2254.       $j++;
  2255.     }
  2256.     $urls['legal']['parent']['url'] = "";
  2257.     $urls['legal']['parent']['name'] = "Pages légales";
  2258.     $j 0;
  2259.     $urls['legal']['children'][$j]['url'] = $this->generateUrl('post_detail', ['slug' => 'mentions-legales-nordinfo']);
  2260.     $urls['legal']['children'][$j]['name'] = "Mentions légales";
  2261.     $j++;
  2262.     $urls['legal']['children'][$j]['url'] = $this->generateUrl('post_detail', ['slug' => 'cgu']);
  2263.     $urls['legal']['children'][$j]['name'] = "Conditions générales";
  2264.     $j++;
  2265.     $urls['legal']['children'][$j]['url'] = $this->generateUrl('post_detail', ['slug' => 'accessibilite-nordinfo']);
  2266.     $urls['legal']['children'][$j]['name'] = "Accessibilité";
  2267.     $urls['form']['parent']['url'] = "";
  2268.     $urls['form']['parent']['name'] = "Support";
  2269.     $j 0;
  2270.     $urls['form']['children'][$j]['url'] = $this->generateUrl('signaler');;
  2271.     $urls['form']['children'][$j]['name'] = "Contact";
  2272.     $urls['sitemap_page']['parent']['url'] = $this->generateUrl('sitemap');
  2273.     $urls['sitemap_page']['parent']['name'] = 'Plan du site';
  2274.     $this->params['urls'] = $urls;
  2275.     return $this->render('Nordinfo/Main/sitemap.html.twig'$this->params);
  2276.   }
  2277.   #[Route(path'/sitemap.xml'name'nordinfo_plandusite_xml')]
  2278.   public function services_plandusite_xml(): Response
  2279.   {
  2280.     $domain "https://info.lenord.fr";
  2281.     $dom = new \DOMDocument('1.0''UTF-8');
  2282.     $rss $dom->createElement('urlset');
  2283.     $rss->setAttribute('xmlns''http://www.sitemaps.org/schemas/sitemap/0.9');
  2284.     $rss_node $dom->appendChild($rss);
  2285.     $url $dom->createElement('url');
  2286.     $url_node $rss_node->appendChild($url);
  2287.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('index')));
  2288.     $url $dom->createElement('url');
  2289.     $url_node $rss_node->appendChild($url);
  2290.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('info')));
  2291.     $url $dom->createElement('url');
  2292.     $url_node $rss_node->appendChild($url);
  2293.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('info')));
  2294.     $url $dom->createElement('url');
  2295.     $url_node $rss_node->appendChild($url);
  2296.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('agenda')));
  2297.     $url $dom->createElement('url');
  2298.     $url_node $rss_node->appendChild($url);
  2299.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('videos')));
  2300.     $url $dom->createElement('url');
  2301.     $url_node $rss_node->appendChild($url);
  2302.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('favoris')));
  2303.     $url $dom->createElement('url');
  2304.     $url_node $rss_node->appendChild($url);
  2305.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('vos_lieux')));
  2306.     $url $dom->createElement('url');
  2307.     $url_node $rss_node->appendChild($url);
  2308.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('topics')));
  2309.     $url $dom->createElement('url');
  2310.     $url_node $rss_node->appendChild($url);
  2311.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('departement')));
  2312.     $url $dom->createElement('url');
  2313.     $url_node $rss_node->appendChild($url);
  2314.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('page', ['slug' => "le-territoire"])));
  2315.     $url $dom->createElement('url');
  2316.     $url_node $rss_node->appendChild($url);
  2317.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('page', ['slug' => "les-competences"])));
  2318.     $url $dom->createElement('url');
  2319.     $url_node $rss_node->appendChild($url);
  2320.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('page', ['slug' => "le-conseil-departemental"])));
  2321.     $url $dom->createElement('url');
  2322.     $url_node $rss_node->appendChild($url);
  2323.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('contacts')));
  2324.     $types $this->em->getRepository(TypeOrganisation::class)->findAll();
  2325.     foreach ($types as $type) {
  2326.       $url $dom->createElement('url');
  2327.       $url_node $rss_node->appendChild($url);
  2328.       $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('organisations', ['type' => $type->getName()])));
  2329.     }
  2330.     //Posts
  2331.     $posts $this->em->getRepository(Post::class)->findBy(['status' => 5]);
  2332.     $date = new DateTime();
  2333.     foreach ($posts as $post) {
  2334.       if ($post->getSlug() != null) {
  2335.         $date_update date_create_from_format('Y-m-d H:i:s'$post->getDateDernierStatut());
  2336.         $date_update = ($date_update != false) ? $date_update->format('Y-m-d') : $date->format('Y-m-d');
  2337.         $url $dom->createElement('url');
  2338.         $url_node $rss_node->appendChild($url);
  2339.         $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('post_detail', ['slug' => $post->getSlug(), 'archive' => false])));
  2340.         //$url_node->appendChild($dom->createElement('lastmod', $post->getDateUpdate()->format('Y-m-d')));
  2341.         $url_node->appendChild($dom->createElement('changefreq''monthly'));
  2342.         $url_node->appendChild($dom->createElement('lastmod'$date_update));
  2343.       }
  2344.     }
  2345.     $url $dom->createElement('url');
  2346.     $url_node $rss_node->appendChild($url);
  2347.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('post_detail', ['slug' => 'mentions-legales-nordinfo'])));
  2348.     $url $dom->createElement('url');
  2349.     $url_node $rss_node->appendChild($url);
  2350.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('post_detail', ['slug' => 'cgu'])));
  2351.     $url $dom->createElement('url');
  2352.     $url_node $rss_node->appendChild($url);
  2353.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('post_detail', ['slug' => 'accessibilite-nordinfo'])));
  2354.     $url $dom->createElement('url');
  2355.     $url_node $rss_node->appendChild($url);
  2356.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('signaler')));
  2357.     $url $dom->createElement('url');
  2358.     $url_node $rss_node->appendChild($url);
  2359.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('sitemap')));
  2360.     $xml $dom->saveXML();
  2361.     $response = new Response($xml);
  2362.     $response->headers->set('Content-Type''text/xml');
  2363.     $response->headers->set('Access-Control-Allow-Origin''*');
  2364.     return $response;
  2365.   }
  2366.   #[Route(path'/console2021/apercu/{id}'name'apercu_post')]
  2367.   public function apercu_post(Request $requestmixed $id): Response
  2368.   {
  2369.     $this->params['actus'] = false;
  2370.     $this->params['admin'] = true;
  2371.     $this->params['favorite'] = false;
  2372.     $this->params['referer'] = $request->headers->get('referer');
  2373.     $post $this->em->getRepository(Post::class)->findOneBy(['slug' => $id]);
  2374.     $this->params['short_description'] = $post?->getShortDescription();
  2375.     $this->params['is_preview'] = true;
  2376.     $content_post null;
  2377.     if ($post?->getContent() !== null) {
  2378.       $content_post $this->feedUtilities->jsonToHtml($post?->getContent(), $request);
  2379.     }
  2380.     if ($post?->getType()?->getType() === 'folder') {
  2381.       $this->params['related_posts'] = $post?->getRelatedPosts();
  2382.       $this->params['related_posts'] = $this->feedUtilities->social_posts_padding($this->params['related_posts'], $request);
  2383.     } else {
  2384.       $this->params['related_posts'] = $this->getRelatedPosts($post);
  2385.     }
  2386.     $this->params['content_post'] = $content_post;
  2387.     $this->params['post'] = $post;
  2388.     
  2389.     if ($post?->getType()?->getType() === 'folder') {
  2390.       $k 0;
  2391.       foreach ($this->params['related_posts'] as $p) {
  2392.         $this->params['related_posts'][$k]->str_date $this->formatJsonDate($p->getJson());
  2393.         $k++;
  2394.       }
  2395.       return $this->render('Nordinfo/Main/detail_folder.html.twig'$this->params);
  2396.     }
  2397.     $url $post?->getSubtitle();
  2398.     if ($post?->getType()?->getType() === "video") {
  2399.       $this->params['youtube_video_id'] = $url;
  2400.     }
  2401.     if ($post?->getType()?->getType() === "event") {
  2402.       $json_convert_dates $this->formatDateAgendaJson($post?->getJson());
  2403.       $this->params['ics_date_debut'] = $json_convert_dates['ics_date_debut'];
  2404.       $this->params['ics_date_fin'] = $json_convert_dates['ics_date_fin'];
  2405.       $this->params['event_date'] = $json_convert_dates['date_string'];
  2406.       $this->params['event_heures'] = $json_convert_dates['heure_string'];
  2407.       $this->params['event_lieu'] = null;
  2408.       $this->params['event_ville'] = null;
  2409.       $this->params['event_adresse'] = null;
  2410.     }
  2411.     if ($post?->getType()?->getType() === 'pub' || $post?->getType()?->getType() === 'socialpost') {
  2412.       return new Response("Pas d'aperçu possible pour ce type de post");
  2413.     }
  2414.     return $this->render('Nordinfo/Main/detail_post.html.twig'$this->params);
  2415.   }
  2416.   
  2417.   #[Route(path'/send_form_custom/{alias}'name'send_form_custom_info'host"info.lenord.fr")]
  2418.   public function send_form_custom(Request $requeststring $alias): Response
  2419.   {
  2420.     $post $request->request;
  2421.     $custom_form $this->em->getRepository(CustomForm::class)->findOneBy(array('alias' => $alias));
  2422.     $destinataires_sendgrid = [];
  2423.     $objet null;
  2424.     $objet "Votre message à " $custom_form->getDestinataire() . " via le site Nord info";
  2425.     $emails explode(";", (string)$custom_form->getEmail());
  2426.     for ($i 0$i count($emails); $i++) {
  2427.       array_push($destinataires_sendgrid$emails[$i]);
  2428.     }
  2429.     $message $post->get('message');
  2430.     //exp
  2431.     //destinataire_
  2432.     //objet_
  2433.     //message_
  2434.     //piece_jointe_
  2435.     $fileName null;
  2436.     $auth_extension = ['png''jpg''jpeg''gif''pdf'];
  2437.     $mime_authorized = ['application/pdf''image/jpg''image/jpeg''image/gif''image/png'];
  2438.     $file null;
  2439.     $newname uniqid();
  2440.     if ($request->files != null && $request->files->get('file') != null) {
  2441.       $file $request->files->get('file');
  2442.       $fileName $file->getClientOriginalName();
  2443.       $fileType $file->getClientMimeType();
  2444.       if (in_array($file->guessExtension(), $auth_extension) && in_array($fileType$mime_authorized)) {
  2445.         try {
  2446.           /*$file->move($uploadDir, $newname.'.'.$file->guessExtension());
  2447.           array_push($files, array(
  2448.             'name' => $newname.'.'.$file->guessExtension(),
  2449.             'type' => $fileType,
  2450.             'data' => $fileData,
  2451.           ));*/
  2452.         } catch (FileException) {
  2453.           $file null;
  2454.           return new JsonResponse(['error' => 'File could not be uploaded']);
  2455.         }
  2456.       } else {
  2457.         $file null;
  2458.         return new JsonResponse(['error' => "Mauvais format d'image"]);
  2459.       }
  2460.     }
  2461.     $date = new DateTime;
  2462.     $content "Le message suivant vient de vous être envoyé via le site Nord info par " $post->get('nom_prenom') .
  2463.       " - Merci de répondre directement à " $post->get('email') . " : " "\n" $post->get('message') . "\n\n" "Nord, le Département est là - https://info.lenord.fr/";
  2464.     $nom_dest $custom_form->getDestinataire();
  2465.     $content_exp "Bonjour, votre message a été transmis à " $nom_dest "." "\n\n" .
  2466.       "Message : " $post->get('message');
  2467.     if ($fileName !== null) {
  2468.       $content_exp .= "\n" "Pièce jointe : " $fileName;
  2469.     }
  2470.     $content_exp .= "\n\n" "Nord, le Département est là - https://info.lenord.fr/";
  2471.     /*$content_exp = $this->renderView(
  2472.       'Nordinfo/Mails/exp_signalement_custom.html.twig',
  2473.       ['destinataire_' => $nom_dest, 'objet_' => $objet, 'message_' => $message, 'piece_jointe_' => ($fileName != null) ? $fileName : "Aucune pièce jointe", 'date' => "NI".$date->format('dmYHis')]
  2474.     );*/
  2475.     //envoi mail
  2476.     $result_ $post->get('nb1') + $post->get('nb2');
  2477.     if ($result_ == $post->get('captcha') && $post->get('raison') == null) {
  2478.       try {
  2479.         //$this->sendMail($content, 'Demande de contact depuis nordinfo : ' . $objet, $destinataires, $files);
  2480.         //FILES!
  2481.         $this->sendgrid_service->send($destinataires_sendgrid$content"Message envoyé par " $post->get('nom_prenom') . " via le site Nord info"null$filefalse$post->get('email'));
  2482.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataires, $content, 'Demande de contact depuis nordinfo : ' . $objet);
  2483.         $this->sendgrid_service->send([$post->get('email')], $content_exp$objetnull$filefalse);
  2484.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $post->get('email'), $content_exp, "Nord info - Envoi d’un message ");
  2485.       } catch (Exception) {
  2486.         $this->params['message'] = 'Email erreur';
  2487.         return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  2488.       }
  2489.     } else {
  2490.       $this->params['message'] = 'Catcha erreur';
  2491.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  2492.     }
  2493.     return $this->render('Nordinfo/Main/endform.html.twig'$this->params);
  2494.   }
  2495.   #[Route(path'/{slug}'name'post_detail')]
  2496.   public function detail_post(Request $requeststring $slug): Response
  2497.   {
  2498.     if ($request->get('function') === 'download_pdf') {
  2499.       $this->params['is_pdf'] = 1;
  2500.     }
  2501.     $post $this->em->getRepository(Post::class)->findOneBy(['slug' => $slug]);
  2502.     if ($post === null) {
  2503.       return $this->pagelegales($request$slug);
  2504.     }
  2505.     if ($post->getArchive() === true) {
  2506.       return $this->error($request);
  2507.     }
  2508.     $presse false;
  2509.     $vip false;
  2510.     $agent false;
  2511.     $topics_list null;
  2512.     foreach ($post->getTargetpublics() as $topic) {
  2513.       if ($topic->getId() == 3) {
  2514.         $presse true;
  2515.       }
  2516.       if ($topic->getId() == 2) {
  2517.         $vip true;
  2518.       }
  2519.       if ($topic->getId() == 4) {
  2520.         $agent true;
  2521.       }
  2522.       $topics_list .= ($topics_list != null) ? ', ' '';
  2523.       $topics_list .= $topic->getName();
  2524.     }
  2525.     if ($post->getStatus()?->getId() !== 5) {
  2526.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2527.     }
  2528.     if ($post->getType()?->getId() === && $this->getUser() == null) {
  2529.       return $this->redirect($this->generateUrl('info'));
  2530.     }
  2531.     if ($presse && ($this->getUser() == null || $this->getUser()->getRole() != 'presse')) {
  2532.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2533.     }
  2534.     if ($vip && ($this->getUser() == null || $this->getUser()->getRole() != 'vip')) {
  2535.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2536.     }
  2537.     if ($agent && ($this->getUser() == null || $this->getUser()->getRole() != 'agent')) {
  2538.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2539.     }
  2540.     $this->params['referer'] = $request->headers->get('referer');
  2541.     $this->params['post'] = $post;
  2542.     $content_post null;
  2543.     if ($post->getContent() != null) {
  2544.       $content_post $this->feedUtilities->jsonToHtml($post->getContent(), $request$post->getTitle());
  2545.     }
  2546.     $this->params['short_description'] = $post->getSubtitle();
  2547.     $url $post->getSubtitle();
  2548.     if ($post->getType()->getType() === "video") {
  2549.       $this->params['youtube_video_id'] = $url;
  2550.     }
  2551.     $this->params['breadcrumb'] = $this->setBreadCrumb($post);
  2552.     $this->params['content_post'] = $content_post;
  2553.     $this->params['favorite'] = $this->isFavorite($post$this->getUser(), $request);
  2554.     if ($post->getType()?->getType() === 'folder') {
  2555.       $iterator $post->getRelatedPosts()->getIterator();
  2556.       $iterator->uasort(fn ($a$b) => ($a->getOrderFolder() > $b->getOrderFolder()) ? -1);
  2557.       $rarray = [];
  2558.       $array = new ArrayCollection(iterator_to_array($iterator));
  2559.       foreach ($array as $po) {
  2560.         $rarray[] = $po;
  2561.       }
  2562.       $this->params['related_posts'] = $rarray;
  2563.     } else {
  2564.       $this->params['related_posts'] = $this->getRelatedPosts($post);
  2565.     }
  2566.     $this->params['related_posts'] = $this->feedUtilities->checkboxes_get_description($this->params['related_posts'], $request);
  2567.     $this->params['related_posts'] = $this->feedUtilities->social_posts_padding($this->params['related_posts'], $request);
  2568.     $this->params['related_posts'] = $this->feedUtilities->social_posts_detect_links($this->params['related_posts']);
  2569.     $this->params['related_posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['related_posts'], $request);
  2570.     $this->params['openGraph'] = ["url" => "https://info.lenord.fr/" $post->getSlug(), "type" => "article""title" => $post->getTitle(), "image" => "https://info.lenord.fr/upload/images/" $post->getIllustrationFilName(), "description" => $content_post];
  2571.     $this->params['twitter_card'] = ["card" => "summary""site" => "@info.lenord.fr"];
  2572.     $this->params['articleSchema'] = [];
  2573.     $this->params['placement_image'] = 'placement2';
  2574.     if ($post->getType()?->getType() === 'event') {
  2575.       $json_convert_dates $this->formatDateAgendaJson($post->getJson());
  2576.       $this->params['ics_date_debut'] = $json_convert_dates['ics_date_debut'];
  2577.       $this->params['ics_date_fin'] = $json_convert_dates['ics_date_fin'];
  2578.       $this->params['event_date'] = $json_convert_dates['date_string'];
  2579.       $this->params['event_heures'] = $json_convert_dates['heure_string'];
  2580.       $this->params['event_lieu'] = null;
  2581.       $this->params['event_ville'] = null;
  2582.       if ($post->getLieuNew() !== null) {
  2583.         $this->params['event_lieu'] = $post->getLieuNew()->getName();
  2584.         $this->params['event_ville'] = $post->getLieuNew()->getVille();
  2585.       }
  2586.       $this->params['event_adresse'] = null;
  2587.       $date_debut null;
  2588.       $date_fin null;
  2589.       $start_date null;
  2590.       $end_date null;
  2591.       if ($post->getDateDebut() !== null) {
  2592.         $date_debut date_create_from_format('d/m/Y'$post->getDateDebut());
  2593.         $start_date $date_debut->format('c');
  2594.       }
  2595.       if ($post->getDateFin() !== null) {
  2596.         $date_fin date_create_from_format('d/m/Y'$post->getDateFin());
  2597.         $end_date $date_fin->format('c');
  2598.       }
  2599.       $schema_params = [
  2600.         'startDate' => $start_date,
  2601.         'endDate' => $end_date,
  2602.         'inLanguage' => 'FR',
  2603.         'isAccessibleForFree' => ($post->getTarifs() != null) ? true false,
  2604.         'location' => $post->getLieu() . ' ' $post->getVille(),
  2605.         'organizer' => $post->getOrganizedBy(),
  2606.         'name' => $post->getTitle(),
  2607.         'description' => $content_post,
  2608.         'image' => "https:/info.lenord.fr/upload/images/" $post->getIllustrationFilName(),
  2609.         //'sameAs'
  2610.         'url' => "https:/info.lenord.fr/" $post->getSlug(),
  2611.       ];
  2612.       $this->params['articleSchema'] = $this->schema_service->generateSchema($schema_params'Event');
  2613.     } else {
  2614.       $currentRoute $request->attributes->get('_route');
  2615.       $currentUrl $this->generateUrl($currentRoute, ['slug' => $slug], true);
  2616.       $schema_params = ['mainEntityOfPage' => $currentUrl'image' => "https:/info.lenord.fr/upload/images/" $post->getIllustrationDetailName(), 'articleBody' => $content_post'articleSection' => $topics_list'headline' => $post->getTitle(), 'description' => $post->getShortDescription(), 'url' => "https:/info.lenord.fr/" $post->getSlug(), 'thumbnailUrl' => "https:/info.lenord.fr/upload/images/" $post->getIllustrationFilName(), 'author' => ["@type" => "Person""name" => $post->getCreatedBy()?->getFirstName() . ' ' $post->getCreatedBy()?->getLastName()], 'dateCreated' => $post->getCreatedAt(), 'dateModified' => $post->getUpdatedAt(), 'datePublished' => $post->getDateDebut(), 'publisher' => ["@type" => "Organization""name" => "Département du Nord"'logo' => ["@type" => "ImageObject""url" => "https://lenord.fr/upload/docs/image/png/2020-06/logo_nord_vlenord.png"]], 'creativeWorkStatus' => $post->getStatus()->getName()];
  2617.       $this->params['articleSchema'] = $this->schema_service->generateSchema($schema_params'NewsArticle');
  2618.     }
  2619.     //epingle
  2620.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2621.     if ($request->get('function') === 'download_pdf') {
  2622.       $pdfOptions = new Options();
  2623.       $pdfOptions->set('defaultFont''Arial');
  2624.       $pdfOptions->setIsRemoteEnabled(true);
  2625.       $dompdf = new Dompdf($pdfOptions);
  2626.       $html $this->renderView('Nordinfo/Main/detail_post.html.twig'$this->params);
  2627.       $dompdf->loadHtml($html);
  2628.       $dompdf->setPaper('A4''portrait');
  2629.       $dompdf->render();
  2630.       $output $dompdf->output();
  2631.       $filename sprintf('nord-info-%s.pdf'$post->getTitle());
  2632.       return new Response(
  2633.         $output,
  2634.         200,
  2635.         [
  2636.           'Content-Type' => 'application/pdf',
  2637.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  2638.         ]
  2639.       );
  2640.     } else {
  2641.       if ($post->getPositionImage() !== null && $post->getPositionImage()?->getId() === 1) {
  2642.         $this->params['placement_image'] = 'placement1';
  2643.       } else if ($post->getPositionImage()?->getId() === 3) {
  2644.         $this->params['placement_image'] = 'placement3';
  2645.       }
  2646.       if ($post->getType()->getType() == 'folder') {
  2647.         $k 0;
  2648.         foreach ($this->params['related_posts'] as $p) {
  2649.           $this->params['related_posts'][$k]->str_date $this->formatJsonDate($p->getJson());
  2650.           $k++;
  2651.         }
  2652.         return $this->render('Nordinfo/Main/detail_folder.html.twig'$this->params);
  2653.       }
  2654.       return $this->render('Nordinfo/Main/detail_post.html.twig'$this->params);
  2655.     }
  2656.   }
  2657.   private function formatJsonDate(mixed $json): mixed
  2658.   {
  2659.     $str_date null;
  2660.     $current_date = new DateTime();
  2661.     $current_date->setTime(000);
  2662.     $json_horaires json_decode($jsontrue);
  2663.     if ($json_horaires !== null) {
  2664.       switch ($json_horaires['modeDates']) {
  2665.         case "range":
  2666.           //de date debut a date fin
  2667.           $date_debut date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  2668.           $date_fin date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateFinish']);
  2669.           $ics_date_debut $json_horaires['datesRange']['dateStart'];
  2670.           $ics_date_fin $json_horaires['datesRange']['dateStart'];
  2671.           $evDateDebut $this->formatStringDate($date_debut);
  2672.           $evDateFin $this->formatStringDate($date_fin);
  2673.           $same_day false;
  2674.           if ($evDateDebut['day'] == $evDateFin['day']) {
  2675.             if ($evDateDebut['month'] == $evDateFin['month']) {
  2676.               $same_day true;
  2677.             }
  2678.           }
  2679.           if ($evDateDebut['day'] == || $evDateDebut['day'] == '01' || $evDateDebut['day'] == '1') {
  2680.             $day_debut $this->array_date_trad["fr"][1];
  2681.           } else {
  2682.             $day_debut $evDateDebut['day'];
  2683.           }
  2684.           if ($evDateDebut['month'] == $evDateFin['month'] && $evDateDebut['year'] == $evDateFin['year']) {
  2685.             if ($same_day) {
  2686.               //$this->translator->trans('du') . ' ' .
  2687.               $str_date $evDateFin['day'] . ' ' $evDateFin['month'];
  2688.             } else {
  2689.               $str_date 'Du ' $day_debut ' au ' $evDateFin['day'] . ' ' $evDateFin['month'];
  2690.             }
  2691.           } else {
  2692.             //check year de la date debut et fin
  2693.             if ($evDateDebut['year'] !== $evDateFin['year']) {
  2694.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' ' $evDateDebut['year'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2695.             } else {
  2696.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2697.             }
  2698.           }
  2699.           break;
  2700.         case 'multiple':
  2701.           $nombre_date 0;
  2702.           $dates_multiples = [];
  2703.           $dates $json_horaires['datesMultiple']['dates'];
  2704.           foreach ($dates as $d) {
  2705.             array_push($dates_multiples$d);
  2706.           }
  2707.           $date null;
  2708.           $array_dates $dates_multiples;
  2709.           $i 0;
  2710.           foreach ($array_dates as $d) {
  2711.             if ($i 0) {
  2712.               $str_date .= ", ";
  2713.             }
  2714.             $date date_create_from_format('d/m/Y'$dates_multiples[$i]);
  2715.             $str_date .= $date->format('d') . ' ' $this->months["fr"][$date->format('n')] . ' ' $date->format('Y');
  2716.             $i++;
  2717.           }
  2718.           break;
  2719.         case 'single':
  2720.           $start_date date_create_from_format('d/m/Y'$json_horaires['dateSingle']['dates'][0]);
  2721.           $day 'Le ' $start_date->format('d');
  2722.           $str_date .= $day;
  2723.           $str_month $this->months["fr"][$start_date->format('n')];
  2724.           $str_date .= ' ' $str_month;
  2725.           $str_date .= ' ' $start_date->format('Y');
  2726.           break;
  2727.       }
  2728.     }
  2729.     return $str_date;
  2730.   }
  2731.   public function pagelegales(Request $requeststring $slug): Response
  2732.   {
  2733.     $this->params['referer'] = $request->headers->get('referer');
  2734.     if ($slug == "comprendre-le-departement") {
  2735.       return $this->redirectToRoute('comprendre_le_departement');
  2736.     }
  2737.     $post $this->em->getRepository(PagesLegales::class)->findOneBy(['slug' => $slug'actif' => 1]);
  2738.     if(!$post){
  2739.       throw $this->createNotFoundException('La page demandée n\'existe pas.');
  2740.     }
  2741.     $this->params['post'] = $post;
  2742.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$this->params['post']->getTitre());
  2743.     //epingle
  2744.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2745.     $epingles_ $this->epingle_service->getEpinglesSection('legales_nordinfo');
  2746.     foreach ($epingles_ as $epingle) {
  2747.       array_push($this->params['epingles'], $epingle);
  2748.     }
  2749.     if ($request->get('function') == 'download_pdf') {
  2750.       $this->params['is_pdf'] = 1;
  2751.       $pdfOptions = new Options();
  2752.       $pdfOptions->set('defaultFont''Arial');
  2753.       $pdfOptions->setIsRemoteEnabled(true);
  2754.       $dompdf = new Dompdf($pdfOptions);
  2755.       $html $this->renderView('Nordinfo/Main/detail_page_legale.html.twig'$this->params);
  2756.       $dompdf->loadHtml($html);
  2757.       $dompdf->setPaper('A4''portrait');
  2758.       $dompdf->render();
  2759.       $output $dompdf->output();
  2760.       $filename sprintf('nord-info-%s.pdf'$this->params['post']->getTitre());
  2761.       return new Response(
  2762.         $output,
  2763.         200,
  2764.         [
  2765.           'Content-Type' => 'application/pdf',
  2766.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  2767.         ]
  2768.       );
  2769.     } else {
  2770.       return $this->render('Nordinfo/Main/detail_page_legale.html.twig'$this->params);
  2771.     }
  2772.   }
  2773.   #[Route(path'/ajax/getServicesAll'name'services_ajax_getServicesAllNordInfo')]
  2774.   public function getServicesAllNordInfo(Request $request): Response
  2775.   {
  2776.     $services $this->em->getRepository(Service::class)->getServicesByGrandprofil($request->request->get('alias'));
  2777.     return new JsonResponse(['datas' => $services]);
  2778.   }
  2779.   private mixed $months = array(
  2780.     'fr' => array(
  2781.       => 'janvier',
  2782.       => 'février',
  2783.       => 'mars',
  2784.       => 'avril',
  2785.       => 'mai',
  2786.       => 'juin',
  2787.       => 'juillet',
  2788.       => 'août',
  2789.       => 'septembre',
  2790.       10 => 'octobre',
  2791.       11 => 'novembre',
  2792.       12 => 'décembre'
  2793.     ),
  2794.     'en' => array(
  2795.       => 'January',
  2796.       => 'February',
  2797.       => 'March',
  2798.       => 'April',
  2799.       => 'May',
  2800.       => 'June',
  2801.       => 'July',
  2802.       => 'August',
  2803.       => 'September',
  2804.       10 => 'October',
  2805.       11 => 'November',
  2806.       12 => 'December',
  2807.     ),
  2808.     'nl' => array(
  2809.       => 'januari',
  2810.       => 'februari',
  2811.       => 'maart',
  2812.       => 'april',
  2813.       => 'mei',
  2814.       => 'juni',
  2815.       => 'juli',
  2816.       => 'augustus',
  2817.       => 'september',
  2818.       10 => 'oktober',
  2819.       11 => 'november',
  2820.       12 => 'december'
  2821.     )
  2822.   );
  2823.   private function formatStringDate(mixed $date): mixed
  2824.   {
  2825.     if ($date instanceof DateTime) {
  2826.       return array(
  2827.         'day' => $date->format('j'),
  2828.         'month' => $this->months["fr"][$date->format('n')],
  2829.         'year' => $date->format('Y')
  2830.       );
  2831.     }
  2832.     return array(
  2833.       'day' => null,
  2834.       'month' => null,
  2835.       'year' => null
  2836.     );
  2837.   }
  2838.   private mixed $array_date_trad = array(
  2839.     'fr' => array(
  2840.       => '1er'
  2841.     ),
  2842.     'en' => array(
  2843.       => '1st'
  2844.     ),
  2845.     'nl' => array(
  2846.       => '1st'
  2847.     )
  2848.   );
  2849.   private function formatDateAgendaJson(string $json): mixed
  2850.   {
  2851.     $str_date null;
  2852.     $current_date = new DateTime();
  2853.     $current_date->setTime(000);
  2854.     $json_horaires json_decode($jsontrue);
  2855.     $ics_date_debut null;
  2856.     $ics_date_fin null;
  2857.     $str_heure null;
  2858.     if ($json_horaires !== null) {
  2859.       switch ($json_horaires['modeDates']) {
  2860.         case "range":
  2861.           //de date debut a date fin
  2862.           $date_debut date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  2863.           $date_fin date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateFinish']);
  2864.           $ics_date_debut $json_horaires['datesRange']['dateStart'];
  2865.           $ics_date_fin $json_horaires['datesRange']['dateStart'];
  2866.           $evDateDebut $this->formatStringDate($date_debut);
  2867.           $evDateFin $this->formatStringDate($date_fin);
  2868.           $same_day false;
  2869.           if ($evDateDebut['day'] == $evDateFin['day']) {
  2870.             if ($evDateDebut['month'] == $evDateFin['month']) {
  2871.               $same_day true;
  2872.             }
  2873.           }
  2874.           if ($evDateDebut['day'] == || $evDateDebut['day'] == '01' || $evDateDebut['day'] == '1') {
  2875.             $day_debut $this->array_date_trad["fr"][1];
  2876.           } else {
  2877.             $day_debut $evDateDebut['day'];
  2878.           }
  2879.           if ($evDateDebut['month'] == $evDateFin['month'] && $evDateDebut['year'] == $evDateFin['year']) {
  2880.             if ($same_day) {
  2881.               //$this->translator->trans('du') . ' ' .
  2882.               $str_date $evDateFin['day'] . ' ' $evDateFin['month'];
  2883.             } else {
  2884.               $str_date 'Du ' $day_debut ' au ' $evDateFin['day'] . ' ' $evDateFin['month'];
  2885.             }
  2886.           } else {
  2887.             //check year de la date debut et fin
  2888.             if ($evDateDebut['year'] !== $evDateFin['year']) {
  2889.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' ' $evDateDebut['year'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2890.             } else {
  2891.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2892.             }
  2893.           }
  2894.           if ($json_horaires['datesRange']['modeHours'] == 'simple') {
  2895.             if ($json_horaires['datesRange']['hoursSimple'][0]['hour1'] !== null && $json_horaires['datesRange']['hoursSimple'][0]['hour2'] != null) {
  2896.               $str_heure .= str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour1']) . " - " str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour2']);
  2897.             }
  2898.             if ($json_horaires['datesRange']['hoursSimple'][0]['hour3'] !== null && $json_horaires['datesRange']['hoursSimple'][0]['hour4'] != null) {
  2899.               $str_heure .= " et " str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour3']) . " - " str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour4']);
  2900.             }
  2901.           }
  2902.           $str_date '<strong>' $str_date '</strong>';
  2903.           break;
  2904.         case 'multiple':
  2905.           $nombre_date 0;
  2906.           $dates_multiples = [];
  2907.           $dates $json_horaires['datesMultiple']['dates'];
  2908.           foreach ($dates as $d) {
  2909.             $date_json date_create_from_format('d/m/Y'$d);
  2910.             if ($date_json >= $current_date) {
  2911.               array_push($dates_multiples$d);
  2912.             }
  2913.           }
  2914.           $nombre_date count($dates_multiples);
  2915.           $ics_date_debut $dates_multiples[0];
  2916.           $ics_date_fin $dates_multiples[0];
  2917.           if ($json_horaires['datesMultiple']['modeHours'] == 'simple') {
  2918.             $date null;
  2919.             if ($nombre_date == 1) {
  2920.               $date1 date_create_from_format('d/m/Y'$dates_multiples[0]);
  2921.               $str_date .= 'Le ' $date1->format('d') . ' ' $this->months["fr"][$date1->format('n')];
  2922.             } else if ($nombre_date == 2) {
  2923.               $date1 date_create_from_format('d/m/Y'$dates_multiples[0]);
  2924.               $date2 date_create_from_format('d/m/Y'$dates_multiples[1]);
  2925.               $str_date .= 'Les ' $date1->format('d') . ' ' $this->months["fr"][$date1->format('n')] . ' et ' $date2->format('d') . ' ';
  2926.               $str_month $this->months["fr"][$date2->format('n')];
  2927.               $str_date .= ' ' $str_month;
  2928.             } else if ($nombre_date == 3) {
  2929.               $date1 date_create_from_format('d/m/Y'$dates_multiples[0]);
  2930.               $date2 date_create_from_format('d/m/Y'$dates_multiples[1]);
  2931.               $date3 date_create_from_format('d/m/Y'$dates_multiples[2]);
  2932.               $str_date .= 'Les ' $date1->format('d') . ' ' $this->months["fr"][$date1->format('n')] . ', ' $date2->format('d') . ' ' $this->months["fr"][$date2->format('n')] . ' et ' $date3->format('d') . ' ' $this->months["fr"][$date3->format('n')];
  2933.             } else if ($nombre_date 3) {
  2934.               $array_dates $dates_multiples;
  2935.               $i 0;
  2936.               foreach ($array_dates as $d) {
  2937.                 if ($i 0) {
  2938.                   $str_date .= "<br>";
  2939.                 }
  2940.                 $date date_create_from_format('d/m/Y'$dates_multiples[$i]);
  2941.                 $str_date .= $date->format('d') . ' ' $this->months["fr"][$date->format('n')] . ' ' $date->format('Y');
  2942.                 $i++;
  2943.               }
  2944.             }
  2945.             $str_date '<strong>' $str_date '</strong>';
  2946.             if ($json_horaires['datesMultiple']['hoursSimple'][0]['hour1'] !== null && $json_horaires['datesMultiple']['hoursSimple'][0]['hour2'] != null) {
  2947.               $str_heure .= str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour1']) . ' - ' str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour2']);
  2948.             }
  2949.             if ($json_horaires['datesMultiple']['hoursSimple'][0]['hour3'] !== null && $json_horaires['datesMultiple']['hoursSimple'][0]['hour4'] != null) {
  2950.               $str_heure .= " et " str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour3']) . " - " str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour4']);
  2951.             }
  2952.           } else if ($json_horaires['datesMultiple']['modeHours'] == 'details') {
  2953.             $hoursDetails $json_horaires['datesMultiple']['hoursDetails'];
  2954.             $i 0;
  2955.             foreach ($hoursDetails as $hour) {
  2956.               $start_date date_create_from_format('d/m/Y'$hour['date']);
  2957.               if ($start_date <= $current_date) {
  2958.                 continue;
  2959.               }
  2960.               if ($i 0) {
  2961.                 $str_date .= "<br>";
  2962.               }
  2963.               if ($hour['hour1'] !== null && $hour['hour2'] != null) {
  2964.                 $str_date .= '<strong>' $start_date->format('d') . ' ' $this->months["fr"][$start_date->format('n')] . ' ' $start_date->format('Y') . '</strong>, ' .
  2965.                   str_replace(":""h"$hour['hour1']) . ' - ' str_replace(":""h"$hour['hour2']);
  2966.               }
  2967.               if ($hour['hour3'] !== null && $hour['hour4'] != null) {
  2968.                 $str_date .= ' et ' str_replace(":""h"$hour['hour3']) . ' - ' str_replace(":""h"$hour['hour4']);
  2969.               }
  2970.               $i++;
  2971.             }
  2972.           }
  2973.           break;
  2974.         case 'single':
  2975.           $start_date date_create_from_format('d/m/Y'$json_horaires['dateSingle']['dates'][0]);
  2976.           $ics_date_debut $json_horaires['dateSingle']['dates'][0];
  2977.           $ics_date_fin $json_horaires['dateSingle']['dates'][0];
  2978.           $day $start_date->format('d');
  2979.           if ($start_date->format('d') == || $start_date->format('d') == '01') {
  2980.             $day "1er";
  2981.           }
  2982.           $str_date .= 'Le ' $day;
  2983.           $str_month $this->months["fr"][$start_date->format('n')];
  2984.           $str_date .= ' ' $str_month;
  2985.           if ($start_date->format('Y') != $current_date->format('Y')) {
  2986.             $str_date .= ' ' $start_date->format('Y');
  2987.           }
  2988.           if ($json_horaires['dateSingle']['hoursSimple'][0]['hour1'] !== null && $json_horaires['dateSingle']['hoursSimple'][0]['hour2'] != null) {
  2989.             $str_heure .= $json_horaires['dateSingle']['hoursSimple'][0]['hour1'] . ' - ' $json_horaires['dateSingle']['hoursSimple'][0]['hour2'];
  2990.           }
  2991.           if ($json_horaires['dateSingle']['hoursSimple'][0]['hour3'] !== null && $json_horaires['dateSingle']['hoursSimple'][0]['hour4'] != null) {
  2992.             $str_heure .= " et " $json_horaires['dateSingle']['hoursSimple'][0]['hour3'] . " - " $json_horaires['dateSingle']['hoursSimple'][0]['hour4'];
  2993.           }
  2994.           $str_date '<strong>' $str_date '</strong>';
  2995.           break;
  2996.       }
  2997.     }
  2998.     return [
  2999.       "date_string" => $str_date,
  3000.       "ics_date_debut" => $ics_date_debut,
  3001.       "ics_date_fin" => $ics_date_fin,
  3002.       "heure_string" => $str_heure
  3003.     ];
  3004.   }
  3005. }