src/Controller/HomeController.php line 23

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Service\SessionParticipationService;
  5. use App\Form\ContactType;
  6. use App\Service\ParticipationMailerService;
  7. use App\Service\UtilService;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  14. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  15. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  16. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  17. class HomeController extends AbstractController
  18. {
  19.     #[Route('/'name'app_home')]
  20.     public function index(SessionParticipationService $sessionParticipationService): Response
  21.     {
  22.         $sessionParticipationService->removeParticipationFromSession();
  23.         return $this->render('home/index.html.twig');
  24.     }
  25.     #[Route('/ouverture'name'app_opening')]
  26.     public function opening(): Response
  27.     {
  28.         return $this->render('home/opening.html.twig', [
  29.             "dateStart" => $this->getParameter("operation_options")["operation_dates"]["date_start"]
  30.         ]);
  31.     }
  32.     #[Route('/fermeture'name'app_closing')]
  33.     public function closing(): Response
  34.     {
  35.         return $this->render('home/closing.html.twig');
  36.     }
  37.     /**
  38.      * @throws TransportExceptionInterface
  39.      * @throws ServerExceptionInterface
  40.      * @throws RedirectionExceptionInterface
  41.      * @throws ClientExceptionInterface
  42.      */
  43.     #[Route('/contact'name'app_contact')]
  44.     public function contact(Request $requestEntityManagerInterface $entityManagerParticipationMailerService $participationMailerServiceUtilService $utilService): Response
  45.     {
  46.         $contact = new Contact();
  47.         $form $this->createForm(ContactType::class, $contact);
  48.         $form->handleRequest($request);
  49.         if ($request->isXmlHttpRequest()) {
  50.             if ($form->isSubmitted() && $form->isValid()) {
  51.                 $entityManager->persist($contact);
  52.                 $entityManager->flush();
  53.                 $participationMailerService->emailContact($contact);
  54.                 if (('Signaler un problème technique sur le site web' === $contact->getTitle()) && ('' !== $_ENV['TECHNICAL_CONTACT'])) {
  55.                     $participationMailerService->emailContact($contact$_ENV['TECHNICAL_CONTACT']);
  56.                 }
  57.                 $route $this->generateUrl("app_contact");
  58.                 $this->addFlash('success''Votre message a été envoyé avec succès');
  59.                 return $this->json([
  60.                     "status" => 1,
  61.                     "data" => [
  62.                         "route" => $route
  63.                     ]
  64.                 ]);
  65.             }
  66.             else {
  67.                 return $this->json([
  68.                     'status' => 0,
  69.                     'data' => $utilService->getErrorMessages($form)
  70.                 ]);
  71.             }
  72.         }
  73.         return $this->render('home/contact.html.twig', [
  74.             'form' => $form->createView(),
  75.             'formAction' => $this->generateUrl('app_contact')
  76.         ]);
  77.     }
  78.     #[Route('/modalites'name'app_terms_use')]
  79.     public function termsUse(): Response
  80.     {
  81.         return $this->render('home/terms_use.html.twig');
  82.     }
  83.     #[Route('/cookies'name'app_cookie')]
  84.     public function cookie(): Response
  85.     {
  86.         return $this->render('home/cookies.html.twig');
  87.     }
  88.     #[Route('/mentions-legales'name'app_legal_notices')]
  89.     public function legalNotices(): Response
  90.     {
  91.         return $this->render('home/legal_notices.html.twig');
  92.     }
  93.     #[Route('/reglement-du-jeu'name'app_rules')]
  94.     public function rules(): Response
  95.     {
  96.         return $this->render('home/rules.html.twig');
  97.     }
  98.     #[Route('/maintenance'name'home_maintenance')]
  99.     public function maintenance(): Response
  100.     {
  101.         return $this->render('home/maintenance.html.twig');
  102.     }
  103.     #[Route('/404/'name'home_404')]
  104.     public function NotFoundRoute(): Response
  105.     {
  106.         return $this->render('bundles/TwigBundle/Exception/error404.html.twig');
  107.     }
  108. }