src/Controller/Nordinfo/MainController.php line 2650

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.     $exclude_ids = [];
  1023.     if ($latestEpingle1) {
  1024.       $exclude_ids[] = $latestEpingle1->getId();
  1025.     }
  1026.     if ($latestTwoEpingles2) {
  1027.       foreach ($latestTwoEpingles2 as $epingle) {
  1028.         $exclude_ids[] = $epingle->getId();
  1029.       }
  1030.     }
  1031.     $posts $this->em->getRepository(Post::class)
  1032.       ->getCustomPosts(
  1033.         $type_posts,
  1034.         false,
  1035.         null,
  1036.         $territory_ids,
  1037.         $topic_ids,
  1038.         true,
  1039.         'DESC',
  1040.         $this->params['initial_limit'],
  1041.         0,
  1042.         false,
  1043.         null,
  1044.         null,
  1045.         false,
  1046.         $public,
  1047.         false,
  1048.         $private,
  1049.         $exclude_ids
  1050.       );
  1051.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)
  1052.       ->getCustomPosts(
  1053.         $type_posts,
  1054.         false,
  1055.         null,
  1056.         $territory_ids,
  1057.         $topic_ids,
  1058.         true,
  1059.         'DESC',
  1060.         null,
  1061.         0,
  1062.         true,
  1063.         null,
  1064.         null,
  1065.         false,
  1066.         $public,
  1067.         false,
  1068.         $private,
  1069.         $exclude_ids
  1070.       );
  1071.     $this->params['posts'] = $posts;
  1072.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1073.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1074.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1075.     $this->params['show_nav'] = 'true';
  1076.     $this->params['text_plus_button'] = 'PLUS D\'ACTU';
  1077.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1078.     $epingles_ $this->epingle_service->getEpinglesSection('mesinfos');
  1079.     foreach ($epingles_ as $epingle) {
  1080.       $this->params['epingles'][] = $epingle;
  1081.     }
  1082.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1083.     return $this->render('Nordinfo/Main/actus.html.twig'$this->params);
  1084.   }
  1085.   #[Route(path'/creation-de-compte'name'registration')]
  1086.   public function registration(): Response
  1087.   {
  1088.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'créer un compte');
  1089.     $this->params['caps'] = $this->getCaptcha();
  1090.     //epingle
  1091.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1092.     return $this->render('Nordinfo/Main/registration.html.twig'$this->params);
  1093.   }
  1094.   #[Route(path'/compte-supprime'name'remove_account')]
  1095.   public function removeAccount(Request $request): Response
  1096.   {
  1097.     $post $request->request;
  1098.     $user $this->getUser();
  1099.     $passwordValid $this->hasher->hashPassword($user$post->get('password'));
  1100.     //epingle
  1101.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1102.     if ($passwordValid && $post->get('checkboxConfirmDelete') != null) {
  1103.       //    if ($passwordValid && $post->get('check') == 'SUPPRIMER') {
  1104.       $destinataire = [];
  1105.       array_push($destinataire, ['email' => $user->getEmail(), 'name' => $user->getEmail()]);
  1106.       $content_mail $this->renderView(
  1107.         'Nordinfo/Mails/removeAccount.html.twig',
  1108.         ['email' => $user->getEmail(), 'nom' => $user->getPrenom() . ' ' $user->getNom()]
  1109.       );
  1110.       $this->em->remove($user);
  1111.       $this->em->flush();
  1112.       $this->sendgrid_service->send([$user->getEmail()], $content_mail"Confirmation de suppression");
  1113.       //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Confirmation de suppression');
  1114.       return $this->render('Nordinfo/Main/endremove.html.twig'$this->params);
  1115.     } else {
  1116.       $this->params['message'] = "Une erreur s'est produite";
  1117.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1118.     }
  1119.   }
  1120.   #[Route(path'/lien-activation/{token}'name'send_activation_again')]
  1121.   public function sendActivation(Request $requeststring $token): Response
  1122.   {
  1123.     $user $this->em->getRepository(User::class)->findOneBy(['token_activation' => $token]);
  1124.     //epingle
  1125.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1126.     if ($user == null) {
  1127.       $this->params['message'] = 'Compte déjà activé ou inexistant';
  1128.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1129.     }
  1130.     //Mail
  1131.     $destinataire = [];
  1132.     array_push($destinataire, ['email' => $user->getEmail(), 'name' => $user->getEmail()]);
  1133.     $date = new DateTime;
  1134.     $url $url $this->generateUrl('user_activate', ['token' => $token]);
  1135.     $content_mail $this->renderView(
  1136.       'Nordinfo/Mails/registration.html.twig',
  1137.       ['url_activation' => 'https://' $request->getHost() . $url]
  1138.     );
  1139.     $this->sendgrid_service->send([$user->getEmail()], $content_mail"Accusé de création de compte");
  1140.     //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Accusé de création de compte');
  1141.     return $this->render('Nordinfo/Main/endform.html.twig'$this->params);
  1142.   }
  1143.   #[Route(path'/send_registration'name'send_registration')]
  1144.   public function send_registration(Request $request): Response
  1145.   {
  1146.     $post $request->request;
  1147.     $caps $this->getCaptcha();
  1148.     //$array_search($post->get('nb1'))
  1149.     $result_ $post->get('nb1') + $post->get('nb2');
  1150.     if ($result_ == $post->get('captcha')) {
  1151.       if ($this->em->getRepository(User::class)->findOneBy(['email' => $post->get('email')]) == null) {
  1152.         //rechercher si adresse @lenord.fa-r-project//droit => agent sinon droit => public
  1153.         $role 'public';
  1154.         $ex_email explode("@"$post->get('email'));
  1155.         if ($ex_email[1] == 'lenord.fr') {
  1156.           $role 'agent';
  1157.         }
  1158.         $token hash('md5'$post->get('email') . uniqid());
  1159.         $this->params['token'] = $token;
  1160.         $user = new User;
  1161.         $hpass $this->hasher->hashPassword($user$post->get('pass'));
  1162.         $user->setEmail($post->get('email'))
  1163.           ->setFirstName($post->get('first_name'))
  1164.           ->setLastName($post->get('last_name'))
  1165.           ->setPassword($hpass)
  1166.           ->setRole($role)
  1167.           ->setActive(false)
  1168.           ->setTokenActivation($token);
  1169.         $this->em->persist($user);
  1170.         $this->em->flush();
  1171.         //email
  1172.         //Mail
  1173.         $destinataire = [];
  1174.         array_push($destinataire, ['email' => $post->get('email'), 'name' => $post->get('email')]);
  1175.         $date = new DateTime;
  1176.         $url $url $this->generateUrl('user_activate', ['token' => $token]);
  1177.         $content_mail $this->renderView(
  1178.           'Nordinfo/Mails/registration.html.twig',
  1179.           ['url_activation' => 'https://' $request->getHost() . $url]
  1180.         );
  1181.         $this->sendgrid_service->send([$post->get('email')], $content_mail"Accusé de création de compte");
  1182.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Accusé de création de compte');
  1183.       } else {
  1184.         $this->params['noenveloppe'] = true;
  1185.         $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>';
  1186.         return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1187.       }
  1188.     } else {
  1189.       $this->params['message'] = 'Captcha erreur';
  1190.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  1191.     }
  1192.     return $this->render('Nordinfo/Main/endregister1.html.twig'$this->params);
  1193.   }
  1194.   public function direct(Request $request): Response
  1195.   {
  1196.     $this->params['referer'] = $request->headers->get('referer');
  1197.     $this->params['list_type'] = 'direct';
  1198.     $this->params['title'] = 'En direct';
  1199.     $this->params['tagbar'] = false;
  1200.     $this->params['items_offset'] = 20;
  1201.     $this->params['initial_limit'] = 20;
  1202.     $post_types = [579];
  1203.     $public $this->getPublic();
  1204.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1205.       $post_types,
  1206.       null,
  1207.       'direct',
  1208.       null,
  1209.       null,
  1210.       false,
  1211.       'DESC',
  1212.       $this->params['initial_limit'],
  1213.       0,
  1214.       null,
  1215.       null,
  1216.       false,
  1217.       $public
  1218.     );
  1219.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1220.       $post_types,
  1221.       null,
  1222.       'direct',
  1223.       null,
  1224.       null,
  1225.       false,
  1226.       'DESC',
  1227.       null,
  1228.       0,
  1229.       true,
  1230.       null,
  1231.       null,
  1232.       false,
  1233.       $public
  1234.     );
  1235.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1236.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1237.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1238.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1239.     $this->params['show_nav'] = 'true';
  1240.     $this->params['show_date_bar'] = true;
  1241.     $this->params['text_plus_button'] = 'PLUS DE POSTS';
  1242.     //epingle
  1243.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1244.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1245.   }
  1246.   #[Route(path'/nos-reseaux'name'reseaux')]
  1247.   public function reseaux(): Response
  1248.   {
  1249.     //epingle
  1250.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1251.     return $this->render('Nordinfo/Main/reseaux.html.twig'$this->params);
  1252.   }
  1253.   /**
  1254.    * @throws \JsonException
  1255.    */
  1256.   #[Route(path'/agenda'name'agenda')]
  1257.   public function agenda(Request $request): Response
  1258.   {
  1259.     /**
  1260.      * BE CAREFUL!
  1261.      * THE CODE THAT HAS TO DO WITH RETRIEVING ITEMS, HAS TO BE ALSO CLONED INSIDE THE AjaxController.php
  1262.      */
  1263.     $this->params['referer'] = $request->headers->get('referer');
  1264.     $date_param $request->query->get('date');
  1265.     $query_date2 null;
  1266.     $query_date_from false;
  1267.     if (!isset($date_param) || trim($date_param) === '') {
  1268.       $query_date = new DateTime();
  1269.       $query_date_from true;
  1270.     } else if ($date_param === 'today') {
  1271.       $query_date = new DateTime();
  1272.     } else if ($date_param === 'weekend') {
  1273.       $query_date = new DateTime('Saturday');
  1274.       $query_date2 = new DateTime('Sunday');
  1275.     } else {
  1276.       $query_date_from true;
  1277.       $query_date date_create_from_format('d/m/Y'$date_param);
  1278.       if (!$query_date) {
  1279.         $query_date date_create_from_format('Y-m-d'$date_param);
  1280.       }
  1281.       $outputDate $query_date->format('d F Y');
  1282.       $outputDate str_replace(
  1283.         array('January''February''March''April''May''June''July''August''September''October''November''December'),
  1284.         array('Janvier''Février''Mars''Avril''Mai''Juin''Juillet''Août''Septembre''Octobre''Novembre''Décembre'),
  1285.         $outputDate
  1286.       );
  1287.       $this->params['show_date_bar_agenda'] = $outputDate;
  1288.     }
  1289.     $this->params['list_type'] = 'agenda';
  1290.     $this->params['title'] = 'Agenda';
  1291.     $this->params['tagbar'] = false;
  1292.     $this->params['cookie_search'] = true;
  1293.     $territory_ids $this->getTerritoryIds($request);
  1294.     $this->params['cookie_territories'] = $this->getTerritories($request);
  1295.     $this->params['cookie_topics'] = $this->getTopics($request);
  1296.     
  1297.     $this->params['topics'] = $this->em->getRepository(Topic::class)->getAll();
  1298.     $checkTopics = [];
  1299.     if ($this->getUser() != null) {
  1300.       foreach ($this->getUser()->getThematiques() as $topic) {
  1301.         $checkTopics[] = $topic->getId();
  1302.       }
  1303.     } else if ($request->cookies->get('topics') != null) {
  1304.       $checkTopics explode(','$request->cookies->get('topics'));
  1305.     }
  1306.     $this->params['checkTopics'] = $checkTopics;
  1307.     $checkTerritories = [];
  1308.     if ($this->getUser() != null) {
  1309.       foreach ($this->getUser()->getTerritoires() as $territoire) {
  1310.         $checkTerritories[] = $territoire->getId();
  1311.       }
  1312.     } else if ($request->cookies->get('territories') != null) {
  1313.       $checkTerritories explode(','$request->cookies->get('territories'));
  1314.     }
  1315.     $territories $this->em->getRepository(Territory::class)->getListeTerritories();
  1316.     $this->params['territories'] = $territories;
  1317.     $this->params['checkTerritories'] = $checkTerritories;
  1318.     $public $this->getPublic();
  1319.     $posts $this->em->getRepository(Post::class)->getCustomArrayPosts(
  1320.       [3679],
  1321.       true,
  1322.       'agenda',
  1323.       $territory_ids,
  1324.       null,
  1325.       false,
  1326.       $this->params['total_limit'],
  1327.       0,
  1328.       false,
  1329.       $query_date,
  1330.       $query_date2,
  1331.       $query_date_from,
  1332.       $public
  1333.     );
  1334.     $posts iterator_to_array($posts);
  1335.     $posts $this->new_feed_utilities->checkboxes_get_description($posts$request);
  1336.     $posts $this->new_feed_utilities->social_posts_padding($posts$request);
  1337.     $posts $this->new_feed_utilities->focus_pub_img_dimensions($posts$request);
  1338.     $posts $this->new_feed_utilities->social_posts_detect_links($posts);
  1339.     $postsProcessed $this->agenda_service->parseAgendaEvents($posts$query_date$query_date2true$date_param);
  1340.     $this->params['items_total'] = count($postsProcessed);
  1341.     $this->params['posts'] = array_slice($postsProcessed0$this->params['initial_limit']);
  1342.     foreach ($this->params['posts'] as &$post) {
  1343.       $post['couleurTexte'] = $post['couleur_texte'];
  1344.       if ($post['couleur_texte']) {
  1345.         $post['couleurTexte']['codeHexa'] = $post['couleur_texte']['code_hexa'];
  1346.         $post['couleurTexte']['codeHexaDark'] = $post['couleur_texte']['code_hexa_dark'];
  1347.       }
  1348.       if ($post['couleur']) {
  1349.         $post['couleur']['codeHexa'] = $post['couleur']['code_hexa'];
  1350.         $post['couleur']['codeHexaDark'] = $post['couleur']['code_hexa_dark'];
  1351.       }
  1352.     }
  1353.     unset($post);
  1354.     
  1355.     $this->params['show_agenda_filters'] = 1;
  1356.     $this->params['show_nav'] = 'true';
  1357.     $this->params['text_plus_button'] = 'PLUS D\'ÉVÈNEMENTS';
  1358.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1359.     $epingles_ $this->epingle_service->getEpinglesSection('agenda');
  1360.     foreach ($epingles_ as $epingle) {
  1361.       $this->params['epingles'][] = $epingle;
  1362.     }
  1363.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1364.     return $this->render('Nordinfo/Main/agenda.html.twig'$this->params);
  1365.   }
  1366.   #[Route(path'/infolettre'name'infolettre')]
  1367.   public function infolettre(Request $request): Response
  1368.   {
  1369.     $this->params['referer'] = $request->headers->get('referer');
  1370.     $this->params['breadcrumb'] = $this->setBreadCrumb(null"Infolettre");
  1371.     //epingle
  1372.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1373.     return $this->render('Nordinfo/Main/infolettre.html.twig'$this->params);
  1374.   }
  1375.   #[Route(path'/videos'name'videos')]
  1376.   public function videos(Request $request): Response
  1377.   {
  1378.     $this->params['referer'] = $request->headers->get('referer');
  1379.     $this->params['list_type'] = 'videos';
  1380.     $this->params['title'] = 'Vidéos';
  1381.     $this->params['tagbar'] = false;
  1382.     $this->params['show_date_bar'] = 1;
  1383.     $posts_types = [4679];
  1384.     $public $this->getPublic();
  1385.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1386.       $posts_types,
  1387.       null,
  1388.       'videos',
  1389.       null,
  1390.       null,
  1391.       false,
  1392.       'DESC',
  1393.       $this->params['initial_limit'],
  1394.       0,
  1395.       false,
  1396.       null,
  1397.       null,
  1398.       false,
  1399.       $public
  1400.     );
  1401.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1402.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1403.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1404.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1405.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1406.       $posts_types,
  1407.       null,
  1408.       'videos',
  1409.       null,
  1410.       null,
  1411.       false,
  1412.       'DESC',
  1413.       null,
  1414.       0,
  1415.       true,
  1416.       null,
  1417.       null,
  1418.       false,
  1419.       $public
  1420.     );
  1421.     $this->params['show_nav'] = 'true';
  1422.     $this->params['text_plus_button'] = 'PLUS DE VIDEOS';
  1423.     //epingle
  1424.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1425.     $epingles_ $this->epingle_service->getEpinglesSection('videos');
  1426.     foreach ($epingles_ as $epingle) {
  1427.       array_push($this->params['epingles'], $epingle);
  1428.     }
  1429.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1430.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1431.   }
  1432.   #[Route(path'/podcasts'name'podcasts')]
  1433.   public function podcasts(Request $request): Response
  1434.   {
  1435.     $this->params['referer'] = $request->headers->get('referer');
  1436.     $this->params['list_type'] = 'podcasts';
  1437.     $this->params['title'] = 'Podcasts';
  1438.     $this->params['tagbar'] = false;
  1439.     $this->params['show_date_bar'] = 1;
  1440.     $posts_types = [10];
  1441.     $public $this->getPublic();
  1442.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1443.       $posts_types,
  1444.       null,
  1445.       'podcasts',
  1446.       null,
  1447.       null,
  1448.       false,
  1449.       'DESC',
  1450.       $this->params['initial_limit'],
  1451.       0,
  1452.       false,
  1453.       null,
  1454.       null,
  1455.       false,
  1456.       $public
  1457.     );
  1458.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1459.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1460.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1461.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1462.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1463.       $posts_types,
  1464.       null,
  1465.       'podcasts',
  1466.       null,
  1467.       null,
  1468.       false,
  1469.       'DESC',
  1470.       null,
  1471.       0,
  1472.       true,
  1473.       null,
  1474.       null,
  1475.       false,
  1476.       $public
  1477.     );
  1478.     $this->params['show_nav'] = 'true';
  1479.     $this->params['text_plus_button'] = 'PLUS DE PODCASTS';
  1480.     //epingle
  1481.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1482.     $epingles_ $this->epingle_service->getEpinglesSection('videos');
  1483.     foreach ($epingles_ as $epingle) {
  1484.       $this->params['epingles'][] = $epingle;
  1485.     }
  1486.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1487.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1488.   }
  1489.   #[Route(path'/dossiers'name'dossiers')]
  1490.   public function dossiers(Request $request): Response
  1491.   {
  1492.     $this->params['referer'] = $request->headers->get('referer');
  1493.     $this->params['list_type'] = 'dossiers';
  1494.     $this->params['title'] = 'Dossiers';
  1495.     $this->params['tagbar'] = false;
  1496.     $this->params['show_date_bar'] = 1;
  1497.     $posts_types = [2];
  1498.     $public $this->getPublic();
  1499.     $this->params['posts'] = $this->em->getRepository(Post::class)->getCustomPosts(
  1500.       $posts_types,
  1501.       null,
  1502.       'dossiers',
  1503.       null,
  1504.       null,
  1505.       false,
  1506.       'DESC',
  1507.       $this->params['initial_limit'],
  1508.       0,
  1509.       false,
  1510.       null,
  1511.       null,
  1512.       false,
  1513.       $public
  1514.     );
  1515.     $this->params['posts'] = $this->feedUtilities->checkboxes_get_description($this->params['posts'], $request);
  1516.     $this->params['posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['posts'], $request);
  1517.     $this->params['posts'] = $this->feedUtilities->social_posts_padding($this->params['posts'], $request);
  1518.     $this->params['posts'] = $this->feedUtilities->social_posts_detect_links($this->params['posts']);
  1519.     $this->params['items_total'] = (int)$this->em->getRepository(Post::class)->getCustomPosts(
  1520.       $posts_types,
  1521.       null,
  1522.       'dossiers',
  1523.       null,
  1524.       null,
  1525.       false,
  1526.       'DESC',
  1527.       null,
  1528.       0,
  1529.       true,
  1530.       null,
  1531.       null,
  1532.       false,
  1533.       $public
  1534.     );
  1535.     $this->params['show_nav'] = 'true';
  1536.     $this->params['text_plus_button'] = 'PLUS DE DOSSIERS';
  1537.     //epingle
  1538.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1539.     $epingles_ $this->epingle_service->getEpinglesSection('videos');
  1540.     foreach ($epingles_ as $epingle) {
  1541.       $this->params['epingles'][] = $epingle;
  1542.     }
  1543.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsefalsetrue);
  1544.     return $this->render('Nordinfo/Main/gabarit_list.html.twig'$this->params);
  1545.   }
  1546.   #[Route(path'/video-{slug}'name'video_detail')]
  1547.   public function video_detail_post(Request $requeststring $slug): Response
  1548.   {
  1549.     return $this->detail_post($request$slug);
  1550.   }
  1551.   private function cmp($a$b)
  1552.   {
  1553.     return strcmp((string)$a->getOrderFolder(), (string)$b->getOrderFolder());
  1554.   }
  1555.   protected function isFavoritev2($post_id$user$request): bool
  1556.   {
  1557.     $favorite false;
  1558.     $user $this->getUser();
  1559.     if ($user !== null) {
  1560.       foreach ($user->getFavoris() as $favori) {
  1561.         if ($post_id == $favori->getId()) {
  1562.           $favorite true;
  1563.           break;
  1564.         }
  1565.       }
  1566.     } else {
  1567.       if ($request->cookies->get('favorite') != null) {
  1568.         if (in_array($post_idexplode(',', (string)$request->cookies->get('favorite'))) == true) {
  1569.           $favorite true;
  1570.         }
  1571.       }
  1572.     }
  1573.     return $favorite;
  1574.   }
  1575.   protected function isFavorite(mixed $postmixed $userRequest $request): bool
  1576.   {
  1577.     $favorite false;
  1578.     $user $this->getUser();
  1579.     if ($user !== null) {
  1580.       foreach ($user->getFavoris() as $favori) {
  1581.         if ($post->getId() == $favori->getId()) {
  1582.           $favorite true;
  1583.           break;
  1584.         }
  1585.       }
  1586.     } else {
  1587.       if ($request->cookies->get('favorite') != null) {
  1588.         if (in_array($post->getId(), explode(',', (string)$request->cookies->get('favorite'))) == true) {
  1589.           $favorite true;
  1590.         }
  1591.       }
  1592.     }
  1593.     return $favorite;
  1594.   }
  1595.   protected function getRelatedPosts(mixed $post): array
  1596.   {
  1597.     $number 0;
  1598.     $relateds = [];
  1599.     $relatedPost1 $post->getRelatedPost1();
  1600.     if ($relatedPost1 === null) {
  1601.       $number 1;
  1602.     } else if ($relatedPost1->getStatus()->getId() === 5) {
  1603.       $relateds[] = $post->getRelatedPost1();
  1604.     }
  1605.     $relatedPost2 $post->getRelatedPost2();
  1606.     if ($relatedPost2 === null) {
  1607.       $number 2;
  1608.     } else if ($relatedPost2->getStatus()->getId() === 5) {
  1609.       $relateds[] = $post->getRelatedPost2();
  1610.     }
  1611.     $relatedPost3 $post->getRelatedPost3();
  1612.     if ($relatedPost3 === null) {
  1613.       $number 3;
  1614.     } else if ($relatedPost3->getStatus()->getId() === 5) {
  1615.       $relateds[] = $post->getRelatedPost3();
  1616.     }
  1617.     $type_id $post->getType()->getId();
  1618.     $topics_id = [];
  1619.     foreach ($post->getTopics() as $topic) {
  1620.       $topics_id[] = $topic->getId();
  1621.     }
  1622.     $territories_id = [];
  1623.     foreach ($post->getTerritories() as $territory) {
  1624.       $territories_id[] = $territory->getId();
  1625.     }
  1626.     $posts $this->em->getRepository(Post::class)->getRelatedPost($number$type_id$topics_id$territories_id$post->getId());
  1627.     foreach ($posts as $p) {
  1628.       if (count($relateds) === 4) {
  1629.         break;
  1630.       }
  1631.       if ($p->getSlug() !== null) {
  1632.         $relateds[] = $p;
  1633.       }
  1634.     }
  1635.     return $relateds;
  1636.   }
  1637.   protected function setBreadCrumb(mixed $post nullmixed $page_title nullmixed $departement falsemixed $liste null): mixed
  1638.   {
  1639.     $breadcrumb = [];
  1640.     array_push($breadcrumb, ['alias' => $this->generateUrl('index'), 'titre' => 'Accueil']);
  1641.     if ($post != null) {
  1642.       switch ($post->getType()->getType()) {
  1643.         case 'article':
  1644.         case 'sondage':
  1645.         case 'folder':
  1646.         case 'pub':
  1647.           array_push($breadcrumb, ['alias' => $this->generateUrl('info'), 'titre' => "L'info"]);
  1648.           break;
  1649.         case 'event':
  1650.           array_push($breadcrumb, ['alias' => $this->generateUrl('agenda'), 'titre' => "Agenda"]);
  1651.           break;
  1652.         case 'video':
  1653.           array_push($breadcrumb, ['alias' => $this->generateUrl('videos'), 'titre' => "Vidéos"]);
  1654.           break;
  1655.         case 'socialpost':
  1656.           array_push($breadcrumb, ['alias' => $this->generateUrl('direct'), 'titre' => 'En direct']);
  1657.           break;
  1658.       }
  1659.       array_push($breadcrumb, ['alias' => '''titre' => $post->getTitle()]);
  1660.     }
  1661.     if ($page_title != null && $departement == false) {
  1662.       array_push($breadcrumb, ['alias' => '''titre' => $page_title]);
  1663.     } else if ($page_title != null && $departement == true && $liste == null) {
  1664.       array_push($breadcrumb, ['alias' => $this->generateUrl('departement'), 'titre' => 'le Département']);
  1665.       array_push($breadcrumb, ['alias' => '''titre' => $page_title]);
  1666.     } else if ($page_title != null && $departement == true && $liste != null) {
  1667.       array_push($breadcrumb, ['alias' => $this->generateUrl('departement'), 'titre' => 'le Département']);
  1668.       if ($liste == 'elus') {
  1669.         array_push($breadcrumb, ['alias' => $this->generateUrl('contacts'), 'titre' => 'contacts et élus']);
  1670.       } else {
  1671.         array_push($breadcrumb, ['alias' => $this->generateUrl(
  1672.           'organisations',
  1673.           ['type' => $liste]
  1674.         ), 'titre' => $liste]);
  1675.       }
  1676.       array_push($breadcrumb, ['alias' => '''titre' => $page_title]);
  1677.     }
  1678.     return $breadcrumb;
  1679.   }
  1680.   protected function getTerritories(Request $request): mixed
  1681.   {
  1682.     $cookie_territories = [];
  1683.     $territories = [];
  1684.     $user $this->getUser();
  1685.     if ($user !== null) {
  1686.       foreach ($user->getTerritoires() as $territoire) {
  1687.         $territories[] = (int)$territoire->getId();
  1688.       }
  1689.     } else {
  1690.       if ($request->cookies->get('territories') != null) {
  1691.         $territories explode(','$request->cookies->get('territories'));
  1692.       }
  1693.     }
  1694.     foreach ($territories as $territory_id) {
  1695.       $terr $this->em->getRepository(Territory::class)->find($territory_id);
  1696.       $cookie_territories[] = $terr?->getDisplayName();
  1697.     }
  1698.     return $cookie_territories;
  1699.   }
  1700.   protected function getTerritoryIds(Request $request): mixed
  1701.   {
  1702.     $territories = [];
  1703.     $user $this->getUser();
  1704.     if ($user !== null) {
  1705.       foreach ($user->getTerritoires() as $territoire) {
  1706.         $territories[] = (int)$territoire->getId();
  1707.       }
  1708.     } else {
  1709.       if ($request->cookies->get('territories') != null) {
  1710.         $territories explode(','$request->cookies->get('territories'));
  1711.       }
  1712.     }
  1713.     return $territories;
  1714.   }
  1715.   protected function getTopics(Request $request): mixed
  1716.   {
  1717.     $cookie_topics = [];
  1718.     $topics = [];
  1719.     $user $this->getUser();
  1720.     if ($user !== null) {
  1721.       foreach ($user->getThematiques() as $topic) {
  1722.         $topics[] = (int)$topic->getId();
  1723.       }
  1724.     } else {
  1725.       if ($request->cookies->get('topics') != null) {
  1726.         $topics explode(','$request->cookies->get('topics'));
  1727.       }
  1728.     }
  1729.     foreach ($topics as $topic_id) {
  1730.       $terr $this->em->getRepository(Topic::class)->find($topic_id);
  1731.       $cookie_topics[] = ($terr != null) ? $terr->getDisplayName() : 'error';
  1732.     }
  1733.     return $cookie_topics;
  1734.   }
  1735.   protected function getTopicIds(Request $request): mixed
  1736.   {
  1737.     $topics = [];
  1738.     $user $this->getUser();
  1739.     if ($user !== null) {
  1740.       foreach ($user->getThematiques() as $topic) {
  1741.         $topics[] = (int)$topic->getId();
  1742.       }
  1743.     } else {
  1744.       if ($request->cookies->get('topics') != null) {
  1745.         $topics explode(','$request->cookies->get('topics'));
  1746.       }
  1747.     }
  1748.     return $topics;
  1749.   }
  1750.   #[Route(path'/contact/{slug}'name'contact_detail')]
  1751.   public function detail_contact(Request $requeststring $slug): Response
  1752.   {
  1753.     $contact $this->em->getRepository(Contact::class)->getContact_($slug);
  1754.     $this->params['contact'] = $contact;
  1755.     $posts = [];
  1756.     $count_post 0;
  1757.     foreach ($contact->getPosts1() as $pp) {
  1758.       if ($count_post >= 3) {
  1759.         break;
  1760.       }
  1761.       $posts[] = $pp;
  1762.       $count_post++;
  1763.     }
  1764.     if ($count_post 3) {
  1765.       foreach ($contact->getPosts2() as $pp) {
  1766.         if ($count_post >= 3) {
  1767.           break;
  1768.         }
  1769.         $posts[] = $pp;
  1770.         $count_post++;
  1771.       }
  1772.     }
  1773.     if ($count_post 3) {
  1774.       foreach ($contact->getPosts3() as $pp) {
  1775.         if ($count_post >= 3) {
  1776.           break;
  1777.         }
  1778.         $posts[] = $pp;
  1779.         $count_post++;
  1780.       }
  1781.     }
  1782.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$contact->getFirstName() . ' ' $contact->getLastName(), true'elus');
  1783.     $this->params['contact_posts'] = $posts;
  1784.     $this->params['referer'] = $request->headers->get('referer');
  1785.     $this->params['caps'] = $this->getCaptcha();
  1786.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1787.     if ($request->get('function') == 'download_pdf') {
  1788.       $this->params['is_pdf'] = 1;
  1789.       $pdfOptions = new Options();
  1790.       $pdfOptions->set('defaultFont''Arial');
  1791.       $pdfOptions->setIsRemoteEnabled(true);
  1792.       $dompdf = new Dompdf($pdfOptions);
  1793.       $html $this->renderView('Nordinfo/Main/detail_contact.html.twig'$this->params);
  1794.       $dompdf->loadHtml($html);
  1795.       $dompdf->setPaper('A4''portrait');
  1796.       $dompdf->render();
  1797.       $output $dompdf->output();
  1798.       $filename sprintf('nord-info-%s.pdf'$contact->getFirstName());
  1799.       return new Response(
  1800.         $output,
  1801.         200,
  1802.         [
  1803.           'Content-Type' => 'application/pdf',
  1804.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  1805.         ]
  1806.       );
  1807.     } else {
  1808.       return $this->render('Nordinfo/Main/detail_contact.html.twig'$this->params);
  1809.     }
  1810.   }
  1811.   #[Route(path'/organisation/{id}'name'organisation_detail')]
  1812.   public function detail_organisation(Request $requestmixed $id): mixed
  1813.   {
  1814.     $organisation $this->em->getRepository(Organization::class)->getOrganisation($id);
  1815.     $this->params['organisation'] = $organisation;
  1816.     $this->params['referer'] = $request->headers->get('referer');
  1817.     $type null;
  1818.     $type_id $organisation->getTypeOrganisation()->getId();
  1819.     /*switch ($type_id) {
  1820.       case 1:
  1821.         $type = 'colleges';
  1822.         break;
  1823.       case 2:
  1824.         $type = 'secteur-social';
  1825.         break;
  1826.       case 3:
  1827.       case 4:
  1828.         $type = 'espaces-naturels-sensibles';
  1829.         break;
  1830.     }*/
  1831.     $type $organisation->getTypeOrganisation()->getName();
  1832.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$organisation->getTitle(), true$type);
  1833.     $related_posts = [];
  1834.     $ids_done = [];
  1835.     foreach ($organisation->getPosts1() as $post) {
  1836.       if (($post->getStatus()->getId() === 5) && !in_array($post->getId(), $ids_donetrue)) {
  1837.         $related_posts[] = $post;
  1838.         $ids_done[] = $post->getId();
  1839.       }
  1840.     }
  1841.     foreach ($organisation->getPosts2() as $post) {
  1842.       if (($post->getStatus()->getId() === 5) && !in_array($post->getId(), $ids_donetrue)) {
  1843.         $related_posts[] = $post;
  1844.         $ids_done[] = $post->getId();
  1845.       }
  1846.     }
  1847.     foreach ($organisation->getPosts3() as $post) {
  1848.       if (($post->getStatus()->getId() === 5) && !in_array($post->getId(), $ids_donetrue)) {
  1849.         $related_posts[] = $post;
  1850.         $ids_done[] = $post->getId();
  1851.       }
  1852.     }
  1853.     $this->params['related_posts'] = $related_posts;
  1854.     $this->params['caps'] = $this->getCaptcha();
  1855.     //epingle
  1856.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1857.     return $this->render('Nordinfo/Main/detail_organisation.html.twig'$this->params);
  1858.   }
  1859.   #[Route(path'/le-departement/{slug}'name'page')]
  1860.   public function page(Request $requeststring $slug): Response
  1861.   {
  1862.     $this->params['referer'] = $request->headers->get('referer');
  1863.     $post $this->em->getRepository(Pages::class)->findOneBy(['alias_url' => $slug'actif' => 1'nordinfo' => 1]);
  1864.     if (!$post) {
  1865.         throw $this->createNotFoundException('La page demandée n\'existe pas.');
  1866.     }
  1867.     $this->params['post'] = $post;
  1868.     $content_post null;
  1869.     if ($this->params['post']->getContent() != null) {
  1870.       $content_post $this->feedUtilities->jsonToHtml($this->params['post']->getContent(), $request$this->params['post']->getTitre());
  1871.     }
  1872.     $this->params['content_post'] = $content_post;
  1873.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$this->params['post']->getTitre(), true);
  1874.     //epingle
  1875.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1876.     return $this->render('Nordinfo/Main/detail_page.html.twig'$this->params);
  1877.   }
  1878.   #[Route(path'/post-testing/{id}'name'post_testing')]
  1879.   public function postTesting(Request $requestmixed $id): Response
  1880.   {
  1881.     $post $this->em
  1882.       ->getRepository(Post::class)
  1883.       ->find($id);
  1884.     $contentJson $post->getContent();
  1885.     $html $this->feedUtilities->jsonToHtml($contentJson$request);
  1886.     return $this->render('Nordinfo/Main/demo-post.html.twig', ['page_content' => $html]);
  1887.   }
  1888.   #[Route(path'/elements'name'elements')]
  1889.   public function elements(): Response
  1890.   {
  1891.     return $this->render('Nordinfo/Main/elements.html.twig'$this->params);
  1892.   }
  1893.   #[Route(path'/thematiques'name'topics')]
  1894.   public function topics(Request $request): Response
  1895.   {
  1896.     $this->params['referer'] = $request->headers->get('referer');
  1897.     $this->params['topics'] = $this->em->getRepository(Topic::class)->getAll();
  1898.     $checkTopics = [];
  1899.     if ($this->getUser() != null) {
  1900.       foreach ($this->getUser()->getThematiques() as $topic) {
  1901.         $checkTopics[] = $topic->getId();
  1902.       }
  1903.     } else if ($request->cookies->get('topics') != null) {
  1904.       $checkTopics explode(','$request->cookies->get('topics'));
  1905.     }
  1906.     $this->params['checkTopics'] = $checkTopics;
  1907.     $this->params['show_nav'] = 'false';
  1908.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'vos thématiques');
  1909.     //epingle
  1910.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1911.     return $this->render('Nordinfo/Main/topics.html.twig'$this->params);
  1912.   }
  1913.   #[Route(path'/vos-lieux'name'vos_lieux')]
  1914.   public function vos_lieux(Request $request): Response
  1915.   {
  1916.     $this->params['referer'] = $request->headers->get('referer');
  1917.     $checkTerritories = [];
  1918.     if ($this->getUser() != null) {
  1919.       foreach ($this->getUser()->getTerritoires() as $territoire) {
  1920.         $checkTerritories[] = $territoire->getId();
  1921.       }
  1922.     } else if ($request->cookies->get('territories') != null) {
  1923.       $checkTerritories explode(','$request->cookies->get('territories'));
  1924.     }
  1925.     $territories $this->em->getRepository(Territory::class)->getListeTerritories();
  1926.     $this->params['territories'] = $territories;
  1927.     $this->params['checkTerritories'] = $checkTerritories;
  1928.     $this->params['show_nav'] = 'false';
  1929.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'Vos lieux de vie');
  1930.     //epingle
  1931.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1932.     return $this->render('Nordinfo/Main/vos_lieux.html.twig'$this->params);
  1933.   }
  1934.   #[Route(path'/mon-compte'name'mon_compte')]
  1935.   public function monCompte(Request $request)
  1936.   {
  1937.     if ($this->getUser() == null) {
  1938.       return $this->redirect('login');
  1939.     }
  1940.     $this->params['referer'] = $request->headers->get('referer');
  1941.     $this->params['show_nav'] = 'false';
  1942.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'Mon Compte');
  1943.     $this->params['cookie_territories'] = $this->getTerritories($request);
  1944.     $this->params['cookie_topics'] = $this->getTopics($request);
  1945.     $this->params['posts_favoris'] = $this->getFavoris($request);
  1946.     $this->params['items_total_favoris'] = sizeof($this->params['posts_favoris']);
  1947.     //epingle
  1948.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1949.     return $this->render('Nordinfo/Main/profile.html.twig'$this->params);
  1950.   }
  1951.   private function getCaptcha(): mixed
  1952.   {
  1953.     $captchaCh = [012345678910];
  1954.     $captchaLe = ["zéro""un""deux""trois""quatre""cinq""six""sept""huit""neuf""dix"];
  1955.     $testcap array_merge($captchaCh$captchaLe);
  1956.     $rnd array_rand($testcap2);
  1957.     $i1 $rnd[0];
  1958.     if ($rnd[0] >= 11) {
  1959.       $i1 $rnd[0] - 11;
  1960.     }
  1961.     $i2 $rnd[1];
  1962.     if ($rnd[1] >= 11) {
  1963.       $i2 $rnd[1] - 11;
  1964.     }
  1965.     $capp = ["valeur1" => ["libelle" => $testcap[$rnd[0]], "valeur" => $captchaCh[$i1]], "valeur2" => ["libelle" => $testcap[$rnd[1]], "valeur" => $captchaCh[$i2]]];
  1966.     return $capp;
  1967.   }
  1968.   #[Route(path'/proposer-un-evenement'name'proposer_event')]
  1969.   public function proposerEvent(Request $request): Response
  1970.   {
  1971.     $this->params['referer'] = $request->headers->get('referer');
  1972.     $this->params['types'] = $this->em->getRepository(EventType::class)->findAll();
  1973.     $communes $this->em->getRepository(Cantons::class)->getCommunes();
  1974.     $villes = [];
  1975.     foreach ($communes as $cc) {
  1976.       $villes array_merge(array_map('trim'explode(',', (string)$cc['communes'])), $villes);
  1977.     }
  1978.     asort($villes);
  1979.     $this->params['villes'] = $villes;
  1980.     $this->params['caps'] = $this->getCaptcha();
  1981.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1982.     return $this->render('Nordinfo/Main/proposerevent.html.twig'$this->params);
  1983.   }
  1984.   #[Route(path'/support'name'signaler')]
  1985.   public function signaler(Request $request): Response
  1986.   {
  1987.     $this->params['referer'] = $request->headers->get('referer');
  1988.     $this->params['types_support'] = $this->em->getRepository(TypeSupport::class)->findAll();
  1989.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'contact');
  1990.     $this->params['objet'] = null;
  1991.     if ($request->query->get('objet') != null) {
  1992.       $this->params['objet'] = 4;
  1993.     }
  1994.     $this->params['caps'] = $this->getCaptcha();
  1995.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  1996.     $this->params['thematiques'] = $this->em->getRepository(FormulaireThematique::class)->findBy(['bool_info' => 1], ['name' => 'ASC']);
  1997.     return $this->render('Nordinfo/Main/signaler.html.twig'$this->params);
  1998.   }
  1999.   #[Route(path'/organisations/{type}'name'search_organisation')]
  2000.   public function searchorganisations(Request $request$type): Response
  2001.   {
  2002.     return $this->organisations($request$type);
  2003.   }
  2004.   #[Route(path'/search-organisations/{type}'name'organisations')]
  2005.   public function organisations(Request $request$type): Response
  2006.   {
  2007.     $this->params['type_'] = $type;
  2008.     $to $this->em->getRepository(TypeOrganisation::class)->findOneByName($type);
  2009.     $this->params['title'] = $to->getTitreListe();
  2010.     $id_type $to->getId();
  2011.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'liste des organisations'true);
  2012.     $this->params['referer'] = $request->headers->get('referer');
  2013.     $filter_title null;
  2014.     $search $request->query->get('search');
  2015.     $search_id null;
  2016.     $this->params['is_search'] = 0;
  2017.     $uri_path parse_url($request->getUri(), PHP_URL_PATH);
  2018.     $uri_segments explode('/'$uri_path);
  2019.     $uri_segment_filter urldecode($uri_segments[2]);
  2020.     if ($request->query->get('territoire_id') != "") {
  2021.       $search null;
  2022.       $search_id $request->query->get('territoire_id');
  2023.       $territory $this->em->getRepository(Territory::class)->find($request->query->get('territoire_id'));
  2024.       $filter_title 'Résultats pour ' $territory->getDisplayName();
  2025.       $this->params['is_search'] = 1;
  2026.     } else if ($uri_segment_filter != '') {
  2027.       $search_id null;
  2028.       $filter_title ' résultats pour "' $uri_segment_filter '"';
  2029.       $this->params['is_search'] = 1;
  2030.     }
  2031.     $this->params['contacts'] = $this->em->getRepository(Organization::class)->getOrganisations_($id_type$search$search_id);
  2032.     $this->params['territoires'] = $this->em->getRepository(Territory::class)->findAll();
  2033.     $this->params['filter_title'] = ($filter_title != null) ? (is_countable($this->params['contacts']) ? count($this->params['contacts']) : 0) . $filter_title null;
  2034.     //epingle
  2035.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2036.     return $this->render('Nordinfo/Main/organisations.html.twig'$this->params);
  2037.   }
  2038.   #[Route(path'/search-contacts'name'search_contact')]
  2039.   public function search_contacts(Request $request): Response
  2040.   {
  2041.     return $this->contacts($request);
  2042.   }
  2043.   #[Route(path'/contacts'name'contacts')]
  2044.   public function contacts(Request $request): Response
  2045.   {
  2046.     $this->params['referer'] = $request->headers->get('referer');
  2047.     $this->params['cantons'] = $this->em->getRepository(Cantons::class)->findAll();
  2048.     $search null;
  2049.     $search_id null;
  2050.     $filter_title null;
  2051.     $this->params['is_search'] = 0;
  2052.     if ($request->query->get('canton_id') != "") {
  2053.       $search null;
  2054.       $search_id $request->query->get('canton_id');
  2055.       $this->params['is_search'] = 1;
  2056.       $canton $this->em->getRepository(Cantons::class)->find($request->query->get('canton_id'));
  2057.       $filter_title ' résultats pour "' $canton->getCanton() . '"';
  2058.     } else if ($request->query->get('search') != "") {
  2059.       $search $request->query->get("search");
  2060.       $search_id null;
  2061.       $this->params['is_search'] = 1;
  2062.       $filter_title ' résultats pour "' $search '"';
  2063.     }
  2064.     $this->params['breadcrumb'] = $this->setBreadCrumb(null'contacts et élus'true);
  2065.     $this->params['contacts'] = $this->em->getRepository(Contact::class)->getContacts_(1$search$search_id);
  2066.     $this->params['filter_title'] = ($filter_title != null) ? (is_countable($this->params['contacts']) ? count($this->params['contacts']) : 0) . $filter_title null;
  2067.     //epingle
  2068.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2069.     return $this->render('Nordinfo/Main/contacts.html.twig'$this->params);
  2070.   }
  2071.   #[Route(path'/apercu-feedback'name'feedback')]
  2072.   public function feedback(Request $request): Response
  2073.   {
  2074.     $this->params['referer'] = $request->headers->get('referer');
  2075.     return $this->render('Nordinfo/Main/feedback.html.twig'$this->params);
  2076.   }
  2077.   #[Route(path'/inviter-a-commenter/{id}'name'invite_comment_post')]
  2078.   public function inviteToComment(mixed $id): Response
  2079.   {
  2080.     $this->params['post'] = $this->em->getRepository(Post::class)->find($id);
  2081.     $this->params['id'] = $id;
  2082.     $this->params['users_agent'] = $this->em->getRepository(User::class)->getUsersComment();
  2083.     return $this->render('Admin/comment_invite.html.twig'$this->params);
  2084.   }
  2085.   #[Route(path'/send-invite-comment/{id}'name'send_invitation_comment')]
  2086.   public function sendInviteToComment(Request $request$id): RedirectResponse
  2087.   {
  2088.     $user $this->getUser();
  2089.     $post $request->request;
  2090.     //Mail
  2091.     $date date_create_from_format('d/m/Y'$post->get('date'));
  2092.     //Interne
  2093.     if ($post->get('emails_interne') != null && !empty($post->get('emails_interne'))) {
  2094.       foreach ((array)$post->get('emails_interne') as $user_id) {
  2095.         $user $this->em->getRepository(User::class)->find($user_id);
  2096.         $destinataire = [];
  2097.         array_push($destinataire, ['email' => $user->getEmail(), 'name' => $user->getEmail()]);
  2098.         //Envoi email
  2099.         $article $this->em->getRepository(Post::class)->find($id);
  2100.         $token base64_encode(random_bytes(60));
  2101.         $token str_replace(["+""/"], '_'$token);
  2102.         $doit_valider $post->get('doit_valider');
  2103.         $com = new PostCommentaires;
  2104.         $com
  2105.           ->setPost($article)
  2106.           ->setDate($date)
  2107.           ->setAuteur($user->getEmail())
  2108.           ->setToken($token)
  2109.           ->setDoitValider(($doit_valider != null) ? $doit_valider false)
  2110.           ->setValide(false);
  2111.         $this->em->persist($com);
  2112.         //date url titre 
  2113.         $url $this->generateUrl('comment_post', ['token' => $token]);
  2114.         $content_mail $this->renderView(
  2115.           'Nordinfo/Mails/commentaire_invite.html.twig',
  2116.           ['texte_email' => $post->get('texte_email'), 'image' => $article->getIllustrationfilName(), 'titre' => $article->getTitle(), 'date' => $date'url' => 'https://' $request->getHost() . $url]
  2117.         );
  2118.         $this->sendgrid_service->send([$user->getEmail()], $content_mail"Nordinfo : Invitation à commenter");
  2119.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Nordinfo : Invitation à commenter');
  2120.       }
  2121.     }
  2122.     //Externe
  2123.     if ($post->get('emails') != null) {
  2124.       $dests explode(';'$post->get('emails'));
  2125.       foreach ($dests as $str) {
  2126.         $destinataire = [];
  2127.         array_push($destinataire, ['email' => $str'name' => $str]);
  2128.         //Envoi email
  2129.         $article $this->em->getRepository(Post::class)->find($id);
  2130.         $token base64_encode(random_bytes(60));
  2131.         $token str_replace(["+""/"], '_'$token);
  2132.         $doit_valider $post->get('doit_valider');
  2133.         $com = new PostCommentaires;
  2134.         $com
  2135.           ->setPost($article)
  2136.           ->setDate($date)
  2137.           ->setAuteur($str)
  2138.           ->setToken($token)
  2139.           ->setDoitValider(($doit_valider != null) ? $doit_valider false)
  2140.           ->setValide(false);
  2141.         $this->em->persist($com);
  2142.         //date url titre 
  2143.         $url $this->generateUrl('comment_post', ['token' => $token]);
  2144.         $content_mail $this->renderView(
  2145.           'Nordinfo/Mails/commentaire_invite.html.twig',
  2146.           ['texte_email' => $post->get('texte_email'), 'image' => $article->getIllustrationfilName(), 'titre' => $article->getTitle(), 'date' => $date'url' => 'https://' $request->getHost() . $url]
  2147.         );
  2148.         $this->sendgrid_service->send([$str], $content_mail"Nordinfo : Invitation à commenter");
  2149.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataire, $content_mail, 'Nordinfo : Invitation à commenter');
  2150.       }
  2151.     }
  2152.     $this->em->flush();
  2153.     $url '/console2020/?entity=Article&action=list';
  2154.     return $this->redirect($url);
  2155.   }
  2156.   public function importXls(): void
  2157.   {
  2158.     $path $this->get('kernel')->getRootDir() . '/../';
  2159.     $file $path 'mdie.xls';
  2160.     $fileType IOFactory::identify($file);
  2161.     $l 0;
  2162.     $reader IOFactory::createReader($fileType);
  2163.     $spreadsheet $reader->load($file);
  2164.     $datas $spreadsheet->getSheet(0)->toArray(nulltruetruetrue);
  2165.     foreach ($datas as $d) {
  2166.       $l++;
  2167.       if ($l 1) {
  2168.         if ($d['C'] == "") {
  2169.           break;
  2170.         }
  2171.         $type $this->em->getRepository(TypeOrganisation::class)->find(6);
  2172.         $territory $this->em->getRepository(Territory::class)->find($d['K']);
  2173.         $organisation = new Organization;
  2174.         $organisation->setTitle($d['C'])
  2175.           ->setSubtitle($d['D'])
  2176.           ->setEmail($d['M'])
  2177.           ->setPhone($d['N'])
  2178.           ->setAcceo($d['O'])
  2179.           ->setCodePostal($d['J'])
  2180.           ->setRue($d['H'])
  2181.           ->setVille($d['I'])
  2182.           ->setTypeOrganisation($type)
  2183.           ->setTerritory($territory);
  2184.         $this->em->persist($organisation);
  2185.       }
  2186.       echo $l '\r\n';
  2187.     }
  2188.     $this->em->flush();
  2189.   }
  2190.   /*
  2191.   #[Route(path: '/console2020/ckfinder', name: 'ckfinder')]
  2192.   public function ckfinder(): Response
  2193.   {
  2194.     return $this->render('/Main/ckfinder.html.twig');
  2195.   }
  2196.   */
  2197.   #[Route(path'/ics'name'ics_download')]
  2198.   public function downloadics(Request $request): Response
  2199.   {
  2200.     $post $request->request;
  2201.     $date_start date_create_from_format('d/m/Y'$post->get('date_start'))->setTime(1000);
  2202.     $date_end date_create_from_format('d/m/Y'$post->get('date_end'))->setTime(1800);
  2203.     $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')]);
  2204.     $filename $post->get('summary') . '.ics';
  2205.     $response = new Response($ics->to_string());
  2206.     $response->headers->set('charset''utf-8');
  2207.     $response->headers->set('Content-Type''text/calendar');
  2208.     $response->headers->set('Content-Disposition''attachment');
  2209.     $response->headers->set('filename'$filename);
  2210.     return $response;
  2211.   }
  2212.   #[Route(path'/sitemap'name'sitemap')]
  2213.   public function sitemap(Request $request): Response
  2214.   {
  2215.     $urls = [];
  2216.     $this->params['page_title'] = "Plan du site";
  2217.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2218.     $this->params['referer'] = $request->headers->get('referer');
  2219.     $urls['index']['parent']['url'] = $this->generateUrl('index');
  2220.     $urls['index']['parent']['name'] = "Accueil";
  2221.     $j 0;
  2222.     $urls['fil']['parent']['url'] = "";
  2223.     $urls['fil']['parent']['name'] = "Actus";
  2224.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('info');
  2225.     $urls['fil']['children'][$j]['name'] = "Mes actus";
  2226.     $j++;
  2227.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('info');
  2228.     $urls['fil']['children'][$j]['name'] = "L'info";
  2229.     $j++;
  2230.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('agenda');
  2231.     $urls['fil']['children'][$j]['name'] = "Agenda";
  2232.     $j++;
  2233.     $urls['fil']['children'][$j]['url'] = $this->generateUrl('videos');
  2234.     $urls['fil']['children'][$j]['name'] = "Vidéos";
  2235.     $urls['custom']['parent']['url'] = "";
  2236.     $urls['custom']['parent']['name'] = "Personnalisation";
  2237.     $j 0;
  2238.     $urls['custom']['children'][$j]['url'] = $this->generateUrl('favoris');;
  2239.     $urls['custom']['children'][$j]['name'] = "Favoris";
  2240.     $j++;
  2241.     $urls['custom']['children'][$j]['url'] = $this->generateUrl('vos_lieux');;
  2242.     $urls['custom']['children'][$j]['name'] = "Mes lieux de vie";
  2243.     $j++;
  2244.     $urls['custom']['children'][$j]['url'] = $this->generateUrl('topics');;
  2245.     $urls['custom']['children'][$j]['name'] = "Mes centres d'intérêt";
  2246.     $urls['departement']['parent']['url'] = $this->generateUrl('departement');
  2247.     $urls['departement']['parent']['name'] = "Le département";
  2248.     $j 0;
  2249.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('page', ['slug' => "le-territoire"]);
  2250.     $urls['departement']['children'][$j]['name'] = "Le territoire";
  2251.     $j++;
  2252.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('page', ['slug' => "les-competences"]);
  2253.     $urls['departement']['children'][$j]['name'] = "Les compétences";
  2254.     $j++;
  2255.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('page', ['slug' => "le-conseil-departemental"]);
  2256.     $urls['departement']['children'][$j]['name'] = "L'institution";
  2257.     $j++;
  2258.     $urls['departement']['children'][$j]['url'] = $this->generateUrl('contacts');
  2259.     $urls['departement']['children'][$j]['name'] = "Les cantons et leurs élus";
  2260.     $j++;
  2261.     $types $this->em->getRepository(TypeOrganisation::class)->findAll();
  2262.     foreach ($types as $type) {
  2263.       $urls['departement']['children'][$j]['url'] = $this->generateUrl('organisations', ['type' => $type->getName()]);
  2264.       $urls['departement']['children'][$j]['name'] = $type->getTitreListe();
  2265.       $j++;
  2266.     }
  2267.     $urls['legal']['parent']['url'] = "";
  2268.     $urls['legal']['parent']['name'] = "Pages légales";
  2269.     $j 0;
  2270.     $urls['legal']['children'][$j]['url'] = $this->generateUrl('post_detail', ['slug' => 'mentions-legales-nordinfo']);
  2271.     $urls['legal']['children'][$j]['name'] = "Mentions légales";
  2272.     $j++;
  2273.     $urls['legal']['children'][$j]['url'] = $this->generateUrl('post_detail', ['slug' => 'cgu']);
  2274.     $urls['legal']['children'][$j]['name'] = "Conditions générales";
  2275.     $j++;
  2276.     $urls['legal']['children'][$j]['url'] = $this->generateUrl('post_detail', ['slug' => 'accessibilite-nordinfo']);
  2277.     $urls['legal']['children'][$j]['name'] = "Accessibilité";
  2278.     $urls['form']['parent']['url'] = "";
  2279.     $urls['form']['parent']['name'] = "Support";
  2280.     $j 0;
  2281.     $urls['form']['children'][$j]['url'] = $this->generateUrl('signaler');;
  2282.     $urls['form']['children'][$j]['name'] = "Contact";
  2283.     $urls['sitemap_page']['parent']['url'] = $this->generateUrl('sitemap');
  2284.     $urls['sitemap_page']['parent']['name'] = 'Plan du site';
  2285.     $this->params['urls'] = $urls;
  2286.     return $this->render('Nordinfo/Main/sitemap.html.twig'$this->params);
  2287.   }
  2288.   #[Route(path'/sitemap.xml'name'nordinfo_plandusite_xml')]
  2289.   public function services_plandusite_xml(): Response
  2290.   {
  2291.     $domain "https://info.lenord.fr";
  2292.     $dom = new \DOMDocument('1.0''UTF-8');
  2293.     $rss $dom->createElement('urlset');
  2294.     $rss->setAttribute('xmlns''http://www.sitemaps.org/schemas/sitemap/0.9');
  2295.     $rss_node $dom->appendChild($rss);
  2296.     $url $dom->createElement('url');
  2297.     $url_node $rss_node->appendChild($url);
  2298.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('index')));
  2299.     $url $dom->createElement('url');
  2300.     $url_node $rss_node->appendChild($url);
  2301.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('info')));
  2302.     $url $dom->createElement('url');
  2303.     $url_node $rss_node->appendChild($url);
  2304.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('info')));
  2305.     $url $dom->createElement('url');
  2306.     $url_node $rss_node->appendChild($url);
  2307.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('agenda')));
  2308.     $url $dom->createElement('url');
  2309.     $url_node $rss_node->appendChild($url);
  2310.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('videos')));
  2311.     $url $dom->createElement('url');
  2312.     $url_node $rss_node->appendChild($url);
  2313.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('favoris')));
  2314.     $url $dom->createElement('url');
  2315.     $url_node $rss_node->appendChild($url);
  2316.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('vos_lieux')));
  2317.     $url $dom->createElement('url');
  2318.     $url_node $rss_node->appendChild($url);
  2319.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('topics')));
  2320.     $url $dom->createElement('url');
  2321.     $url_node $rss_node->appendChild($url);
  2322.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('departement')));
  2323.     $url $dom->createElement('url');
  2324.     $url_node $rss_node->appendChild($url);
  2325.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('page', ['slug' => "le-territoire"])));
  2326.     $url $dom->createElement('url');
  2327.     $url_node $rss_node->appendChild($url);
  2328.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('page', ['slug' => "les-competences"])));
  2329.     $url $dom->createElement('url');
  2330.     $url_node $rss_node->appendChild($url);
  2331.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('page', ['slug' => "le-conseil-departemental"])));
  2332.     $url $dom->createElement('url');
  2333.     $url_node $rss_node->appendChild($url);
  2334.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('contacts')));
  2335.     $types $this->em->getRepository(TypeOrganisation::class)->findAll();
  2336.     foreach ($types as $type) {
  2337.       $url $dom->createElement('url');
  2338.       $url_node $rss_node->appendChild($url);
  2339.       $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('organisations', ['type' => $type->getName()])));
  2340.     }
  2341.     //Posts
  2342.     $posts $this->em->getRepository(Post::class)->findBy(['status' => 5]);
  2343.     $date = new DateTime();
  2344.     foreach ($posts as $post) {
  2345.       if ($post->getSlug() != null) {
  2346.         $date_update date_create_from_format('Y-m-d H:i:s'$post->getDateDernierStatut());
  2347.         $date_update = ($date_update != false) ? $date_update->format('Y-m-d') : $date->format('Y-m-d');
  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' => $post->getSlug(), 'archive' => false])));
  2351.         //$url_node->appendChild($dom->createElement('lastmod', $post->getDateUpdate()->format('Y-m-d')));
  2352.         $url_node->appendChild($dom->createElement('changefreq''monthly'));
  2353.         $url_node->appendChild($dom->createElement('lastmod'$date_update));
  2354.       }
  2355.     }
  2356.     $url $dom->createElement('url');
  2357.     $url_node $rss_node->appendChild($url);
  2358.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('post_detail', ['slug' => 'mentions-legales-nordinfo'])));
  2359.     $url $dom->createElement('url');
  2360.     $url_node $rss_node->appendChild($url);
  2361.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('post_detail', ['slug' => 'cgu'])));
  2362.     $url $dom->createElement('url');
  2363.     $url_node $rss_node->appendChild($url);
  2364.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('post_detail', ['slug' => 'accessibilite-nordinfo'])));
  2365.     $url $dom->createElement('url');
  2366.     $url_node $rss_node->appendChild($url);
  2367.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('signaler')));
  2368.     $url $dom->createElement('url');
  2369.     $url_node $rss_node->appendChild($url);
  2370.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('sitemap')));
  2371.     $xml $dom->saveXML();
  2372.     $response = new Response($xml);
  2373.     $response->headers->set('Content-Type''text/xml');
  2374.     $response->headers->set('Access-Control-Allow-Origin''*');
  2375.     return $response;
  2376.   }
  2377.   #[Route(path'/console2021/apercu/{id}'name'apercu_post')]
  2378.   public function apercu_post(Request $requestmixed $id): Response
  2379.   {
  2380.     $this->params['actus'] = false;
  2381.     $this->params['admin'] = true;
  2382.     $this->params['favorite'] = false;
  2383.     $this->params['referer'] = $request->headers->get('referer');
  2384.     $post $this->em->getRepository(Post::class)->findOneBy(['slug' => $id]);
  2385.     $this->params['short_description'] = $post?->getShortDescription();
  2386.     $this->params['is_preview'] = true;
  2387.     $content_post null;
  2388.     if ($post?->getContent() !== null) {
  2389.       $content_post $this->feedUtilities->jsonToHtml($post?->getContent(), $request);
  2390.     }
  2391.     if ($post?->getType()?->getType() === 'folder') {
  2392.       $this->params['related_posts'] = $post?->getRelatedPosts();
  2393.       $this->params['related_posts'] = $this->feedUtilities->social_posts_padding($this->params['related_posts'], $request);
  2394.     } else {
  2395.       $this->params['related_posts'] = $this->getRelatedPosts($post);
  2396.     }
  2397.     $this->params['content_post'] = $content_post;
  2398.     $this->params['post'] = $post;
  2399.     
  2400.     if ($post?->getType()?->getType() === 'folder') {
  2401.       $k 0;
  2402.       foreach ($this->params['related_posts'] as $p) {
  2403.         $this->params['related_posts'][$k]->str_date $this->formatJsonDate($p->getJson());
  2404.         $k++;
  2405.       }
  2406.       return $this->render('Nordinfo/Main/detail_folder.html.twig'$this->params);
  2407.     }
  2408.     $url $post?->getSubtitle();
  2409.     if ($post?->getType()?->getType() === "video") {
  2410.       $this->params['youtube_video_id'] = $url;
  2411.     }
  2412.     if ($post?->getType()?->getType() === "event") {
  2413.       $json_convert_dates $this->formatDateAgendaJson($post?->getJson());
  2414.       $this->params['ics_date_debut'] = $json_convert_dates['ics_date_debut'];
  2415.       $this->params['ics_date_fin'] = $json_convert_dates['ics_date_fin'];
  2416.       $this->params['event_date'] = $json_convert_dates['date_string'];
  2417.       $this->params['event_heures'] = $json_convert_dates['heure_string'];
  2418.       $this->params['event_lieu'] = null;
  2419.       $this->params['event_ville'] = null;
  2420.       $this->params['event_adresse'] = null;
  2421.     }
  2422.     if ($post?->getType()?->getType() === 'pub' || $post?->getType()?->getType() === 'socialpost') {
  2423.       return new Response("Pas d'aperçu possible pour ce type de post");
  2424.     }
  2425.     return $this->render('Nordinfo/Main/detail_post.html.twig'$this->params);
  2426.   }
  2427.   
  2428.   #[Route(path'/send_form_custom/{alias}'name'send_form_custom_info'host"info.lenord.fr")]
  2429.   public function send_form_custom(Request $requeststring $alias): Response
  2430.   {
  2431.     $post $request->request;
  2432.     $custom_form $this->em->getRepository(CustomForm::class)->findOneBy(array('alias' => $alias));
  2433.     $destinataires_sendgrid = [];
  2434.     $objet null;
  2435.     $objet "Votre message à " $custom_form->getDestinataire() . " via le site Nord info";
  2436.     $emails explode(";", (string)$custom_form->getEmail());
  2437.     for ($i 0$i count($emails); $i++) {
  2438.       array_push($destinataires_sendgrid$emails[$i]);
  2439.     }
  2440.     $message $post->get('message');
  2441.     //exp
  2442.     //destinataire_
  2443.     //objet_
  2444.     //message_
  2445.     //piece_jointe_
  2446.     $fileName null;
  2447.     $auth_extension = ['png''jpg''jpeg''gif''pdf'];
  2448.     $mime_authorized = ['application/pdf''image/jpg''image/jpeg''image/gif''image/png'];
  2449.     $file null;
  2450.     $newname uniqid();
  2451.     if ($request->files != null && $request->files->get('file') != null) {
  2452.       $file $request->files->get('file');
  2453.       $fileName $file->getClientOriginalName();
  2454.       $fileType $file->getClientMimeType();
  2455.       if (in_array($file->guessExtension(), $auth_extension) && in_array($fileType$mime_authorized)) {
  2456.         try {
  2457.           /*$file->move($uploadDir, $newname.'.'.$file->guessExtension());
  2458.           array_push($files, array(
  2459.             'name' => $newname.'.'.$file->guessExtension(),
  2460.             'type' => $fileType,
  2461.             'data' => $fileData,
  2462.           ));*/
  2463.         } catch (FileException) {
  2464.           $file null;
  2465.           return new JsonResponse(['error' => 'File could not be uploaded']);
  2466.         }
  2467.       } else {
  2468.         $file null;
  2469.         return new JsonResponse(['error' => "Mauvais format d'image"]);
  2470.       }
  2471.     }
  2472.     $date = new DateTime;
  2473.     $content "Le message suivant vient de vous être envoyé via le site Nord info par " $post->get('nom_prenom') .
  2474.       " - Merci de répondre directement à " $post->get('email') . " : " "\n" $post->get('message') . "\n\n" "Nord, le Département est là - https://info.lenord.fr/";
  2475.     $nom_dest $custom_form->getDestinataire();
  2476.     $content_exp "Bonjour, votre message a été transmis à " $nom_dest "." "\n\n" .
  2477.       "Message : " $post->get('message');
  2478.     if ($fileName !== null) {
  2479.       $content_exp .= "\n" "Pièce jointe : " $fileName;
  2480.     }
  2481.     $content_exp .= "\n\n" "Nord, le Département est là - https://info.lenord.fr/";
  2482.     /*$content_exp = $this->renderView(
  2483.       'Nordinfo/Mails/exp_signalement_custom.html.twig',
  2484.       ['destinataire_' => $nom_dest, 'objet_' => $objet, 'message_' => $message, 'piece_jointe_' => ($fileName != null) ? $fileName : "Aucune pièce jointe", 'date' => "NI".$date->format('dmYHis')]
  2485.     );*/
  2486.     //envoi mail
  2487.     $result_ $post->get('nb1') + $post->get('nb2');
  2488.     if ($result_ == $post->get('captcha') && $post->get('raison') == null) {
  2489.       try {
  2490.         //$this->sendMail($content, 'Demande de contact depuis nordinfo : ' . $objet, $destinataires, $files);
  2491.         //FILES!
  2492.         $this->sendgrid_service->send($destinataires_sendgrid$content"Message envoyé par " $post->get('nom_prenom') . " via le site Nord info"null$filefalse$post->get('email'));
  2493.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $destinataires, $content, 'Demande de contact depuis nordinfo : ' . $objet);
  2494.         $this->sendgrid_service->send([$post->get('email')], $content_exp$objetnull$filefalse);
  2495.         //$this->mail_service->sendTransacEmail('nordinfo@info-lenord.fr', 'Nord info contact', $post->get('email'), $content_exp, "Nord info - Envoi d’un message ");
  2496.       } catch (Exception) {
  2497.         $this->params['message'] = 'Email erreur';
  2498.         return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  2499.       }
  2500.     } else {
  2501.       $this->params['message'] = 'Catcha erreur';
  2502.       return $this->render('Nordinfo/Main/endformerror.html.twig'$this->params);
  2503.     }
  2504.     return $this->render('Nordinfo/Main/endform.html.twig'$this->params);
  2505.   }
  2506.   #[Route(path'/{slug}'name'post_detail')]
  2507.   public function detail_post(Request $requeststring $slug): Response
  2508.   {
  2509.     if ($request->get('function') === 'download_pdf') {
  2510.       $this->params['is_pdf'] = 1;
  2511.     }
  2512.     $post $this->em->getRepository(Post::class)->findOneBy(['slug' => $slug]);
  2513.     if ($post === null) {
  2514.       return $this->pagelegales($request$slug);
  2515.     }
  2516.     if ($post->getArchive() === true) {
  2517.       return $this->error($request);
  2518.     }
  2519.     $presse false;
  2520.     $vip false;
  2521.     $agent false;
  2522.     $topics_list null;
  2523.     foreach ($post->getTargetpublics() as $topic) {
  2524.       if ($topic->getId() == 3) {
  2525.         $presse true;
  2526.       }
  2527.       if ($topic->getId() == 2) {
  2528.         $vip true;
  2529.       }
  2530.       if ($topic->getId() == 4) {
  2531.         $agent true;
  2532.       }
  2533.       $topics_list .= ($topics_list != null) ? ', ' '';
  2534.       $topics_list .= $topic->getName();
  2535.     }
  2536.     if ($post->getStatus()?->getId() !== 5) {
  2537.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2538.     }
  2539.     if ($post->getType()?->getId() === && $this->getUser() == null) {
  2540.       return $this->redirect($this->generateUrl('info'));
  2541.     }
  2542.     if ($presse && ($this->getUser() == null || $this->getUser()->getRole() != 'presse')) {
  2543.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2544.     }
  2545.     if ($vip && ($this->getUser() == null || $this->getUser()->getRole() != 'vip')) {
  2546.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2547.     }
  2548.     if ($agent && ($this->getUser() == null || $this->getUser()->getRole() != 'agent')) {
  2549.       return $this->redirectToRoute('error', ['_format' => 'html''code' => '404']);
  2550.     }
  2551.     $this->params['referer'] = $request->headers->get('referer');
  2552.     $this->params['post'] = $post;
  2553.     $content_post null;
  2554.     if ($post->getContent() != null) {
  2555.       $content_post $this->feedUtilities->jsonToHtml($post->getContent(), $request$post->getTitle());
  2556.     }
  2557.     $this->params['short_description'] = $post->getSubtitle();
  2558.     $url $post->getSubtitle();
  2559.     if ($post->getType()->getType() === "video") {
  2560.       $this->params['youtube_video_id'] = $url;
  2561.     }
  2562.     $this->params['breadcrumb'] = $this->setBreadCrumb($post);
  2563.     $this->params['content_post'] = $content_post;
  2564.     $this->params['favorite'] = $this->isFavorite($post$this->getUser(), $request);
  2565.     if ($post->getType()?->getType() === 'folder') {
  2566.       $iterator $post->getRelatedPosts()->getIterator();
  2567.       $iterator->uasort(fn ($a$b) => ($a->getOrderFolder() > $b->getOrderFolder()) ? -1);
  2568.       $rarray = [];
  2569.       $array = new ArrayCollection(iterator_to_array($iterator));
  2570.       foreach ($array as $po) {
  2571.         $rarray[] = $po;
  2572.       }
  2573.       $this->params['related_posts'] = $rarray;
  2574.     } else {
  2575.       $this->params['related_posts'] = $this->getRelatedPosts($post);
  2576.     }
  2577.     $this->params['related_posts'] = $this->feedUtilities->checkboxes_get_description($this->params['related_posts'], $request);
  2578.     $this->params['related_posts'] = $this->feedUtilities->social_posts_padding($this->params['related_posts'], $request);
  2579.     $this->params['related_posts'] = $this->feedUtilities->social_posts_detect_links($this->params['related_posts']);
  2580.     $this->params['related_posts'] = $this->feedUtilities->focus_pub_img_dimensions($this->params['related_posts'], $request);
  2581.     $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];
  2582.     $this->params['twitter_card'] = ["card" => "summary""site" => "@info.lenord.fr"];
  2583.     $this->params['articleSchema'] = [];
  2584.     $this->params['placement_image'] = 'placement2';
  2585.     if ($post->getType()?->getType() === 'event') {
  2586.       $json_convert_dates $this->formatDateAgendaJson($post->getJson());
  2587.       $this->params['ics_date_debut'] = $json_convert_dates['ics_date_debut'];
  2588.       $this->params['ics_date_fin'] = $json_convert_dates['ics_date_fin'];
  2589.       $this->params['event_date'] = $json_convert_dates['date_string'];
  2590.       $this->params['event_heures'] = $json_convert_dates['heure_string'];
  2591.       $this->params['event_lieu'] = null;
  2592.       $this->params['event_ville'] = null;
  2593.       if ($post->getLieuNew() !== null) {
  2594.         $this->params['event_lieu'] = $post->getLieuNew()->getName();
  2595.         $this->params['event_ville'] = $post->getLieuNew()->getVille();
  2596.       }
  2597.       $this->params['event_adresse'] = null;
  2598.       $date_debut null;
  2599.       $date_fin null;
  2600.       $start_date null;
  2601.       $end_date null;
  2602.       if ($post->getDateDebut() !== null) {
  2603.         $date_debut date_create_from_format('d/m/Y'$post->getDateDebut());
  2604.         $start_date $date_debut->format('c');
  2605.       }
  2606.       if ($post->getDateFin() !== null) {
  2607.         $date_fin date_create_from_format('d/m/Y'$post->getDateFin());
  2608.         $end_date $date_fin->format('c');
  2609.       }
  2610.       $schema_params = [
  2611.         'startDate' => $start_date,
  2612.         'endDate' => $end_date,
  2613.         'inLanguage' => 'FR',
  2614.         'isAccessibleForFree' => ($post->getTarifs() != null) ? true false,
  2615.         'location' => $post->getLieu() . ' ' $post->getVille(),
  2616.         'organizer' => $post->getOrganizedBy(),
  2617.         'name' => $post->getTitle(),
  2618.         'description' => $content_post,
  2619.         'image' => "https:/info.lenord.fr/upload/images/" $post->getIllustrationFilName(),
  2620.         //'sameAs'
  2621.         'url' => "https:/info.lenord.fr/" $post->getSlug(),
  2622.       ];
  2623.       $this->params['articleSchema'] = $this->schema_service->generateSchema($schema_params'Event');
  2624.     } else {
  2625.       $currentRoute $request->attributes->get('_route');
  2626.       $currentUrl $this->generateUrl($currentRoute, ['slug' => $slug], true);
  2627.       $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()];
  2628.       $this->params['articleSchema'] = $this->schema_service->generateSchema($schema_params'NewsArticle');
  2629.     }
  2630.     //epingle
  2631.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2632.     if ($request->get('function') === 'download_pdf') {
  2633.       $pdfOptions = new Options();
  2634.       $pdfOptions->set('defaultFont''Arial');
  2635.       $pdfOptions->setIsRemoteEnabled(true);
  2636.       $dompdf = new Dompdf($pdfOptions);
  2637.       $html $this->renderView('Nordinfo/Main/detail_post.html.twig'$this->params);
  2638.       $dompdf->loadHtml($html);
  2639.       $dompdf->setPaper('A4''portrait');
  2640.       $dompdf->render();
  2641.       $output $dompdf->output();
  2642.       $filename sprintf('nord-info-%s.pdf'$post->getTitle());
  2643.       return new Response(
  2644.         $output,
  2645.         200,
  2646.         [
  2647.           'Content-Type' => 'application/pdf',
  2648.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  2649.         ]
  2650.       );
  2651.     } else {
  2652.       if ($post->getPositionImage() !== null && $post->getPositionImage()?->getId() === 1) {
  2653.         $this->params['placement_image'] = 'placement1';
  2654.       } else if ($post->getPositionImage()?->getId() === 3) {
  2655.         $this->params['placement_image'] = 'placement3';
  2656.       }
  2657.       if ($post->getType()->getType() == 'folder') {
  2658.         $k 0;
  2659.         foreach ($this->params['related_posts'] as $p) {
  2660.           $this->params['related_posts'][$k]->str_date $this->formatJsonDate($p->getJson());
  2661.           $k++;
  2662.         }
  2663.         return $this->render('Nordinfo/Main/detail_folder.html.twig'$this->params);
  2664.       }
  2665.       return $this->render('Nordinfo/Main/detail_post.html.twig'$this->params);
  2666.     }
  2667.   }
  2668.   private function formatJsonDate(mixed $json): mixed
  2669.   {
  2670.     $str_date null;
  2671.     $current_date = new DateTime();
  2672.     $current_date->setTime(000);
  2673.     $json_horaires json_decode($jsontrue);
  2674.     if ($json_horaires !== null) {
  2675.       switch ($json_horaires['modeDates']) {
  2676.         case "range":
  2677.           //de date debut a date fin
  2678.           $date_debut date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  2679.           $date_fin date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateFinish']);
  2680.           $ics_date_debut $json_horaires['datesRange']['dateStart'];
  2681.           $ics_date_fin $json_horaires['datesRange']['dateStart'];
  2682.           $evDateDebut $this->formatStringDate($date_debut);
  2683.           $evDateFin $this->formatStringDate($date_fin);
  2684.           $same_day false;
  2685.           if ($evDateDebut['day'] == $evDateFin['day']) {
  2686.             if ($evDateDebut['month'] == $evDateFin['month']) {
  2687.               $same_day true;
  2688.             }
  2689.           }
  2690.           if ($evDateDebut['day'] == || $evDateDebut['day'] == '01' || $evDateDebut['day'] == '1') {
  2691.             $day_debut $this->array_date_trad["fr"][1];
  2692.           } else {
  2693.             $day_debut $evDateDebut['day'];
  2694.           }
  2695.           if ($evDateDebut['month'] == $evDateFin['month'] && $evDateDebut['year'] == $evDateFin['year']) {
  2696.             if ($same_day) {
  2697.               //$this->translator->trans('du') . ' ' .
  2698.               $str_date $evDateFin['day'] . ' ' $evDateFin['month'];
  2699.             } else {
  2700.               $str_date 'Du ' $day_debut ' au ' $evDateFin['day'] . ' ' $evDateFin['month'];
  2701.             }
  2702.           } else {
  2703.             //check year de la date debut et fin
  2704.             if ($evDateDebut['year'] !== $evDateFin['year']) {
  2705.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' ' $evDateDebut['year'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2706.             } else {
  2707.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2708.             }
  2709.           }
  2710.           break;
  2711.         case 'multiple':
  2712.           $nombre_date 0;
  2713.           $dates_multiples = [];
  2714.           $dates $json_horaires['datesMultiple']['dates'];
  2715.           foreach ($dates as $d) {
  2716.             array_push($dates_multiples$d);
  2717.           }
  2718.           $date null;
  2719.           $array_dates $dates_multiples;
  2720.           $i 0;
  2721.           foreach ($array_dates as $d) {
  2722.             if ($i 0) {
  2723.               $str_date .= ", ";
  2724.             }
  2725.             $date date_create_from_format('d/m/Y'$dates_multiples[$i]);
  2726.             $str_date .= $date->format('d') . ' ' $this->months["fr"][$date->format('n')] . ' ' $date->format('Y');
  2727.             $i++;
  2728.           }
  2729.           break;
  2730.         case 'single':
  2731.           $start_date date_create_from_format('d/m/Y'$json_horaires['dateSingle']['dates'][0]);
  2732.           $day 'Le ' $start_date->format('d');
  2733.           $str_date .= $day;
  2734.           $str_month $this->months["fr"][$start_date->format('n')];
  2735.           $str_date .= ' ' $str_month;
  2736.           $str_date .= ' ' $start_date->format('Y');
  2737.           break;
  2738.       }
  2739.     }
  2740.     return $str_date;
  2741.   }
  2742.   public function pagelegales(Request $requeststring $slug): Response
  2743.   {
  2744.     $this->params['referer'] = $request->headers->get('referer');
  2745.     if ($slug == "comprendre-le-departement") {
  2746.       return $this->redirectToRoute('comprendre_le_departement');
  2747.     }
  2748.     $post $this->em->getRepository(PagesLegales::class)->findOneBy(['slug' => $slug'actif' => 1]);
  2749.     if(!$post){
  2750.       throw $this->createNotFoundException('La page demandée n\'existe pas.');
  2751.     }
  2752.     $this->params['post'] = $post;
  2753.     $this->params['breadcrumb'] = $this->setBreadCrumb(null$this->params['post']->getTitre());
  2754.     //epingle
  2755.     $this->params['epingles'] = $this->epingle_service->getEpingles('nordinfo');
  2756.     $epingles_ $this->epingle_service->getEpinglesSection('legales_nordinfo');
  2757.     foreach ($epingles_ as $epingle) {
  2758.       array_push($this->params['epingles'], $epingle);
  2759.     }
  2760.     if ($request->get('function') == 'download_pdf') {
  2761.       $this->params['is_pdf'] = 1;
  2762.       $pdfOptions = new Options();
  2763.       $pdfOptions->set('defaultFont''Arial');
  2764.       $pdfOptions->setIsRemoteEnabled(true);
  2765.       $dompdf = new Dompdf($pdfOptions);
  2766.       $html $this->renderView('Nordinfo/Main/detail_page_legale.html.twig'$this->params);
  2767.       $dompdf->loadHtml($html);
  2768.       $dompdf->setPaper('A4''portrait');
  2769.       $dompdf->render();
  2770.       $output $dompdf->output();
  2771.       $filename sprintf('nord-info-%s.pdf'$this->params['post']->getTitre());
  2772.       return new Response(
  2773.         $output,
  2774.         200,
  2775.         [
  2776.           'Content-Type' => 'application/pdf',
  2777.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  2778.         ]
  2779.       );
  2780.     } else {
  2781.       return $this->render('Nordinfo/Main/detail_page_legale.html.twig'$this->params);
  2782.     }
  2783.   }
  2784.   #[Route(path'/ajax/getServicesAll'name'services_ajax_getServicesAllNordInfo')]
  2785.   public function getServicesAllNordInfo(Request $request): Response
  2786.   {
  2787.     $services $this->em->getRepository(Service::class)->getServicesByGrandprofil($request->request->get('alias'));
  2788.     return new JsonResponse(['datas' => $services]);
  2789.   }
  2790.   private mixed $months = array(
  2791.     'fr' => array(
  2792.       => 'janvier',
  2793.       => 'février',
  2794.       => 'mars',
  2795.       => 'avril',
  2796.       => 'mai',
  2797.       => 'juin',
  2798.       => 'juillet',
  2799.       => 'août',
  2800.       => 'septembre',
  2801.       10 => 'octobre',
  2802.       11 => 'novembre',
  2803.       12 => 'décembre'
  2804.     ),
  2805.     'en' => array(
  2806.       => 'January',
  2807.       => 'February',
  2808.       => 'March',
  2809.       => 'April',
  2810.       => 'May',
  2811.       => 'June',
  2812.       => 'July',
  2813.       => 'August',
  2814.       => 'September',
  2815.       10 => 'October',
  2816.       11 => 'November',
  2817.       12 => 'December',
  2818.     ),
  2819.     'nl' => array(
  2820.       => 'januari',
  2821.       => 'februari',
  2822.       => 'maart',
  2823.       => 'april',
  2824.       => 'mei',
  2825.       => 'juni',
  2826.       => 'juli',
  2827.       => 'augustus',
  2828.       => 'september',
  2829.       10 => 'oktober',
  2830.       11 => 'november',
  2831.       12 => 'december'
  2832.     )
  2833.   );
  2834.   private function formatStringDate(mixed $date): mixed
  2835.   {
  2836.     if ($date instanceof DateTime) {
  2837.       return array(
  2838.         'day' => $date->format('j'),
  2839.         'month' => $this->months["fr"][$date->format('n')],
  2840.         'year' => $date->format('Y')
  2841.       );
  2842.     }
  2843.     return array(
  2844.       'day' => null,
  2845.       'month' => null,
  2846.       'year' => null
  2847.     );
  2848.   }
  2849.   private mixed $array_date_trad = array(
  2850.     'fr' => array(
  2851.       => '1er'
  2852.     ),
  2853.     'en' => array(
  2854.       => '1st'
  2855.     ),
  2856.     'nl' => array(
  2857.       => '1st'
  2858.     )
  2859.   );
  2860.   private function formatDateAgendaJson(string $json): mixed
  2861.   {
  2862.     $str_date null;
  2863.     $current_date = new DateTime();
  2864.     $current_date->setTime(000);
  2865.     $json_horaires json_decode($jsontrue);
  2866.     $ics_date_debut null;
  2867.     $ics_date_fin null;
  2868.     $str_heure null;
  2869.     if ($json_horaires !== null) {
  2870.       switch ($json_horaires['modeDates']) {
  2871.         case "range":
  2872.           //de date debut a date fin
  2873.           $date_debut date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  2874.           $date_fin date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateFinish']);
  2875.           $ics_date_debut $json_horaires['datesRange']['dateStart'];
  2876.           $ics_date_fin $json_horaires['datesRange']['dateStart'];
  2877.           $evDateDebut $this->formatStringDate($date_debut);
  2878.           $evDateFin $this->formatStringDate($date_fin);
  2879.           $same_day false;
  2880.           if ($evDateDebut['day'] == $evDateFin['day']) {
  2881.             if ($evDateDebut['month'] == $evDateFin['month']) {
  2882.               $same_day true;
  2883.             }
  2884.           }
  2885.           if ($evDateDebut['day'] == || $evDateDebut['day'] == '01' || $evDateDebut['day'] == '1') {
  2886.             $day_debut $this->array_date_trad["fr"][1];
  2887.           } else {
  2888.             $day_debut $evDateDebut['day'];
  2889.           }
  2890.           if ($evDateDebut['month'] == $evDateFin['month'] && $evDateDebut['year'] == $evDateFin['year']) {
  2891.             if ($same_day) {
  2892.               //$this->translator->trans('du') . ' ' .
  2893.               $str_date $evDateFin['day'] . ' ' $evDateFin['month'];
  2894.             } else {
  2895.               $str_date 'Du ' $day_debut ' au ' $evDateFin['day'] . ' ' $evDateFin['month'];
  2896.             }
  2897.           } else {
  2898.             //check year de la date debut et fin
  2899.             if ($evDateDebut['year'] !== $evDateFin['year']) {
  2900.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' ' $evDateDebut['year'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2901.             } else {
  2902.               $str_date 'Du ' $day_debut ' ' $evDateDebut['month'] . ' au ' $evDateFin['day'] . ' ' $evDateFin['month'] . ' ' $evDateFin['year'];
  2903.             }
  2904.           }
  2905.           if ($json_horaires['datesRange']['modeHours'] == 'simple') {
  2906.             if ($json_horaires['datesRange']['hoursSimple'][0]['hour1'] !== null && $json_horaires['datesRange']['hoursSimple'][0]['hour2'] != null) {
  2907.               $str_heure .= str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour1']) . " - " str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour2']);
  2908.             }
  2909.             if ($json_horaires['datesRange']['hoursSimple'][0]['hour3'] !== null && $json_horaires['datesRange']['hoursSimple'][0]['hour4'] != null) {
  2910.               $str_heure .= " et " str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour3']) . " - " str_replace(":""h"$json_horaires['datesRange']['hoursSimple'][0]['hour4']);
  2911.             }
  2912.           }
  2913.           $str_date '<strong>' $str_date '</strong>';
  2914.           break;
  2915.         case 'multiple':
  2916.           $nombre_date 0;
  2917.           $dates_multiples = [];
  2918.           $dates $json_horaires['datesMultiple']['dates'];
  2919.           foreach ($dates as $d) {
  2920.             $date_json date_create_from_format('d/m/Y'$d);
  2921.             if ($date_json >= $current_date) {
  2922.               array_push($dates_multiples$d);
  2923.             }
  2924.           }
  2925.           $nombre_date count($dates_multiples);
  2926.           $ics_date_debut $dates_multiples[0];
  2927.           $ics_date_fin $dates_multiples[0];
  2928.           if ($json_horaires['datesMultiple']['modeHours'] == 'simple') {
  2929.             $date null;
  2930.             if ($nombre_date == 1) {
  2931.               $date1 date_create_from_format('d/m/Y'$dates_multiples[0]);
  2932.               $str_date .= 'Le ' $date1->format('d') . ' ' $this->months["fr"][$date1->format('n')];
  2933.             } else if ($nombre_date == 2) {
  2934.               $date1 date_create_from_format('d/m/Y'$dates_multiples[0]);
  2935.               $date2 date_create_from_format('d/m/Y'$dates_multiples[1]);
  2936.               $str_date .= 'Les ' $date1->format('d') . ' ' $this->months["fr"][$date1->format('n')] . ' et ' $date2->format('d') . ' ';
  2937.               $str_month $this->months["fr"][$date2->format('n')];
  2938.               $str_date .= ' ' $str_month;
  2939.             } else if ($nombre_date == 3) {
  2940.               $date1 date_create_from_format('d/m/Y'$dates_multiples[0]);
  2941.               $date2 date_create_from_format('d/m/Y'$dates_multiples[1]);
  2942.               $date3 date_create_from_format('d/m/Y'$dates_multiples[2]);
  2943.               $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')];
  2944.             } else if ($nombre_date 3) {
  2945.               $array_dates $dates_multiples;
  2946.               $i 0;
  2947.               foreach ($array_dates as $d) {
  2948.                 if ($i 0) {
  2949.                   $str_date .= "<br>";
  2950.                 }
  2951.                 $date date_create_from_format('d/m/Y'$dates_multiples[$i]);
  2952.                 $str_date .= $date->format('d') . ' ' $this->months["fr"][$date->format('n')] . ' ' $date->format('Y');
  2953.                 $i++;
  2954.               }
  2955.             }
  2956.             $str_date '<strong>' $str_date '</strong>';
  2957.             if ($json_horaires['datesMultiple']['hoursSimple'][0]['hour1'] !== null && $json_horaires['datesMultiple']['hoursSimple'][0]['hour2'] != null) {
  2958.               $str_heure .= str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour1']) . ' - ' str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour2']);
  2959.             }
  2960.             if ($json_horaires['datesMultiple']['hoursSimple'][0]['hour3'] !== null && $json_horaires['datesMultiple']['hoursSimple'][0]['hour4'] != null) {
  2961.               $str_heure .= " et " str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour3']) . " - " str_replace(":""h"$json_horaires['datesMultiple']['hoursSimple'][0]['hour4']);
  2962.             }
  2963.           } else if ($json_horaires['datesMultiple']['modeHours'] == 'details') {
  2964.             $hoursDetails $json_horaires['datesMultiple']['hoursDetails'];
  2965.             $i 0;
  2966.             foreach ($hoursDetails as $hour) {
  2967.               $start_date date_create_from_format('d/m/Y'$hour['date']);
  2968.               if ($start_date <= $current_date) {
  2969.                 continue;
  2970.               }
  2971.               if ($i 0) {
  2972.                 $str_date .= "<br>";
  2973.               }
  2974.               if ($hour['hour1'] !== null && $hour['hour2'] != null) {
  2975.                 $str_date .= '<strong>' $start_date->format('d') . ' ' $this->months["fr"][$start_date->format('n')] . ' ' $start_date->format('Y') . '</strong>, ' .
  2976.                   str_replace(":""h"$hour['hour1']) . ' - ' str_replace(":""h"$hour['hour2']);
  2977.               }
  2978.               if ($hour['hour3'] !== null && $hour['hour4'] != null) {
  2979.                 $str_date .= ' et ' str_replace(":""h"$hour['hour3']) . ' - ' str_replace(":""h"$hour['hour4']);
  2980.               }
  2981.               $i++;
  2982.             }
  2983.           }
  2984.           break;
  2985.         case 'single':
  2986.           $start_date date_create_from_format('d/m/Y'$json_horaires['dateSingle']['dates'][0]);
  2987.           $ics_date_debut $json_horaires['dateSingle']['dates'][0];
  2988.           $ics_date_fin $json_horaires['dateSingle']['dates'][0];
  2989.           $day $start_date->format('d');
  2990.           if ($start_date->format('d') == || $start_date->format('d') == '01') {
  2991.             $day "1er";
  2992.           }
  2993.           $str_date .= 'Le ' $day;
  2994.           $str_month $this->months["fr"][$start_date->format('n')];
  2995.           $str_date .= ' ' $str_month;
  2996.           if ($start_date->format('Y') != $current_date->format('Y')) {
  2997.             $str_date .= ' ' $start_date->format('Y');
  2998.           }
  2999.           if ($json_horaires['dateSingle']['hoursSimple'][0]['hour1'] !== null && $json_horaires['dateSingle']['hoursSimple'][0]['hour2'] != null) {
  3000.             $str_heure .= $json_horaires['dateSingle']['hoursSimple'][0]['hour1'] . ' - ' $json_horaires['dateSingle']['hoursSimple'][0]['hour2'];
  3001.           }
  3002.           if ($json_horaires['dateSingle']['hoursSimple'][0]['hour3'] !== null && $json_horaires['dateSingle']['hoursSimple'][0]['hour4'] != null) {
  3003.             $str_heure .= " et " $json_horaires['dateSingle']['hoursSimple'][0]['hour3'] . " - " $json_horaires['dateSingle']['hoursSimple'][0]['hour4'];
  3004.           }
  3005.           $str_date '<strong>' $str_date '</strong>';
  3006.           break;
  3007.       }
  3008.     }
  3009.     return [
  3010.       "date_string" => $str_date,
  3011.       "ics_date_debut" => $ics_date_debut,
  3012.       "ics_date_fin" => $ics_date_fin,
  3013.       "heure_string" => $str_heure
  3014.     ];
  3015.   }
  3016. }