src/Controller/Services/MainServicesController.php line 219

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Services;
  3. use App\Entity\CustomForm;
  4. use App\Entity\Footer;
  5. use App\Entity\FooterSites;
  6. use App\Entity\FormulaireThematique;
  7. use App\Entity\Glossaire;
  8. use App\Entity\InscritNewsletter;
  9. use App\Entity\LogEs;
  10. use App\Entity\PageAccueilService;
  11. use App\Entity\PagesLegales;
  12. use App\Entity\Service;
  13. use App\Entity\ServiceFeedback;
  14. use App\Entity\ServiceGrandProfil;
  15. use App\Entity\ServiceSousProfil;
  16. use App\Entity\ServiceTheme;
  17. use Dompdf\Dompdf;
  18. use Dompdf\Options;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use App\Utilities\Feed;
  22. use App\Service\ElasticsearchService;
  23. use App\Service\EpingleService;
  24. use App\Service\RssService;
  25. use App\Service\SendgridMailService;
  26. use App\Service\SeoService;
  27. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use Symfony\Component\HttpFoundation\JsonResponse;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpFoundation\RequestStack;
  32. use Symfony\Component\HttpFoundation\Response;
  33. /**
  34.  * @method User getUser()
  35.  */
  36. #[Route(host"serviceslenord.spontaneit.fr")]
  37. //#[Route(host: "services.lenord.fr")]
  38. //#[Route(host:"localhost")]
  39. class MainServicesController extends AbstractController
  40. {
  41.   protected mixed $params = [];
  42.   private mixed $session;
  43.   public function __construct(
  44.     private EntityManagerInterface $em,
  45.     private Feed $feedUtilities,
  46.     private RssService $rss_service,
  47.     private ElasticsearchService $es_service,
  48.     private EpingleService $epingle_service,
  49.     private RequestStack $request_stack,
  50.     private SendgridMailService $sendgrid_service,
  51.     private SeoService $seo_service
  52.   ) {
  53.     $this->epingle_service $epingle_service;
  54.     $this->rss_service $rss_service;
  55.     $this->es_service $es_service;
  56.     $this->feedUtilities $feedUtilities;
  57.     $this->sendgrid_service $sendgrid_service;
  58.     $this->seo_service $seo_service;
  59.     $this->session $this->request_stack->getSession();
  60.     $this->params['title'] = "";
  61.     $this->params['epingles'] = [];
  62.     $this->params['is_pdf'] = 0;
  63.     $this->params['is_preview'] = 0;
  64.     $this->params['breadcrumb'] = [];
  65.     $this->params['footer'] = $this->em->getRepository(Footer::class)->find(1);
  66.   }
  67.   #[Route(path'/sitemap.xml'name'services_plandusite_xml')]
  68.   public function services_plandusite_xml(Request $request): Response
  69.   {
  70.     $date = new \DateTime();
  71.     $domain "https://services.lenord.fr";
  72.     $dom = new \DOMDocument('1.0''UTF-8');
  73.     $rss $dom->createElement('urlset');
  74.     $rss->setAttribute('xmlns''http://www.sitemaps.org/schemas/sitemap/0.9');
  75.     $rss_node $dom->appendChild($rss);
  76.     $url $dom->createElement('url');
  77.     $url_node $rss_node->appendChild($url);
  78.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_home')));
  79.     $url $dom->createElement('url');
  80.     $url_node $rss_node->appendChild($url);
  81.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_services', ['slug' => 'particulier'])));
  82.     $url $dom->createElement('url');
  83.     $url_node $rss_node->appendChild($url);
  84.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_services', ['slug' => 'professionnel'])));
  85.     $url $dom->createElement('url');
  86.     $url_node $rss_node->appendChild($url);
  87.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_services', ['slug' => 'association'])));
  88.     $url $dom->createElement('url');
  89.     $url_node $rss_node->appendChild($url);
  90.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_services', ['slug' => 'collectivite'])));
  91.     $services $this->em->getRepository(Service::class)->findBy(['statut' => 5]);
  92.     foreach ($services as $service) {
  93.       $url $dom->createElement('url');
  94.       $url_node $rss_node->appendChild($url);
  95.       $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_detail_service', ['slug' => $service->getAliasUrl()])));
  96.       $url_node->appendChild($dom->createElement('lastmod', ($service->getDateUpdate() != null) ? $service->getDateUpdate()->format('Y-m-d') : $date->format('Y-m-d')));
  97.       $url_node->appendChild($dom->createElement('changefreq''monthly'));
  98.     }
  99.     $url $dom->createElement('url');
  100.     $url_node $rss_node->appendChild($url);
  101.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_support')));
  102.     $url $dom->createElement('url');
  103.     $url_node $rss_node->appendChild($url);
  104.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_glossaire')));
  105.     $url $dom->createElement('url');
  106.     $url_node $rss_node->appendChild($url);
  107.     $url_node->appendChild($dom->createElement('loc''https://demarches.services.lenord.fr/portals/usagers/forum?page=monCompte'));
  108.     $url $dom->createElement('url');
  109.     $url_node $rss_node->appendChild($url);
  110.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_recherche')));
  111.     $url $dom->createElement('url');
  112.     $url_node $rss_node->appendChild($url);
  113.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_detail_service', ['slug' => 'mentions-legales-nord-services'])));
  114.     $url $dom->createElement('url');
  115.     $url_node $rss_node->appendChild($url);
  116.     $url_node->appendChild($dom->createElement('loc'$domain $this->generateUrl('services_detail_service', ['slug' => 'accessibilite-nord-services'])));
  117.     $xml $dom->saveXML();
  118.     $response = new Response($xml);
  119.     $response->headers->set('Content-Type''text/xml');
  120.     $response->headers->set('Access-Control-Allow-Origin''*');
  121.     return $response;
  122.   }
  123.   #[Route(path'/plan-du-site'name'services_plandusite')]
  124.   public function services_plandusite(Request $request): Response
  125.   {
  126.     $this->params['title'] = "Plan du site";
  127.     $this->params['meta_description'] = "Le plan du site Nord services";
  128.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => $this->params['title']]];
  129.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  130.     $this->params['referer'] = $request->headers->get('referer');
  131.     $urls = [];
  132.     // Home
  133.     $urls['index']['parent']['url'] = $this->generateUrl('services_home');
  134.     $urls['index']['parent']['name'] = "Accueil";
  135.     //Services
  136.     //Particuliers
  137.     $urls['particuliers']['parent']['url'] = $this->generateUrl('services_services', ['slug' => 'particulier']);
  138.     $urls['particuliers']['parent']['name'] = "Particuliers";
  139.     //Professionnels
  140.     $urls['professionnels']['parent']['url'] = $this->generateUrl('services_services', ['slug' => 'professionnel']);
  141.     $urls['professionnels']['parent']['name'] = "Professionnels";
  142.     //Associations
  143.     $urls['associations']['parent']['url'] = $this->generateUrl('services_services', ['slug' => 'association']);
  144.     $urls['associations']['parent']['name'] = "Associations";
  145.     //Collectivités
  146.     $urls['collectivites']['parent']['url'] = $this->generateUrl('services_services', ['slug' => 'collectivite']);
  147.     $urls['collectivites']['parent']['name'] = "Collectivités";
  148.     //Services
  149.     $themes $this->em->getRepository(ServiceTheme::class)->findAll();
  150.     foreach ($themes as $theme) {
  151.       if ($theme->getServices()->count() > 0) {
  152.         $urls[$theme->getAliasUrl()]['parent']['url'] = null;
  153.         $urls[$theme->getAliasUrl()]['parent']['name'] = $theme->getTitre();
  154.         $i 0;
  155.         foreach ($theme->getServices() as $service) {
  156.           $urls[$theme->getAliasUrl()]['children'][$i]['url'] = $this->generateUrl('services_detail_service', ['slug' => $service->getAliasUrl()]);
  157.           $urls[$theme->getAliasUrl()]['children'][$i]['name'] = $service->getTitre();
  158.           $i++;
  159.         }
  160.       }
  161.     }
  162.     //Contact / Support
  163.     $urls['support']['parent']['url'] = $this->generateUrl('services_support');
  164.     $urls['support']['parent']['name'] = "Contact";
  165.     //Glossaire
  166.     $urls['glossaire']['parent']['url'] = $this->generateUrl('services_glossaire');
  167.     $urls['glossaire']['parent']['name'] = "Glossaire";
  168.     //Demarches
  169.     $urls['glossaire']['parent']['url'] = 'https://demarches.services.lenord.fr/portals/usagers/forum?page=monCompte';
  170.     $urls['glossaire']['parent']['name'] = "Nord démarches";
  171.     //Recherche 
  172.     $urls['recherche']['parent']['url'] = $this->generateUrl('services_recherche');
  173.     $urls['recherche']['parent']['name'] = "Recherche";
  174.     //Mentions légales
  175.     $urls['mentionlegale']['parent']['url'] = $this->generateUrl('services_detail_service', ['slug' => 'mentions-legales-nord-services']);
  176.     $urls['mentionlegale']['parent']['name'] = "Mentions légales";
  177.     //Accessibilité
  178.     $urls['accessibilite']['parent']['url'] = $this->generateUrl('services_detail_service', ['slug' => 'accessibilite-nord-services']);
  179.     $urls['accessibilite']['parent']['name'] = "Accessibilité";
  180.     $this->params['urls'] = $urls;
  181.     //Epingle
  182.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  183.     if ($request->get('function') == 'download_pdf') {
  184.       $this->params['is_pdf'] = 1;
  185.       $pdfOptions = new Options();
  186.       $pdfOptions->set('defaultFont''Arial');
  187.       $pdfOptions->setIsRemoteEnabled(true);
  188.       $dompdf = new Dompdf($pdfOptions);
  189.       $html $this->renderView('Services/Main/plandusite.html.twig'$this->params);
  190.       $dompdf->loadHtml($html);
  191.       $dompdf->setPaper('A4''portrait');
  192.       $dompdf->render();
  193.       $output $dompdf->output();
  194.       $filename sprintf('le-nord-%s.pdf'$this->params['title']);
  195.       return new Response(
  196.         $output,
  197.         200,
  198.         [
  199.           'Content-Type' => 'application/pdf',
  200.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  201.         ]
  202.       );
  203.     } else {
  204.       return $this->render('Services/Main/plandusite.html.twig'$this->params);
  205.     }
  206.   }
  207.   #[Route(path'/'name'services_home')]
  208.   public function home(): Response
  209.   {
  210.     $this->params['title'] = "";
  211.     $this->params['meta_description'] = "Tous les services du Département du Nord pour les particuliers, les professionnels, les associations et les collectivités";
  212.     $this->params['home'] = $this->em->getRepository(PageAccueilService::class)->find(1);
  213.     //
  214.     $count_services_home $this->params['home']->getServices()->count();
  215.     $this->params['services_forcomplete'] = [];
  216.     if ($count_services_home 9) {
  217.       $limit $count_services_home;
  218.       $this->params['services_forcomplete'] = $this->em->getRepository(Service::class)->findBy(['statut' => 5], ['view_count' => 'DESC'], 9);
  219.     }
  220.     $this->params['count_sous_profils'] = count($this->em->getRepository(ServiceSousProfil::class)->findAll());
  221.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsetrue);
  222.     $this->params['nordinfo_rss'] = null;
  223.     if ($this->params['home']->getUrlRssNordinfo() != null) {
  224.       $this->params['nordinfo_rss'] = $this->rss_service->getArrayArticle($this->params['home']->getUrlRssNordinfo());
  225.     }
  226.     //Epingle
  227.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  228.     $epingles_ $this->epingle_service->getEpinglesSection('home_services');
  229.     foreach ($epingles_ as $epingle) {
  230.       array_push($this->params['epingles'], $epingle);
  231.     }
  232.     return $this->render('Services/Main/home.html.twig'$this->params);
  233.   }
  234.   #[Route(path'/console2021/apercu_service/{id}'name'apercu_service')]
  235.   public function apercu_service(Request $requestmixed $id): Response
  236.   {
  237.     $this->params['service'] = $this->em->getRepository(Service::class)->findOneBy(['alias_url' => $id]);
  238.     $this->params['service']->setViewCount($this->params['service']->getViewCount() + 1);
  239.     $this->em->persist($this->params['service']);
  240.     $this->em->flush();
  241.     $this->params['id'] = $this->params['service']->getId();
  242.     $this->params['title'] = $this->params['service']->getTitre();
  243.     $this->params['meta_description'] = $this->params['service']->getChapo();
  244.     $this->params['content_post'] = $this->feedUtilities->jsonToHtml($this->params['service']->getContent(), $request);
  245.     $this->params['count_sous_profils'] = count($this->em->getRepository(ServiceSousProfil::class)->findAll());
  246.     $this->params['referer'] = $request->headers->get('referer');
  247.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  248.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => $this->params['title']]];
  249.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  250.     $this->params['openGraph'] = ["title" => $this->params['service']->getTitre(), "url" => "https://services.lenord.fr/" $id"image" => "https://services.lenord.fr/img/logos/logo-nord-services.svg""type" => "website""description" => $this->params['content_post']];
  251.     $this->params['hasVoted'] = $this->session->has('vote_' $this->params['service']->getId());
  252.     $epingles_politiques $this->epingle_service->getEpinglesSection('services');
  253.     foreach ($epingles_politiques as $epingle) {
  254.       array_push($this->params['epingles'], $epingle);
  255.     }
  256.     foreach ($this->params['service']->getEpingles() as $e) {
  257.       if ($e->getActive() == 1) {
  258.         array_push($this->params['epingles'], $e);
  259.       }
  260.     }
  261.     if ($request->get('function') == 'download_pdf') {
  262.       $this->params['is_pdf'] = 1;
  263.       $pdfOptions = new Options();
  264.       $pdfOptions->set('defaultFont''Arial');
  265.       $pdfOptions->setIsRemoteEnabled(true);
  266.       $dompdf = new Dompdf($pdfOptions);
  267.       $html $this->renderView('Services/Main/service.html.twig'$this->params);
  268.       $dompdf->loadHtml($html);
  269.       $dompdf->setPaper('A4''portrait');
  270.       $dompdf->render();
  271.       $output $dompdf->output();
  272.       $filename sprintf('le-nord-%s.pdf'$this->params['title']);
  273.       return new Response(
  274.         $output,
  275.         200,
  276.         [
  277.           'Content-Type' => 'application/pdf',
  278.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  279.         ]
  280.       );
  281.     } else {
  282.       return $this->render('Services/Main/service.html.twig'$this->params);
  283.     }
  284.   }
  285.   #[Route(path'/recherche'name'services_recherche')]
  286.   public function services_recherche(Request $request): Response
  287.   {
  288.     $this->params['results'] = null;
  289.     if ($request->query->get('search') != null) {
  290.       $search_fields = ['combined'];
  291.       $results $this->es_service->searchDocuments('lenord'$search_fields$request->query->get('search'), ['service''glossaire'], [], [], 25true);
  292. //      $results = [];
  293.       $this->params['results'] = $results;
  294.       //Save log
  295.       $logEs = new LogEs;
  296.       $logEs->setRecherche($request->query->get('search'))
  297.         ->setDate(new \DateTime())
  298.         ->setSite("services");
  299.       $this->em->persist($logEs);
  300.       $this->em->flush();
  301.     }
  302.     $this->params['title'] = 'Recherche: "' $request->query->get('search') . '"';
  303.     $this->params['search'] = $request->query->get('search');
  304.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsetrue);
  305.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  306.     $this->params['count_sous_profils'] = count($this->em->getRepository(ServiceSousProfil::class)->findAll());
  307.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => 'Recherche']];
  308.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  309.     $this->params['referer'] = $request->headers->get('referer');
  310.     $epingles_politiques $this->epingle_service->getEpinglesSection('services');
  311.     foreach ($epingles_politiques as $epingle) {
  312.       array_push($this->params['epingles'], $epingle);
  313.     }
  314.     return $this->render('Services/Main/search.html.twig'$this->params);
  315.   }
  316.   #[Route(path'/services_recherche/ajax'name'services_elastic_search')]
  317.   public function services_elastic_search(Request $request): Response
  318.   {
  319.     $search_fields = ['title''content''subtitle'];
  320.     $results $this->es_service->searchDocuments('lenord'$search_fields$request->query->get('search'), 'service');
  321.     return new JsonResponse($results['hits']['hits']);
  322.   }
  323.   private function getCaptcha(): mixed
  324.   {
  325.     $captchaCh = [012345678910];
  326.     $captchaLe = ["zéro""un""deux""trois""quatre""cinq""six""sept""huit""neuf""dix"];
  327.     $testcap array_merge($captchaCh$captchaLe);
  328.     $rnd array_rand($testcap2);
  329.     $i1 $rnd[0];
  330.     if ($rnd[0] >= 11) {
  331.       $i1 $rnd[0] - 11;
  332.     }
  333.     $i2 $rnd[1];
  334.     if ($rnd[1] >= 11) {
  335.       $i2 $rnd[1] - 11;
  336.     }
  337.     $capp = ["valeur1" => ["libelle" => $testcap[$rnd[0]], "valeur" => $captchaCh[$i1]], "valeur2" => ["libelle" => $testcap[$rnd[1]], "valeur" => $captchaCh[$i2]]];
  338.     return $capp;
  339.   }
  340.   #[Route(path'/glossaire'name'services_glossaire')]
  341.   public function glossaire(Request $request): Response
  342.   {
  343.     $this->params['title'] = "Glossaire";
  344.     $this->params['meta_description'] = "Le glossaire du site du Département du Nord : acronymes et définitions utiles";
  345.     $glossaire $this->em->getRepository(Glossaire::class)->findBy([], ['terme' => 'ASC']);
  346.     $this->params['glossaires'] = $glossaire;
  347.     $this->params['letters'] = $this->em->getRepository(Glossaire::class)->getFirstLetters();
  348.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsetrue);
  349.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => 'Glossaire']];
  350.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  351.     $this->params['referer'] = $request->headers->get('referer');
  352.     //Epingle
  353.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  354.     $epingles_ $this->epingle_service->getEpinglesSection('glossaire_services');
  355.     foreach ($epingles_ as $epingle) {
  356.       array_push($this->params['epingles'], $epingle);
  357.     }
  358.     return $this->render('Services/Main/glossaire.html.twig'$this->params);
  359.   }
  360.   #[Route(path'/ajax/serviceSaveAvis'name'services_save_avis')]
  361.   public function serviceSaveAvis(Request $request): Response
  362.   {
  363.     $service $this->em->getRepository(Service::class)->find($request->request->get('id'));
  364.     if ($request->request->get('valeur') == 'positif') {
  365.       $service->setAvisPositif($service->getAvisPositif() + 1);
  366.     } else {
  367.       $service->setAvisNegatif($service->getAvisNegatif() + 1);
  368.       $feedback = new ServiceFeedback;
  369.       $feedback->setService($service)
  370.         ->setDate(new \DateTime())
  371.         ->setCommentaire($request->request->get('comment'));
  372.       $this->em->persist($feedback);
  373.     }
  374.     $this->em->persist($service);
  375.     $this->em->flush();
  376.     $this->session->set('vote_' $request->request->get('id'), true);
  377.     return new JsonResponse(['success' => true]);
  378.   }
  379.   #[Route(path'/ajax/getServicesByGrandprofil'name'services_ajax_getServices')]
  380.   public function getServicesByGrandprofil(Request $request): Response
  381.   {
  382.     $services $this->em->getRepository(Service::class)->getServicesByGrandprofil($request->request->get('alias'));
  383.     return new JsonResponse(['datas' => $services]);
  384.   }
  385.   #[Route(path'/ajax/getServicesAll'name'services_ajax_getServices')]
  386.   public function getServicesAll(Request $request): Response
  387.   {
  388.     $services $this->em->getRepository(Service::class)->getServicesByGrandprofil($request->request->get('alias'));
  389.     return new JsonResponse(['datas' => $services]);
  390.   }
  391.   #[Route(path'/formulaire-de-contact'name'services_support')]
  392.   public function services_support(Request $request): Response
  393.   {
  394.     $this->params['title'] = "Formulaire de contact";
  395.     $message $request->query->get('message');
  396.     $this->params['_message'] = $message;
  397.     $this->params['meta_description'] = "Contacter les services du Département du Nord par courriel";
  398.     $this->params['referer'] = $request->headers->get('referer');
  399.     $this->params['caps'] = $this->getCaptcha();
  400.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  401.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => "Formulaire de contact"]];
  402.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  403.     $this->params['thematiques'] = $this->em->getRepository(FormulaireThematique::class)->findBy(['bool_services' => 1], ['name' => 'ASC']);
  404.     return $this->render('Services/Main/support.html.twig'$this->params);
  405.   }
  406.   /*
  407.   #[Route(path: '/formulaire-{slug}', name: 'custom_form_services', host: "services.lenord.fr")]
  408.   public function custom_form(Request $request, ?string $slug): Response
  409.   {
  410.     $custom_form = $this->em->getRepository(CustomForm::class)->findOneBy(array('alias' => $slug));
  411.     $this->params['caps'] = $this->getCaptcha();
  412.     $this->params['form'] = $custom_form;
  413.     return $this->render('Services/Main/custom_form.html.twig', $this->params);
  414.   }
  415.     */
  416.   #[Route(path'/send_form_custom/{alias}'name'send_form_custom_services'host"services.lenord.fr")]
  417.   public function send_form_custom(Request $request, ?string $alias): Response
  418.   {
  419.     $post $request->request;
  420.     $custom_form $this->em->getRepository(CustomForm::class)->findOneBy(array('alias' => $alias));
  421.     $destinataires_sendgrid = [];
  422.     $objet null;
  423.     $objet "Votre message Ã  " $custom_form->getDestinataire() . " via le site Nord services";
  424.     $emails explode(";", (string) $custom_form->getEmail());
  425.     for ($i 0$i count($emails); $i++) {
  426.       array_push($destinataires_sendgrid$emails[$i]);
  427.     }
  428.     $message $post->get('message');
  429.     //exp
  430.     //destinataire_
  431.     //objet_
  432.     //message_
  433.     //piece_jointe_
  434.     $fileName null;
  435.     $auth_extension = ['png''jpg''jpeg''gif''pdf'];
  436.     $mime_authorized = ['application/pdf''image/jpg''image/jpeg''image/gif''image/png'];
  437.     $file null;
  438.     $newname uniqid();
  439.     if ($request->files != null && $request->files->get('file') != null) {
  440.       $file $request->files->get('file');
  441.       $fileName $file->getClientOriginalName();
  442.       $fileType $file->getClientMimeType();
  443.       if (in_array($file->guessExtension(), $auth_extension) && in_array($fileType$mime_authorized)) {
  444.         /*try {
  445.           /*$file->move($uploadDir, $newname.'.'.$file->guessExtension());
  446.           array_push($files, array(
  447.             'name' => $newname.'.'.$file->guessExtension(),
  448.             'type' => $fileType,
  449.             'data' => $fileData,
  450.           ));
  451.         } catch (FileException) {
  452.           $file = null;
  453.           return new JsonResponse(['error' => 'File could not be uploaded']);
  454.         }*/
  455.       } else {
  456.         $file null;
  457.         return new JsonResponse(['error' => "Mauvais format d'image"]);
  458.       }
  459.     }
  460.     $date = new \DateTime;
  461.     /*$content = $this->renderView(
  462.       'Nordinfo/Mails/dest_signalement2.html.twig',
  463.       ['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')]
  464.     );*/
  465.     $content "Le message suivant vient de vous Ãªtre envoyé via le site Nord services par " $post->get('nom_prenom') .
  466.       " - Merci de répondre directement Ã  " $post->get('email') . " : " "\n" $post->get('message') . "\n\n" "Nord, le Département est là - https://services.lenord.fr/";
  467.     $nom_dest $custom_form->getDestinataire();
  468.     $content_exp "Bonjour, votre message a Ã©té transmis Ã  " $nom_dest "." "\n\n" .
  469.       "Message : " $post->get('message');
  470.     if ($fileName !== null) {
  471.       $content_exp .= "\n" "Pièce jointe : " $fileName;
  472.     }
  473.     $content_exp .= "\n\n" "Nord, le Département est là - https://services.lenord.fr/";
  474.     //envoi mail
  475.     $result_ $post->get('nb1') + $post->get('nb2');
  476.     if ($result_ == $post->get('captcha') && $post->get('raison') == null) {
  477.       try {
  478.         $this->sendgrid_service->send($destinataires_sendgrid$content"Message envoyé par " $post->get('nom_prenom') . " via le site Nord services"null$filefalse$post->get('email'));
  479.         $this->sendgrid_service->send([$post->get('email')], $content_exp$objetnull$filefalse);
  480.       } catch (\Exception) {
  481.         $this->params['message'] = 'Email erreur';
  482.         return $this->render('Services/Main/endformerror.html.twig'$this->params);
  483.       }
  484.     } else {
  485.       $this->params['message'] = 'Catcha erreur';
  486.       return $this->render('Services/Main/endformerror.html.twig'$this->params);
  487.     }
  488.     return $this->render('Services/Main/endform.html.twig'$this->params);
  489.   }
  490.   #[Route(path'/confirmation'name'services_send_form')]
  491.   public function sendform(Request $request): Response
  492.   {
  493.     $post $request->request;
  494.     $result_ $post->get('nb1') + $post->get('nb2');
  495.     if ($result_ == $post->get('captcha')) {
  496.       $destinataires_sendgrid = [];
  497.       $message $post->get('message');
  498.       //Thematique
  499.       $thematique null;
  500.       $formThematique $this->em->getRepository(FormulaireThematique::class)->find($post->get('thematique'));
  501.       $thematique $formThematique->getName();
  502.       $emails explode(";", (string) $formThematique->getDestinataires());
  503.       for ($i 0$i count($emails); $i++) {
  504.         array_push($destinataires_sendgrid$emails[$i]);
  505.       }
  506.       //exp
  507.       //destinataire_
  508.       //objet_
  509.       //message_
  510.       //piece_jointe_
  511.       $fileName null;
  512.       $auth_extension = ['png''jpg''jpeg''gif''pdf'];
  513.       $mime_authorized = ['application/pdf''image/jpg''image/jpeg''image/gif''image/png'];
  514.       $file null;
  515.       if ($request->files != null && $request->files->get('file') != null) {
  516.         $file $request->files->get('file');
  517.         $fileName $file->getClientOriginalName();
  518.         $fileType $file->getClientMimeType();
  519.         if (in_array($file->guessExtension(), $auth_extension) && in_array($fileType$mime_authorized)) {
  520.           //$file->move($uploadDir, $newname.'.'.$file->guessExtension());
  521.           /*try {
  522.             array_push($files, array(
  523.               'name' => $newname.'.'.$file->guessExtension(),
  524.               'type' => $fileType,
  525.               'data' => $fileData,
  526.             ));
  527.           } catch (FileException) {
  528.             $file = null;
  529.             return new JsonResponse(['error' => 'File could not be uploaded']);
  530.           }*/
  531.         } else {
  532.           $file null;
  533.           return new JsonResponse(['error' => "Mauvais format d'image"]);
  534.         }
  535.       }
  536.       $date = new \DateTime;
  537.       $content $this->renderView(
  538.         'Services/Mails/dest_signalement2.html.twig',
  539.         ['site' => 'services''expediteur_email_' => ($post->get('prenom') != null && $post->get('nom') != null) ? $post->get('prenom') . ' ' $post->get('nom') : $post->get('email'), 'destinataire_' => "agent en charge du support aux usagers"'objet_' => 'Nouveau message sur Nord services - ' $thematique ' / ' "NS" $date->format('dmYHis'), 'thematique' => $thematique'email' => $post->get('email'), 'message_' => $message'piece_jointe_' => ($fileName != null) ? $fileName "Aucune pièce jointe"'date' => "NS" $date->format('dmYHis')]
  540.       );
  541.       $nom_dest 'rédaction du Nord info';
  542.       if ($post->get('dest_nom') != null) {
  543.         $nom_dest $post->get('dest_nom');
  544.       }
  545.       $content_exp $this->renderView(
  546.         'Services/Mails/exp_signalement2.html.twig',
  547.         ['site' => 'services''destinataire_' => $nom_dest'objet_' => 'Votre message sur Nord services - ' $thematique ' / ' "NS" $date->format('dmYHis'), 'thematique' => $thematique'email' => $post->get('email'), 'message_' => $message'piece_jointe_' => ($fileName != null) ? $fileName "Aucune pièce jointe"'date' => "NS" $date->format('dmYHis')]
  548.       );
  549.       //Newsletter
  550.       if ($result_ == $post->get('captcha')) {
  551.         if ($post->get('newsletter') != null) {
  552.           $ins $this->em->getRepository(InscritNewsletter::class)->findOneBy(['email' => $post->get('email')]);
  553.           if ($ins == null) {
  554.             $ins = new InscritNewsletter;
  555.             $ins->setEmail($post->get('email'))
  556.               ->setPrenom($post->get('prenom'))
  557.               ->setNom($post->get('nom'))
  558.               ->setDate(new \DateTime());
  559.             $this->em->persist($ins);
  560.             $this->em->flush();
  561.           }
  562.         }
  563.         //envoi mail
  564.         $result_ $post->get('nb1') + $post->get('nb2');
  565.         try {
  566.           $this->sendgrid_service->send($destinataires_sendgrid$content'Nouveau message sur Nord Services - ' $thematique ' / ' "NS" $date->format('dmYHis'), null$file);
  567.           $this->sendgrid_service->send([$post->get('email')], $content_exp'Votre message sur Nord Services - ' $thematique ' / ' "NS" $date->format('dmYHis'), null$file);
  568.         } catch (\Exception) {
  569.           $this->params['message'] = 'Email erreur';
  570.           return $this->render('Services/Main/endformerror.html.twig'$this->params);
  571.         }
  572.       }
  573.     } else {
  574.       $this->params['message'] = 'Captcha erreur';
  575.       return $this->render('Services/Main/endformerror.html.twig'$this->params);
  576.     }
  577.     return $this->render('Services/Main/endform.html.twig'$this->params);
  578.   }
  579.   #[Route(path'/{slug}'name'services_services'requirements: ['slug' => 'particulier|professionnel|association|collectivite'])]
  580.   public function services(Request $request, ?string $slug): Response
  581.   {
  582.     $this->params['slug'] = $slug;
  583.     $this->params['grp'] = $this->em->getRepository(ServiceGrandProfil::class)->findOneBy(['alias_url' => $slug]);
  584.     $sousprofils = [];
  585.     $sousprofils_id = [];
  586.     $array_fields = [];
  587.     $sousprofils_title = [];
  588.     $sousprofils_entities = [];
  589.     $search_text null;
  590.     $this->params['title'] = ucfirst((string) $slug);
  591.     if ($slug == 'collectivite') {
  592.       $this->params['title'] = "Collectivité";
  593.     }
  594.     $this->params['meta_description'] = "Tous les services du Département du Nord pour les " $slug "s nordistes";
  595.     if ($request->query->get('sp') != null) {
  596.       //$array_fields = array('sousprofils.alias');
  597.       $i 0;
  598.       foreach ((array)$request->query->get('sp') as $alias) {
  599.         array_push($sousprofils$alias);
  600.         $sousp $this->em->getRepository(ServiceSousProfil::class)->findOneBy(['alias_url' => $alias]);
  601.         array_push($sousprofils_entities$sousp);
  602.         array_push($sousprofils_id$sousp->getId());
  603.         array_push($sousprofils_title$sousp->getTitre());
  604.         if ($i 0) {
  605.           $this->params['title'] .= " & ";
  606.         }
  607.         $this->params['title'] .= ' ' '"' $sousp->getTitre() . '"';
  608.         $i++;
  609.       }
  610.     }
  611.     $this->params['sousprofils_entities'] = $sousprofils_entities;
  612.     $this->params['filters'] = $request->query->get('sp');
  613.     $this->params['totalCount'] = $this->em->getRepository(Service::class)->getTotalCount($slug$sousprofils_id);
  614.     $this->params['results'] = [];
  615.     $this->params['results'] = $this->es_service->searchDocuments('lenord'$array_fields$search_text'service', [$slug], $sousprofils$this->params['totalCount']['nb_service']);
  616.     $this->params['themes'] = $this->em->getRepository(ServiceTheme::class)->countByTheme($slug$sousprofils_id);
  617.     $all_themes $this->em->getRepository(ServiceTheme::class)->getAllByGp($slug);
  618.     $theme_arr = [];
  619.     foreach ($all_themes as $theme) {
  620.       $nb_service 0;
  621.       $key array_search($theme$this->params['themes']);
  622.       if ($key !== false) {
  623.         $nb_service $this->em->getRepository(ServiceTheme::class)->countService($slug$sousprofils_id$theme->getId())['nb_service'];
  624.       }
  625.       array_push($theme_arr, ['nb_service' => $nb_service'titre' => $theme->getTitre(), 'alias_url' => $theme->getAliasUrl()]);
  626.     }
  627.     $this->params['all_themes'] = $theme_arr;
  628.     $this->params['sites'] = $this->em->getRepository(FooterSites::class)->getForFooter(falsetrue);
  629.     $this->params['count_sous_profils'] = count($this->em->getRepository(ServiceSousProfil::class)->findAll());
  630.     //breadcrumb
  631.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => 'Particulier']];
  632.     if ($slug == 'collectivite') {
  633.       $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => 'Collectivité']];
  634.     } else if ($slug == 'association') {
  635.       $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => 'Association']];
  636.     } else if ($slug == 'professionnel') {
  637.       $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => 'Professionnel']];
  638.     }
  639.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  640.     if ($this->params['title'] == "collectivite") {
  641.       $this->params['title'] = "Collectivité";
  642.     }
  643.     foreach ($sousprofils_title as $title_sp) {
  644.       $this->params['title'] .= ' "' $title_sp '"';
  645.     }
  646.     //Epingle
  647.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  648.     $epingles_politiques $this->epingle_service->getEpinglesSection('services');
  649.     foreach ($epingles_politiques as $epingle) {
  650.       array_push($this->params['epingles'], $epingle);
  651.     }
  652.     //dd($this->params['results']['hits']);
  653.     return $this->render('Services/Main/services.html.twig'$this->params);
  654.   }
  655.   #[Route(path'/store_preferences'name'services_store_preferences')]
  656.   public function storeUserPreferences(Request $request): Response
  657.   {
  658.     $post $request->request;
  659.     $function $post->get('function');
  660.     $user $this->getUser();
  661.     switch ($function) {
  662.       case 'store_dark_mode':
  663.         $user->setDarkMode((int)$post->get('dark_mode'));
  664.         $this->em->persist($user);
  665.         $this->em->flush();
  666.         break;
  667.       case 'store_font_size':
  668.         $user->setFontSize($post->get('font_size'));
  669.         $this->em->persist($user);
  670.         $this->em->flush();
  671.         break;
  672.       case 'store_font_family':
  673.         $user->setFontFamily($post->get('font_family'));
  674.         $this->em->persist($user);
  675.         $this->em->flush();
  676.         break;
  677.     }
  678.     return new JsonResponse(['success' => true]);
  679.   }
  680.   /**
  681.    * @throws \JsonException
  682.    */
  683.   #[Route(path'/{slug}'name'services_detail_service')]
  684.   public function service(Request $request, ?string $slug): Response
  685.   {
  686.     $this->params['service'] = $this->em->getRepository(Service::class)->findOneBy(['alias_url' => $slug]);
  687.     if ($this->params['service'] == null) {
  688.       return $this->pagelegales($request$slug);
  689.     }
  690.     if ($this->params['service']->getStatut() != null && $this->params['service']->getStatut()->getId() == 5) {
  691.       $this->params['service']->setViewCount($this->params['service']->getViewCount() + 1);
  692.       $this->em->persist($this->params['service']);
  693.       $this->em->flush();
  694.       $this->params['id'] = $this->params['service']->getId();
  695.       $this->params['title'] = $this->params['service']->getTitre();
  696.       $this->params['meta_description'] = $this->params['service']->getChapo();
  697.       $this->params['content_post'] = $this->feedUtilities->jsonToHtml($this->params['service']->getContent(), $request$this->params['title']);
  698.       $this->params['count_sous_profils'] = count($this->em->getRepository(ServiceSousProfil::class)->findAll());
  699.       $this->params['referer'] = $request->headers->get('referer');
  700.       $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  701.       $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => $this->params['title']]];
  702.       $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request),  JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  703.       $this->params['openGraph'] = ["title" => $this->params['service']->getTitre(), "url" => "https://services.lenord.fr/" $slug"image" => "https://services.lenord.fr/img/logos/logo-nord-services.svg""type" => "website""description" => $this->params['content_post']];
  704.       $this->params['hasVoted'] = $this->session->has('vote_' $this->params['service']->getId());
  705.       $epingles_politiques $this->epingle_service->getEpinglesSection('services');
  706.       foreach ($epingles_politiques as $epingle) {
  707.         array_push($this->params['epingles'], $epingle);
  708.       }
  709.       foreach ($this->params['service']->getEpingles() as $e) {
  710.         if ($e->getActive() == 1) {
  711.           array_push($this->params['epingles'], $e);
  712.         }
  713.       }
  714.       if ($request->get('function') == 'download_pdf') {
  715.         $this->params['is_pdf'] = 1;
  716.         $pdfOptions = new Options();
  717.         $pdfOptions->set('defaultFont''Arial');
  718.         $pdfOptions->setIsRemoteEnabled(true);
  719.         $dompdf = new Dompdf($pdfOptions);
  720.         $html $this->renderView('Services/Main/service.html.twig'$this->params);
  721.         $dompdf->loadHtml($html);
  722.         $dompdf->setPaper('A4''portrait');
  723.         $dompdf->render();
  724.         $output $dompdf->output();
  725.         $filename sprintf('le-nord-%s.pdf'$this->params['title']);
  726.         return new Response(
  727.           $output,
  728.           200,
  729.           [
  730.             'Content-Type' => 'application/pdf',
  731.             'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  732.           ]
  733.         );
  734.       } else {
  735.         return $this->render('Services/Main/service.html.twig'$this->params);
  736.       }
  737.     } else {
  738.       return $this->pagelegales($request"erreur404");
  739.     }
  740.   }
  741.   /**
  742.    * @throws \JsonException
  743.    */
  744.   public function pagelegales(Request $request, ?string $slug): Response
  745.   {
  746.     $this->params['referer'] = $request->headers->get('referer');
  747.     $post $this->em->getRepository(PagesLegales::class)->findOneBy(['slug' => $slug'actif' => 1]);
  748.     if (!$post) {
  749.       throw $this->createNotFoundException('La page demandée n\'existe pas.');
  750.     }
  751.     $this->params['post'] = $post;
  752.     $this->params['title'] = $this->params['post']->getTitre();
  753.     $this->params['meta_description'] = $this->params['post']->getMetaDescription();
  754.     $this->params['epingles'] = $this->epingle_service->getEpingles('services');
  755.     $epingles_ $this->epingle_service->getEpinglesSection('legales_services');
  756.     foreach ($epingles_ as $epingle) {
  757.       array_push($this->params['epingles'], $epingle);
  758.     }
  759.     $this->params['breadcrumb'] = [['alias' => '/''titre' => 'Accueil'], ['alias' => '''titre' => $this->params['title']]];
  760.     $this->params['seo_breadcrumb'] = json_encode($this->seo_service->getSeoBreadcrumb($this->params['breadcrumb'], $request), JSON_THROW_ON_ERROR JSON_UNESCAPED_SLASHES JSON_HEX_APOS);
  761.     if ($request->get('function') === 'download_pdf') {
  762.       $this->params['is_pdf'] = 1;
  763.       $pdfOptions = new Options();
  764.       $pdfOptions->set('defaultFont''Arial');
  765.       $pdfOptions->setIsRemoteEnabled(true);
  766.       $dompdf = new Dompdf($pdfOptions);
  767.       $html $this->renderView('Services/Main/detail_page_legale.html.twig'$this->params);
  768.       $dompdf->loadHtml($html);
  769.       $dompdf->setPaper('A4''portrait');
  770.       $dompdf->render();
  771.       $output $dompdf->output();
  772.       $filename sprintf('le-nord-%s.pdf'$this->params['title']);
  773.       return new Response(
  774.         $output,
  775.         200,
  776.         [
  777.           'Content-Type' => 'application/pdf',
  778.           'Content-Disposition' => sprintf('attachment; filename="%s"'"$filename"),
  779.         ]
  780.       );
  781.     } else {
  782.       return $this->render('Services/Main/detail_page_legale.html.twig'$this->params);
  783.     }
  784.   }
  785. }