src/Controller/FrontController.php line 122

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Actualite;
  4. use App\Entity\Demande;
  5. use App\Entity\Page;
  6. use App\Repository\FaqRepository;
  7. use App\Repository\FormuleRepository;
  8. use App\Repository\PageRepository;
  9. use App\Repository\ActualiteRepository;
  10. use App\Repository\AvisRepository;
  11. use App\Repository\PopupRepository;
  12. use App\Repository\SliderRepository;
  13. use App\Service\MailService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Pagerfanta\Doctrine\ORM\QueryAdapter;
  16. use Pagerfanta\Pagerfanta;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  19. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  20. use Symfony\Component\Form\Extension\Core\Type\TextType;
  21. use Symfony\Component\Form\Form;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\Mime\Address;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. class FrontController extends AbstractController
  27. {
  28.     #[Route('/'name'app_default')]
  29.     public function index(
  30.         PageRepository $pageRepository,
  31.         ActualiteRepository $actualiteRepository,
  32.         AvisRepository $avisRepository,
  33.         PopupRepository $popupRepository,
  34.         SliderRepository $sliderRepository,
  35.         FormuleRepository $formuleRepository
  36.     ) : Response
  37.     {
  38.         $page $pageRepository->findOneBySlug('index.html');
  39.         if ($page)
  40.         {
  41.             $src '';
  42.             preg_match'#<img .* src="(.*)".*>#isU'$page->getContenu(), $matches );
  43.             if(isset($matches[1])) $src $matches[1];
  44.             {
  45.                 $slides $sliderRepository->findBy(array('actif' => true),array('id' => 'ASC'));
  46.                 $actualites $actualiteRepository->findLast(3);
  47.                 $avisListe $avisRepository->findAll();
  48.                 $popup $popupRepository->findOneBy(array('actif' => true),array('id' => 'DESC'));
  49.                 $formules $formuleRepository->findAll();
  50.                 return $this->render('front/accueil.html.twig', [
  51.                     'page' => $page,
  52.                     'src' => $src,
  53.                     'slides' => $slides,
  54.                     'actualites' => $actualites,
  55.                     'avisListe' => $avisListe,
  56.                     'popup' => $popup,
  57.                     'formules' => $formules
  58.                 ]);
  59.             }
  60.         }
  61.         throw $this->createNotFoundException('Page introuvable');
  62.     }
  63.     #[Route('/{slug}'name'app_index')]
  64.     public function page(
  65.         Page $page null,
  66.         ActualiteRepository $actualiteRepository,
  67.         AvisRepository $avisRepository,
  68.         FormuleRepository $formuleRepository
  69.     ) : Response
  70.     {
  71.         if ($page)
  72.         {
  73.             $src '';
  74.             $matches = [];
  75.             preg_match'#<img .* src="(.*)".*>#isU'$page->getContenu(), $matches );
  76.             if(isset($matches[1])) $src $matches[1];
  77.             $fomules $formuleRepository->findAll();
  78.             if ($page->isAccueil())
  79.             {
  80.                 $actualites $actualiteRepository->findLast(3);
  81.                 $avisListe $avisRepository->findAll();
  82.                 return $this->render('front/accueil.html.twig', [
  83.                     'page' => $page,
  84.                     'src' => $src,
  85.                     'actualites' => $actualites,
  86.                     'avisListe' => $avisListe,
  87.                     'formules' => $fomules
  88.                 ]);
  89.             } elseif ($page->getTemplate() == || $page->getTemplate() == null){
  90.                 return $this->render('front/page.html.twig', [
  91.                     'page' => $page,
  92.                     'formules' => $fomules,
  93.                     'src' => $src
  94.                 ]);
  95.             } elseif ($page->getTemplate() == 2){
  96.                 return $this->render('front/cours.html.twig', [
  97.                     'page' => $page,
  98.                     'formules' => $fomules,
  99.                     'src' => $src
  100.                 ]);
  101.             }
  102.             return $this->render('front/page.html.twig', [
  103.                 'page' => $page,
  104.                 'formules' => $fomules,
  105.                 'src' => $src
  106.             ]);
  107.         }
  108.         throw $this->createNotFoundException('Page introuvable');
  109.     }
  110.     #[Route('/actualites'name'app_actualites'priority1)]
  111.     public function actualites(
  112.         ActualiteRepository $actualiteRepository,
  113.         FormuleRepository $formuleRepository
  114.     ) : Response
  115.     {
  116.         $queryBuilder $actualiteRepository->createOrderedByDateQueryBuilder();
  117.         $adapter = new QueryAdapter($queryBuilder);
  118.         $formules $formuleRepository->findAll();
  119.         $pagerfanta Pagerfanta::createForCurrentPageWithMaxPerPage(
  120.             $adapter,
  121.             1,
  122.             9
  123.         );
  124.         return $this->render('front/actualites.html.twig', [
  125.             'pager' => $pagerfanta,
  126.             'formules' => $formules
  127.         ]);
  128.     }
  129.     #[Route('/actualite/{slug}'name'app_actualite_detail')]
  130.     public function actualiteDetail(
  131.         Actualite $actualite null,
  132.         ActualiteRepository $actualiteRepository,
  133.         FormuleRepository $formuleRepository
  134.     ) : Response
  135.     {
  136.         $fomules $formuleRepository->findAll();
  137.         $actualites $actualiteRepository->findBy(array('categorie' => $actualite->getCategorie()->getId()), null3);
  138.         $fomules $formuleRepository->findAll();
  139.         return $this->render('front/actu-detail.html.twig', [
  140.             'actualite' => $actualite,
  141.             'actualites' => $actualites,
  142.             'formules' => $fomules
  143.         ]);
  144.     }
  145.     #[Route('/contact.html'name'app_contact'priority1)]
  146.     public function contact(Request $requestEntityManagerInterface $entityManagerMailService $mailService) : Response
  147.     {
  148.         $demande = new Demande();
  149.         $form $this->createFormBuilder($demande)
  150.             ->add('nom',TextType::class)
  151.             ->add('prenom',TextType::class, [
  152.                 'required' => false,
  153.             ])
  154.             ->add('telephone',TextType::class)
  155.             ->add('email',EmailType::class)
  156.             ->add('sujet',TextType::class, [
  157.                 'required' => false,
  158.             ])
  159.             ->add('message',TextareaType::class);
  160.         $form $form->getForm();
  161.         $form->handleRequest($request);
  162.         if ($form->isSubmitted() && $form->isValid()) {
  163.             /** @var Demande $demande */
  164.             $demande $form->getData();
  165.             $to = new Address($this->getParameter('email_admin'),'Ecole de Surf Côte Sauvage');
  166.             $from = new Address($demande->getEmail(), $demande->getNom(). ' ' .$demande->getPrenom());
  167.             $sujet $demande->getSujet();
  168.             $message $demande->getMessage();
  169.             $data = array("secret" => "0xac8d6075a37A4ED5B28915701b14cff918D15726""response" => $_POST["h-captcha-response"]);
  170.             $verify curl_init();
  171.             curl_setopt($verifyCURLOPT_URL"https://hcaptcha.com/siteverify");
  172.             curl_setopt($verifyCURLOPT_POSTtrue);
  173.             curl_setopt($verifyCURLOPT_POSTFIELDShttp_build_query($data));
  174.             curl_setopt($verifyCURLOPT_RETURNTRANSFERtrue);
  175.             $response curl_exec($verify);
  176.             // var_dump($response);
  177.             $responseData json_decode($response);
  178.             if (!$responseData->success) {
  179.                 $this->addFlash('error''<p>Valider le captcha anti-robot.</p>');
  180.             } else {
  181.                 $res $mailService->sendEmail($to$from$sujet,'front/contact-email.html.twig',[
  182.                     'nom' => $demande->getNom(),
  183.                     'prenom' => $demande->getPrenom(),
  184.                     'phone' => $demande->getTelephone(),
  185.                     'add_email' => $demande->getEmail(),
  186.                     'sujet' => $demande->getSujet(),
  187.                     'message' => $message
  188.                 ]);
  189.                 $entityManager->persist($demande);
  190.                 $entityManager->flush();
  191.                 $this->addFlash('success''<p>Votre demande a bien été enregistrée et nous vous en remercions.</p>
  192.                         <p>Nous allons vous contacter dans les plus brefs délais.</p>');
  193.             }
  194. //            return $this->redirectToRoute('app_contact');
  195.         }
  196.         return $this->render('front/contact.html.twig', [
  197.             'form' => $form->createView()
  198.         ]);
  199.     }
  200.     #[Route('/faq.html'name'app_faq'priority1)]
  201.     public function faq(
  202.         Request $request,
  203.         FaqRepository $faqRepository,
  204.         FormuleRepository $formuleRepository
  205.     ) : Response
  206.     {
  207.         $faqList $faqRepository->findAll();
  208.         $forules $formuleRepository->findAll();
  209.         return $this->render('front/faq.html.twig',[
  210.             'faqList' => $faqList,
  211.             'formules' => $forules
  212.         ]);
  213.     }
  214. }