src/Controller/Nordinfo/MainController.php line 2567

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