src/Controller/Nordinfo/MainController.php line 2571

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