src/Controller/Nordinfo/MainController.php line 2635

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