<?php
namespace App\Controller;
use App\Entity\Page;
use App\Form\ContactType;
use App\Entity\Configuration;
use App\Service\EmailManager;
use App\Service\ContactManager;
use App\Repository\ConfigurationRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class FooterController extends AbstractController
{
private EmailManager $emailManager;
private ConfigurationRepository $configurationRepository;
public function __construct(EmailManager $emailManager,ConfigurationRepository $configurationRepository)
{
$this->emailManager = $emailManager;
$this->configurationRepository = $configurationRepository;
}
/**
* Récupère l'objet Configuration en bdd
*
* @return Configuration
*/
public function getConfiguration(): Configuration
{
return $this->configurationRepository->findOneBy(['uuid' => Configuration::UNIQUE_UUID]);
}
/**
* @Route("/footer/{slug}", name="app_footer")
*/
public function index(Page $page): Response
{
return $this->render('footer/index.html.twig', [
'page' => $page,
]);
}
/**
* @Route("/contact", name="contact", methods={"GET","POST"})
*/
public function contact(Request $request): Response
{
$user = $this->getUser();
$contactManager = new ContactManager;
$form = $this->createForm(ContactType::class, $contactManager);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$contactManager->setNom(strip_tags(trim($contactManager->getNom())));
$contactManager->setEmail(strip_tags(trim($contactManager->getEmail())));
$contactManager->setSujet(strip_tags(trim($contactManager->getSujet())));
$contactManager->setMessage(strip_tags(trim($contactManager->getMessage())));
$template = 'contact.html.twig';
$data = [
'contactManager' => $contactManager,
];
$this->emailManager->getSendMail($user, $contactManager->getSujet(), $template, $data, $this->getConfiguration()->getEmailContact());
$this->addFlash('success', 'Merci pour votre message, nous vous répondrons dans les plus brefs délais');
return $this->redirectToRoute('contact', [], Response::HTTP_SEE_OTHER);
}
return $this->render('footer/contact.html.twig', [
'form' => $form->createView()
]);
}
}