src/Controller/HomeController.php line 25

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Entity\Portfolios;
  5. use App\Form\ContactType;
  6. use App\Services\MailerService;
  7. use App\Repository\PortfoliosRepository;
  8. use App\Repository\TemoignagesRepository;
  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 HomeController extends AbstractController
  14. {
  15.     /**
  16.      * Affiche la page d'accueil
  17.      *
  18.      * @param TemoignagesRepository $temoignagesRepository
  19.      * @return Response
  20.      */
  21.     #[Route('/'name'app_home')]
  22.     public function index(TemoignagesRepository $temoignagesRepository): Response
  23.     {
  24.         return $this->render('home/index.html.twig', [
  25.             'temoignages' => $temoignagesRepository->returnTemoignages(),
  26.         ]);
  27.     }
  28.     /**
  29.      * Permet de contacter la société
  30.      *
  31.      * @param MailerService $mailer
  32.      * @param Request $request
  33.      * @param TemoignagesRepository $temoignagesRepository
  34.      * @return Response
  35.      */
  36.     #[Route('/contact'name'app_contact')]
  37.     public function contact(MailerService $mailerRequest $requestTemoignagesRepository $temoignagesRepository): Response
  38.     {
  39.         $contact = new Contact();
  40.         $form $this->createForm(ContactType::class, $contact);
  41.         $form->handleRequest($request);
  42.                 
  43.         if ($form->isSubmitted() && $form->isValid()) {
  44.             $mailer->sendEmail(
  45.                 from$contact->getEmail(), 
  46.                 name$contact->getNom(), 
  47.                 template'emails/_contact.html.twig'
  48.                 subject$contact->getSujet(), 
  49.                 content$contact->getMessage()
  50.             );
  51.             $this->addFlash('success''<span class="me-2 fa fa-circle-check"></span>Votre message a bien été envoyé<br>Nous allons vous répondre dans les meilleurs délais');
  52.             return $this->redirectToRoute('app_contact');
  53.         }
  54.         if($form->isSubmitted() && !$form->isValid()) {
  55.             $this->addFlash(
  56.                 'danger'
  57.                 '<span class="me-2 fa fa-circle-exclamation"></span>Des erreurs subsistent, veuillez modifier votre saisie'
  58.             );
  59.         }
  60.         return $this->render('home/contact.html.twig', [
  61.             'temoignages' => $temoignagesRepository->returnTemoignages(),
  62.             'form' => $form->createView(),
  63.             'contact' => $contact
  64.         ]);
  65.     }
  66.     /**
  67.      * Permet de lister les réalisations
  68.      *
  69.      * @return Response
  70.      */
  71.     #[Route('/realisations'name'app_portfolios_index')]
  72.     public function portfolio(): Response
  73.     {
  74.         return $this->render('home/portfolio.html.twig');
  75.     }
  76.     /**
  77.      * Permet de voir une réalisation en détails
  78.      * 
  79.      * @param Portfolios $portfolio
  80.      */
  81.     #[Route('/realisations/{slug}'name'app_portfolios_details')]
  82.     public function portfolioDetails(Portfolios $portfolio): Response
  83.     {
  84.         return $this->render('home/portfolio_details.html.twig', [
  85.             'portfolio' => $portfolio
  86.         ]);
  87.     }
  88. }