src/Controller/HomeController.php line 23
<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Service\SessionParticipationService;
use App\Form\ContactType;
use App\Service\ParticipationMailerService;
use App\Service\UtilService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class HomeController extends AbstractController
{
#[Route('/', name: 'app_home')]
public function index(SessionParticipationService $sessionParticipationService): Response
{
$sessionParticipationService->removeParticipationFromSession();
return $this->render('home/index.html.twig');
}
#[Route('/ouverture', name: 'app_opening')]
public function opening(): Response
{
return $this->render('home/opening.html.twig', [
"dateStart" => $this->getParameter("operation_options")["operation_dates"]["date_start"]
]);
}
#[Route('/fermeture', name: 'app_closing')]
public function closing(): Response
{
return $this->render('home/closing.html.twig');
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
#[Route('/contact', name: 'app_contact')]
public function contact(Request $request, EntityManagerInterface $entityManager, ParticipationMailerService $participationMailerService, UtilService $utilService): Response
{
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($request->isXmlHttpRequest()) {
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($contact);
$entityManager->flush();
$participationMailerService->emailContact($contact);
if (('Signaler un problème technique sur le site web' === $contact->getTitle()) && ('' !== $_ENV['TECHNICAL_CONTACT'])) {
$participationMailerService->emailContact($contact, $_ENV['TECHNICAL_CONTACT']);
}
$route = $this->generateUrl("app_contact");
$this->addFlash('success', 'Votre message a été envoyé avec succès');
return $this->json([
"status" => 1,
"data" => [
"route" => $route
]
]);
}
else {
return $this->json([
'status' => 0,
'data' => $utilService->getErrorMessages($form)
]);
}
}
return $this->render('home/contact.html.twig', [
'form' => $form->createView(),
'formAction' => $this->generateUrl('app_contact')
]);
}
#[Route('/modalites', name: 'app_terms_use')]
public function termsUse(): Response
{
return $this->render('home/terms_use.html.twig');
}
#[Route('/cookies', name: 'app_cookie')]
public function cookie(): Response
{
return $this->render('home/cookies.html.twig');
}
#[Route('/mentions-legales', name: 'app_legal_notices')]
public function legalNotices(): Response
{
return $this->render('home/legal_notices.html.twig');
}
#[Route('/reglement-du-jeu', name: 'app_rules')]
public function rules(): Response
{
return $this->render('home/rules.html.twig');
}
#[Route('/maintenance', name: 'home_maintenance')]
public function maintenance(): Response
{
return $this->render('home/maintenance.html.twig');
}
#[Route('/404/', name: 'home_404')]
public function NotFoundRoute(): Response
{
return $this->render('bundles/TwigBundle/Exception/error404.html.twig');
}
}