src/Controller/FrontController.php line 229

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\About;
  4. use App\Entity\Actuality;
  5. use App\Entity\ActualityCategory;
  6. use App\Entity\ActualityPage;
  7. use App\Entity\Composition;
  8. use App\Entity\Contact;
  9. use App\Entity\ContactPage;
  10. use App\Entity\DefinitionPage;
  11. use App\Entity\Departement;
  12. use App\Entity\FullMemberPage;
  13. use App\Entity\Join;
  14. use App\Entity\ManuelPage;
  15. use App\Entity\Newsletter;
  16. use App\Entity\Page;
  17. use App\Entity\PartenairePage;
  18. use App\Entity\Publication;
  19. use App\Entity\PublicationPage;
  20. use App\Entity\ThemePublication;
  21. use App\Entity\These;
  22. use App\Entity\ThesePage;
  23. use App\Form\ContactFormType;
  24. use App\Form\NewsletterType;
  25. use App\Repository\AboutRepository;
  26. use App\Repository\ActualityCategoryRepository;
  27. use App\Repository\ActualityLabelRepository;
  28. use App\Repository\ActualityPageRepository;
  29. use App\Repository\ActualityRepository;
  30. use App\Repository\CompositionRepository;
  31. use App\Repository\ContactPageRepository;
  32. use App\Repository\DefinitionPageRepository;
  33. use App\Repository\DefinitionRepository;
  34. use App\Repository\DepartementRepository;
  35. use App\Repository\FullMemberPageRepository;
  36. use App\Repository\HomepageRepository;
  37. use App\Repository\JoinRepository;
  38. use App\Repository\ManuelPageRepository;
  39. use App\Repository\PageRepository;
  40. use App\Repository\PartenairePageRepository;
  41. use App\Repository\PublicationPageRepository;
  42. use App\Repository\PublicationRepository;
  43. use App\Repository\ThemePublicationRepository;
  44. use App\Repository\ThemeRepository;
  45. use App\Repository\ThesePageRepository;
  46. use App\Repository\TheseRepository;
  47. use App\Service\DataImportCsv;
  48. use Cofondateur\SocleTechniqueBundle\Sitemap\SitemapService;
  49. use Doctrine\ORM\EntityManagerInterface;
  50. use Doctrine\Persistence\ManagerRegistry;
  51. use GuzzleHttp\Client;
  52. use Pagerfanta\Adapter\ArrayAdapter;
  53. use Pagerfanta\Doctrine\ORM\QueryAdapter;
  54. use Pagerfanta\Exception\NotValidCurrentPageException;
  55. use Pagerfanta\Pagerfanta;
  56. use Psr\Log\LoggerInterface;
  57. use SendinBlue\Client\Api\ContactsApi;
  58. use SendinBlue\Client\ApiException;
  59. use SendinBlue\Client\Configuration;
  60. use SendinBlue\Client\Model\CreateContact;
  61. use SendinBlue\Client\Model\CreateList;
  62. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  63. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  64. use Symfony\Component\HttpFoundation\Request;
  65. use Symfony\Component\HttpFoundation\Response;
  66. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  67. use Symfony\Component\Mailer\MailerInterface;
  68. use Symfony\Component\Mime\Address;
  69. use Symfony\Component\Routing\Annotation\Route;
  70. class FrontController extends AbstractController
  71. {
  72.     /** @var ManagerRegistry */
  73.     private $em;
  74.     public function __construct(ManagerRegistry $em)
  75.     {
  76.         $this->em $em;
  77.     }
  78.     /**
  79.      * @Route("/", name="app_homepage")
  80.      */
  81.     public function index(HomepageRepository $homepageRepository): Response
  82.     {
  83.         $homepage $homepageRepository->findUnique();
  84.         return $this->render('front/index.html.twig', [
  85.             'homepage' => $homepage,
  86.         ]);
  87.     }
  88.     /**
  89.      * @Route("/association/a-propos", name="app_about_index")
  90.      */
  91.     public function about(Request $request): Response
  92.     {
  93.         /** @var AboutRepository $repo */
  94.         $repo $this->em->getRepository(About::class);
  95.         $page $repo->findUnique();
  96.         return $this->render('front/About/index.html.twig', array('page' => $page));
  97.     }
  98.     /**
  99.      * @Route("/association/composition", name="app_composition_index")
  100.      */
  101.     public function composition(Request $request): Response
  102.     {
  103.         /** @var CompositionRepository $repo */
  104.         $repo $this->em->getRepository(Composition::class);
  105.         $page $repo->findUnique();
  106.         return $this->render('front/Composition/index.html.twig', array('page' => $page));
  107.     }
  108.     /**
  109.      * @Route("/association/membres-titulaires", name="app_full_member_page_index")
  110.      */
  111.     public function fullMemberPage(Request $request): Response
  112.     {
  113.         /** @var FullMemberPageRepository $repo */
  114.         $repo $this->em->getRepository(FullMemberPage::class);
  115.         $page $repo->findUnique();
  116.         return $this->render('front/FullMemberPage/index.html.twig', array('page' => $page));
  117.     }
  118.     /**
  119.      * @Route("/association/departements", name="app_departement_index")
  120.      */
  121.     public function departement(Request $request): Response
  122.     {
  123.         /** @var DepartementRepository $repo */
  124.         $repo $this->em->getRepository(Departement::class);
  125.         $page $repo->findUnique();
  126.         return $this->render('front/Departement/index.html.twig', array('page' => $page));
  127.     }
  128.     /**
  129.      * @Route("/associations/partenaire", name="app_partenaire_page_index")
  130.      */
  131.     public function partenairePage(Request $request): Response
  132.     {
  133.         /** @var PartenairePageRepository $repo */
  134.         $repo $this->em->getRepository(PartenairePage::class);
  135.         $page $repo->findUnique();
  136.         return $this->render('front/PartenairePage/index.html.twig', array('page' => $page));
  137.     }
  138.     /**
  139.      * @Route("/theme/{slugTheme}/{slugPage}", name="app_page_show")
  140.      */
  141.     public function showPage(Request $requeststring $slugThemestring $slugPageThemeRepository $themeRepositoryPageRepository $pageRepositoryThemePublicationRepository $themePublicationRepository): Response
  142.     {
  143.         if ($slugTheme !== 'publication') {
  144.             $theme $themeRepository->findOneBy(['slug' => $slugTheme]);
  145.             $page $pageRepository->findOneBy(['theme' => $theme'slug' => $slugPage]);
  146.             if (!$theme || !$page || $page->getTheme()->getId() !== $theme->getId()) {
  147.                 throw $this->createNotFoundException();
  148.             }
  149.         } else {
  150.             $page $pageRepository->findOneBy(['slug' => $slugPage'themePublication' => true]);
  151.             $theme $themePublicationRepository->findUnique();
  152.             if (!$page) {
  153.                 throw $this->createNotFoundException();
  154.             }
  155.         }
  156.         return $this->render('front/Page/show.html.twig', array(
  157.             'page' => $page,
  158.             'theme' => $theme
  159.         ));
  160.     }
  161.     /**
  162.      * @Route("/publications/detail/{slug}", name="app_publication_show")
  163.      */
  164.     public function showPublication(Request $requestPublication $publication): Response
  165.     {
  166.         return $this->render('front/Publication/show.html.twig', array('page' => $publication));
  167.     }
  168.     /**
  169.      * @Route("/publications/{page}", name="app_publication_list", requirements={"page"="\d+"}, defaults={"page": 1})
  170.      */
  171.     public function listPublications(Request $request$page): Response
  172.     {
  173.         /** @var PublicationRepository $repo */
  174.         $repo $this->em->getRepository(Publication::class);
  175.         $qb $repo->createQueryBuilder('e');
  176.         $qb->andWhere('e.activate = true');
  177.         $publications = new Pagerfanta(new QueryAdapter($qb->orderBy('e.date''DESC')));
  178.         $publications->setMaxPerPage(10);
  179.         $publications->setCurrentPage($page);
  180.         $pageNb $page;
  181.         /** @var PublicationPageRepository $repo */
  182.         $repo $this->em->getRepository(PublicationPage::class);
  183.         $page $repo->findUnique();
  184.         return $this->render('front/Publication/list.html.twig', array(
  185.             'publications' => $publications,
  186.             'page' => $page,
  187.             'openTab' => $pageNb 1
  188.         ));
  189.     }
  190.     /**
  191.      * @Route("/theses/detail/{slug}", name="app_these_show")
  192.      */
  193.     public function showThese(Request $requestThese $these): Response
  194.     {
  195.         return $this->render('front/These/show.html.twig', array('page' => $these));
  196.     }
  197.     /**
  198.      * @Route("/theses/{page}", name="app_these_list", requirements={"page"="\d+"}, defaults={"page": 1})
  199.      */
  200.     public function listTheses(Request $request$page): Response
  201.     {
  202.         /** @var TheseRepository $repo */
  203.         $repo $this->em->getRepository(These::class);
  204.         $qb $repo->createQueryBuilder('e');
  205.         $qb->andWhere('e.activate = true');
  206.         $qb->orderBy('e.date''DESC');
  207.         $theses = new Pagerfanta(new QueryAdapter($qb));
  208.         $theses->setMaxPerPage(10);
  209.         $theses->setCurrentPage($page);
  210.         $pageNb $page;
  211.         /** @var ThesePageRepository $repo */
  212.         $repo $this->em->getRepository(ThesePage::class);
  213.         $page $repo->findUnique();
  214.         return $this->render('front/These/list.html.twig', array(
  215.             'theses' => $theses,
  216.             'page' => $page,
  217.             'openTab' => $pageNb 1
  218.         ));
  219.     }
  220.     /**
  221.      * @Route("/actualites/detail/{slug}", name="app_actuality_show")
  222.      */
  223.     public function showActuality(Request $requestActuality $actuality): Response
  224.     {
  225.         return $this->render('front/Actuality/show.html.twig', array('page' => $actuality));
  226.     }
  227.     /**
  228.      * @Route("/actualites/{page}/{category}", name="app_actuality_list", requirements={"page"="\d+"}, defaults={"page": 1, "category": null})
  229.      */
  230.     public function listActualitys(Request $request$page$categoryActualityCategoryRepository $actualityCategoryRepositoryActualityLabelRepository $actualityLabelRepository): Response
  231.     {
  232.         /** @var ActualityRepository $repo */
  233.         $repo $this->em->getRepository(Actuality::class);
  234.         $qb $repo->createQueryBuilder('e');
  235.         $qb->andWhere('e.activate = true');
  236.         $categoryActive null;
  237.         if ($category !== null) {
  238.             $qb->leftJoin('e.category''c')
  239.                 ->addSelect('c')
  240.                 ->andWhere('c.slug = :category')
  241.                 ->setParameter('category'$category);
  242.             $categoryActive $actualityCategoryRepository->findOneBy(['slug' => $category]);
  243.         }
  244.         $label $request->query->get('label');
  245.         $labelActive null;
  246.         if ($label !== null) {
  247.             $qb->leftJoin('e.labels''l')
  248.                 ->addSelect('l')
  249.                 ->andWhere('l.slug = :label')
  250.                 ->setParameter('label'$label);
  251.             $labelActive $actualityLabelRepository->findOneBy(['slug' => $label]);
  252.         }
  253.         $actualitys = new Pagerfanta(new QueryAdapter($qb->orderBy('e.createdAt''DESC')));
  254.         $actualitys->setMaxPerPage(10);
  255.         $actualitys->setCurrentPage($page);
  256.         /** @var ActualityPageRepository $repo */
  257.         $repo $this->em->getRepository(ActualityPage::class);
  258.         $page $repo->findUnique();
  259.         return $this->render('front/Actuality/list.html.twig', array(
  260.             'actualities' => $actualitys,
  261.             'page' => $page,
  262.             'categoryActive' => $categoryActive,
  263.             'labelActive' => $labelActive,
  264.         ));
  265.     }
  266.     /**
  267.      * @Route("/definitions", name="app_definition_page_index")
  268.      */
  269.     public function definitionPage(Request $requestDefinitionRepository $definitionRepository): Response
  270.     {
  271.         /** @var DefinitionPageRepository $repo */
  272.         $repo $this->em->getRepository(DefinitionPage::class);
  273.         $page $repo->findUnique();
  274.         $definitions $definitionRepository->findBy([], ['letter' => "ASC"]);
  275.         // Grouper les définitions par lettre
  276.         $letters array_reduce($definitions, function ($acc$definition) {
  277.             $letter strtoupper($definition->getLetter());
  278.             if (!isset($acc[$letter])) {
  279.                 $acc[$letter] = [];
  280.             }
  281.             $acc[$letter][] = $definition;
  282.             return $acc;
  283.         }, []);
  284.         // Trier chaque groupe de définitions par le champ `name`
  285.         foreach ($letters as &$group) {
  286.             usort($group, function ($a$b) {
  287.                 return strcmp($a->getName(), $b->getName());
  288.             });
  289.         }
  290.         return $this->render('front/DefinitionPage/index.html.twig', [
  291.             'page' => $page,
  292.             'letters' => $letters,
  293.         ]);
  294.     }
  295.     /**
  296.      * @Route("/adherer", name="app_join_index")
  297.      */
  298.     public function join(Request $request): Response
  299.     {
  300.         /** @var JoinRepository $repo */
  301.         $repo $this->em->getRepository(Join::class);
  302.         $page $repo->findUnique();
  303.         return $this->render('front/Join/index.html.twig', array('page' => $page));
  304.     }
  305.     /**
  306.      * @Route("/contact", name="app_contact_show")
  307.      */
  308.     public function showContact(Request $requestEntityManagerInterface $emMailerInterface $mailerLoggerInterface $logger): Response
  309.     {
  310.         /** @var ContactPageRepository $repo */
  311.         $repo $this->em->getRepository(ContactPage::class);
  312.         $page $repo->findUnique();
  313.         $contact = new Contact;
  314.         $form $this->createForm(ContactFormType::class, $contact);
  315.         $form->handleRequest($request);
  316.         
  317.         if ($form->isSubmitted() && $form->isValid()) {
  318.             $contact->setCreatedAt(new \DateTime());
  319.             $em->persist($contact);
  320.             $em->flush();
  321.             $recipients $_ENV['MAIL_RECIPIENT'];
  322.             $recipients explode(','$recipients);
  323.             $datasMail = [
  324.                 'name' => $contact->getFirstname() . ' ' $contact->getName(),
  325.                 'job' => $contact->getJob(),
  326.                 'email' => $contact->getEmail(),
  327.                 'phone' => $contact->getPhone(),
  328.                 'message' => $contact->getMessage(),
  329.                 'date' => $contact->getCreatedAt()->format('d/m/Y H:i'),
  330.             ];
  331.             $email = (new TemplatedEmail())
  332.                 ->from(new Address($_ENV['MAIL_SENDER'], 'SFMG'))
  333.                 ->to(...$recipients)
  334.                 ->subject("Vous avez reçu une nouvelle demande de contact")
  335.                 // path of the Twig template to render
  336.                 ->htmlTemplate('mail/contact.html.twig')
  337.                 // pass variables (name => value) to the template
  338.                 ->context(["data" => $datasMail]);
  339.             try {
  340.                 $mailer->send($email);
  341.                 $this->addFlash('successContact''Merci nous avons reçu votre demande. Nous vous répondrons dans les plus brefs délais.');
  342.             }  catch (TransportExceptionInterface $e) {
  343.                 $this->addFlash('errorContact''Une erreur est survenue lors de l\'envoi du message. Merci de réessayer.');
  344.                 $logger->error('Error sending contact email: ' $e->getMessage());
  345.             }
  346.         }
  347.         return $this->render('front/Contact/show.html.twig', array(
  348.             'page' => $page,
  349.             'form' => $form->createView(),
  350.         ));
  351.     }
  352.     /**
  353.      * @Route("/search", name="app_search_index")
  354.      */
  355.     public function search(Request $requestActualityRepository $actualityRepositoryPageRepository $pageRepositoryTheseRepository $theseRepositoryPublicationRepository $publicationRepositoryDefinitionRepository $definitionRepository): Response
  356.     {
  357.         $query $request->get('query'''); // Get the search query, default to an empty string
  358.         // Default to 1 if no specific page parameter is provided
  359.         $pageActualities $request->query->getInt('actualities_page'1);
  360.         $pagePages $request->query->getInt('pages_page'1);
  361.         $pageTheses $request->query->getInt('theses_page'1);
  362.         $pagePublications $request->query->getInt('publications_page'1);
  363.         $pagesDefined = [
  364.             'actualities' => $request->query->getInt('actualities_page'),
  365.             'pages' => $request->query->getInt('pages_page'),
  366.             'theses' => $request->query->getInt('theses_page'),
  367.             'publications' => $request->query->getInt('publications_page'),
  368.         ];
  369.         $maxPerPage 10// Set the number of items per page
  370.         $result = [];
  371.         $result['actualities'] = [
  372.             'title' => 'Actualités',
  373.         ];
  374.         $result['pages'] = [
  375.             'title' => 'Pages',
  376.         ];
  377.         $result['theses'] = [
  378.             'title' => 'Thèses',
  379.         ];
  380.         $result['publications'] = [
  381.             'title' => 'Publications',
  382.         ];
  383.         $result['definitions'] = [
  384.             'title' => 'Définitions',
  385.         ];
  386.         $result['lengthTotal'] = 0;
  387.         try {
  388.             // Actualities pagination
  389.             $qbActualities $actualityRepository->createQueryBuilder('p')
  390.                 ->andWhere('p.title LIKE :query OR p.resume LIKE :query')
  391.                 // Filtrer les actualités activées
  392.                 ->andWhere('p.activate = true')
  393.                 // Joindre les sections liées à Actuality
  394.                 ->leftJoin('p.sections''s')
  395.                 ->addSelect('s')
  396.                 // Rechercher dans s.title
  397.                 ->orWhere('s.title LIKE :query')
  398.                 // Joindre les paragraphs liés aux sections
  399.                 ->leftJoin('s.paragraphs''par')
  400.                 ->addSelect('par')
  401.                 // Rechercher dans les propriétés de Paragraph
  402.                 ->orWhere('par.subTitle LIKE :query')
  403.                 ->orWhere('par.title LIKE :query')
  404.                 ->orWhere('par.text LIKE :query')
  405.                 ->orWhere('par.secondSubTitle LIKE :query')
  406.                 ->orWhere('par.secondTitle LIKE :query')
  407.                 ->orWhere('par.secondText LIKE :query')
  408.                 ->setParameter('query''%' $query '%');
  409.             $actualities $qbActualities->getQuery()->getResult();
  410.             $result['actualities']['data'] = $actualities;
  411.             $result['actualities']['length'] = count($actualities);
  412.             $result['lengthTotal'] += $result['actualities']['length'];
  413.             // Pages pagination
  414.             $pages $pageRepository->createQueryBuilder('p')
  415.                 ->andWhere('p.title LIKE :query')
  416.                 ->andWhere('p.activate = true')
  417.                 ->andWhere('p.theme IS NOT NULL OR p.themePublication = true')
  418.                 // Joindre les sections liées à Actuality
  419.                 ->leftJoin('p.sections''s')
  420.                 ->addSelect('s')
  421.                 // Rechercher dans s.title
  422.                 ->orWhere('s.title LIKE :query')
  423.                 // Joindre les paragraphs liés aux sections
  424.                 ->leftJoin('s.paragraphs''par')
  425.                 ->addSelect('par')
  426.                 // Rechercher dans les propriétés de Paragraph
  427.                 ->orWhere('par.subTitle LIKE :query')
  428.                 ->orWhere('par.title LIKE :query')
  429.                 ->orWhere('par.text LIKE :query')
  430.                 ->orWhere('par.secondSubTitle LIKE :query')
  431.                 ->orWhere('par.secondTitle LIKE :query')
  432.                 ->orWhere('par.secondText LIKE :query')
  433.                 ->setParameter('query''%' $query '%')->getQuery()->getResult();
  434.             $result['pages']['data'] = $pages;
  435.             $result['pages']['length'] = count($pages);
  436.             $result['lengthTotal'] += $result['pages']['length'];
  437.             // Theses pagination
  438.             $qbThese $theseRepository->createQueryBuilder('p')
  439.                 ->andWhere('p.title LIKE :query OR p.author LIKE :query')
  440.                 ->andWhere('p.activate = true')
  441.                 // Joindre les sections liées à Actuality
  442.                 ->leftJoin('p.sections''s')
  443.                 ->addSelect('s')
  444.                 // Rechercher dans s.title
  445.                 ->orWhere('s.title LIKE :query')
  446.                 // Joindre les paragraphs liés aux sections
  447.                 ->leftJoin('s.paragraphs''par')
  448.                 ->addSelect('par')
  449.                 // Rechercher dans les propriétés de Paragraph
  450.                 ->orWhere('par.subTitle LIKE :query')
  451.                 ->orWhere('par.title LIKE :query')
  452.                 ->orWhere('par.text LIKE :query')
  453.                 ->orWhere('par.secondSubTitle LIKE :query')
  454.                 ->orWhere('par.secondTitle LIKE :query')
  455.                 ->orWhere('par.secondText LIKE :query')
  456.                 ->setParameter('query''%' $query '%');
  457.             $theses $qbThese->getQuery()->getResult();
  458.             $result['theses']['data'] = $theses;
  459.             $result['theses']['length'] = count($theses);
  460.             $result['lengthTotal'] += $result['theses']['length'];
  461.             // Publications pagination
  462.             $qbPublication $publicationRepository->createQueryBuilder('p')
  463.                 ->andWhere('p.title LIKE :query OR p.author LIKE :query')
  464.                 ->andWhere('p.activate = true')
  465.                 // Joindre les sections liées à Actuality
  466.                 ->leftJoin('p.sections''s')
  467.                 ->addSelect('s')
  468.                 // Rechercher dans s.title
  469.                 ->orWhere('s.title LIKE :query')
  470.                 // Joindre les paragraphs liés aux sections
  471.                 ->leftJoin('s.paragraphs''par')
  472.                 ->addSelect('par')
  473.                 // Rechercher dans les propriétés de Paragraph
  474.                 ->orWhere('par.subTitle LIKE :query')
  475.                 ->orWhere('par.title LIKE :query')
  476.                 ->orWhere('par.text LIKE :query')
  477.                 ->orWhere('par.secondSubTitle LIKE :query')
  478.                 ->orWhere('par.secondTitle LIKE :query')
  479.                 ->orWhere('par.secondText LIKE :query')
  480.                 ->setParameter('query''%' $query '%');
  481.             $publications $qbPublication->getQuery()->getResult();
  482.             $result['publications']['data'] = $publications;
  483.             $result['publications']['length'] = count($publications);
  484.             $result['lengthTotal'] += $result['publications']['length'];
  485.             $qbDefinition $definitionRepository->createQueryBuilder('p')
  486.                 ->andWhere('p.name LIKE :query OR p.definition LIKE :query')
  487.                 ->setParameter('query''%' $query '%');
  488.             $definitions $qbDefinition->getQuery()->getResult();
  489.             $result['definitions']['data'] = $definitions;
  490.             $result['definitions']['length'] = count($definitions);
  491.             $result['lengthTotal'] += $result['definitions']['length'];
  492.         } catch (NotValidCurrentPageException $e) {
  493.             // Handle the case where the current page is not valid
  494.             return $this->redirectToRoute('app_search_index', ['query' => $query'actualities_page' => 1'pages_page' => 1'theses_page' => 1'publications_page' => 1]);
  495.         }
  496.         return $this->render('front/Search/index.html.twig', [
  497.             'result' => $result,
  498.             'query' => $query,
  499.             'pageDefined' => $pagesDefined,
  500.         ]);
  501.     }
  502. /**
  503.  * @Route("subsribe-newsletter", name="app_subscribe_newsletter")
  504.  */
  505. public function subscribe(Request $requestEntityManagerInterface $emMailerInterface $mailerLoggerInterface $logger): Response
  506. {
  507.     $newsletter = new Newsletter();
  508.     $form $this->createForm(NewsletterType::class, $newsletter);
  509.     $form->handleRequest($request);
  510.     if ($form->isSubmitted() && $form->isValid()) {
  511.         $newsletter->setCreatedAt(new \DateTimeImmutable());
  512.         $em->persist($newsletter);
  513.         $em->flush();
  514.         $email $newsletter->getEmail();
  515.         $name $newsletter->getName();
  516.         if (empty($email)) {
  517.             return $this->redirectToRoute('app_homepage');
  518.         }
  519.         $config Configuration::getDefaultConfiguration()->setApiKey('api-key''your-api-key');
  520.         $contactsApi = new ContactsApi(new Client(), $config);
  521.         try {
  522.             $contactsApi->getContactInfo($email);
  523.             $this->addFlash('successNewsletter'"Votre email est déjà inscrit.");
  524.         } catch (ApiException $e) {
  525.             $listId 128;
  526.             $createContact = new CreateContact([
  527.                 'email' => $email,
  528.                 'listIds' => [$listId],
  529.                 'attributes' => ['LASTNAME' => $name],
  530.                 'updateEnabled' => true
  531.             ]);
  532.             try {
  533.                 $contactsApi->createContact($createContact);
  534.                 $recipients explode(','$_ENV['MAIL_RECIPIENT']);
  535.                 $datasMail = ['name' => $name'email' => $email'date' => (new \DateTime())->format('d/m/Y H:i')];
  536.                 $email = (new TemplatedEmail())
  537.                     ->from(new Address($_ENV['MAIL_SENDER'], 'SFMG'))
  538.                     ->to(...$recipients)
  539.                     ->subject("Une nouvelle personne s'est inscrite à la newsletter")
  540.                     ->htmlTemplate('mail/newsletter.html.twig')
  541.                     ->context(["data" => $datasMail]);
  542.                 $mailer->send($email);
  543.                 $this->addFlash('successNewsletter''L\'email ' $email " a bien été ajouté à notre newsletter.");
  544.             } catch (\Exception $e) {
  545.                 $this->addFlash('errorNewsletter'"Une erreur s'est produite, merci de réessayer.");
  546.             }
  547.         }
  548.         return $this->redirectToRoute('app_homepage');
  549.     }
  550.     return $this->redirectToRoute('app_homepage');
  551. }
  552.     public function getNewsletterForm(): Response
  553.     {
  554.         $newsletter = new Newsletter();
  555.         $form $this->createForm(NewsletterType::class, null, [
  556.             'confidentiality_path' => $this->generateUrl('app_confidentiality'),
  557.         ]);
  558.         return $this->render('commons/_newsletter_form.html.twig', [
  559.             'newsletterForm' => $form->createView(),
  560.         ]);
  561.     }
  562.     
  563.     /**
  564.      * @Route("/publications/manuels", name="app_manuel_page_index")
  565.      */
  566.     public function manuelPage(Request $request): Response
  567.     {
  568.         /** @var ManuelPageRepository $repo */
  569.         $repo $this->em->getRepository(ManuelPage::class);
  570.         $page $repo->findUnique();
  571.         return $this->render('front/ManuelPage/index.html.twig', array('page' => $page));
  572.     }
  573.     /**
  574.      * @Route("/sitemap.{_format}", name="app_sitemap_front", format="html")
  575.      */
  576.     public function sitemap(Request $requestSitemapService $sitemapService): Response
  577.     {
  578.         $format $request->getRequestFormat();
  579.         $links $sitemapService->generateSitemap();
  580.         $template 'front/';
  581.         if ($format === 'xml') {
  582.             $template .= 'sitemap/index.xml.twig';
  583.         } else {
  584.             $template .= 'sitemap/index.html.twig';
  585.         }
  586.         return $this->render($template, [
  587.             'sitemapLinkGroups' => $links
  588.         ]);
  589.     }
  590.     /**
  591.      * @Route("/mentions-legales", name="app_legal_terms")
  592.      */
  593.     public function legalTerms(): Response
  594.     {
  595.         return $this->render('front/legalTerms.html.twig');
  596.     }
  597.     /**
  598.      * @Route("/confidentialite", name="app_confidentiality")
  599.      */
  600.     public function confidentiality(): Response
  601.     {
  602.         return $this->render('front/confidentiality.html.twig',array(
  603.             'siteName' => $_ENV['SITENAME'],
  604.             'hostname' => $_ENV['HOSTNAME']
  605.         ));
  606.     }
  607. }