src/Controller/Nordinfo/MainController.php line 1013

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