src/Controller/FooterController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Page;
  4. use App\Form\ContactType;
  5. use App\Entity\Configuration;
  6. use App\Service\EmailManager;
  7. use App\Service\ContactManager;
  8. use App\Repository\ConfigurationRepository;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. class FooterController extends AbstractController
  14. {
  15.     private EmailManager $emailManager;
  16.     private ConfigurationRepository $configurationRepository;
  17.     public function __construct(EmailManager $emailManager,ConfigurationRepository $configurationRepository)
  18.     {
  19.         $this->emailManager $emailManager;
  20.         $this->configurationRepository $configurationRepository;
  21.     }
  22.     /**
  23.      * Récupère l'objet Configuration en bdd
  24.      *
  25.      * @return Configuration
  26.      */
  27.     public function getConfiguration(): Configuration
  28.     {
  29.         return $this->configurationRepository->findOneBy(['uuid' => Configuration::UNIQUE_UUID]);
  30.     }
  31.     
  32.     /**
  33.      * @Route("/footer/{slug}", name="app_footer")
  34.      */
  35.     public function index(Page $page): Response
  36.     {
  37.         return $this->render('footer/index.html.twig', [
  38.             'page' => $page,
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("/contact", name="contact", methods={"GET","POST"})
  43.      */
  44.     public function contact(Request $request): Response
  45.     {
  46.         $user $this->getUser();
  47.         $contactManager = new ContactManager;
  48.         $form $this->createForm(ContactType::class, $contactManager);
  49.         $form->handleRequest($request);
  50.         if ($form->isSubmitted() && $form->isValid()) {
  51.             $contactManager->setNom(strip_tags(trim($contactManager->getNom())));
  52.             $contactManager->setEmail(strip_tags(trim($contactManager->getEmail())));
  53.             $contactManager->setSujet(strip_tags(trim($contactManager->getSujet())));
  54.             $contactManager->setMessage(strip_tags(trim($contactManager->getMessage())));
  55.             $template 'contact.html.twig';
  56.             $data = [
  57.                 'contactManager' => $contactManager,
  58.             ];
  59.             $this->emailManager->getSendMail($user$contactManager->getSujet(), $template$data$this->getConfiguration()->getEmailContact());
  60.             $this->addFlash('success''Merci pour votre message, nous vous répondrons dans les plus brefs délais');
  61.             return $this->redirectToRoute('contact', [], Response::HTTP_SEE_OTHER);
  62.         }
  63.         return $this->render('footer/contact.html.twig', [
  64.             'form' => $form->createView()
  65.         ]);
  66.     }
  67. }