src/Controller/HomeController.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Twig\Environment;
  4. use DateTimeImmutable;
  5. use App\Entity\Booking;
  6. use App\Service\Mailjet;
  7. use App\Entity\Testimonial;
  8. use App\Service\StaticData;
  9. use App\Form\TestimonialType;
  10. use App\Service\CheckRecaptcha;
  11. use App\Form\CheckAvailabilityType;
  12. use App\Repository\VideoRepository;
  13. use App\Repository\AboutAreaRepository;
  14. use App\Repository\BookingConstraintRepository;
  15. use App\Repository\HobbyAreaRepository;
  16. use App\Repository\IntroAreaRepository;
  17. use Doctrine\ORM\EntityManagerInterface;
  18. use App\Repository\GalleryAreaRepository;
  19. use App\Repository\HobbySingleRepository;
  20. use App\Repository\ServiceAreaRepository;
  21. use App\Repository\TestimonialRepository;
  22. use App\Repository\GalleryCategoryRepository;
  23. use App\Repository\TestimonialAreaRepository;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. use App\Repository\HomeMainSliderImageRepository;
  28. use App\Repository\ServiceCategoryRepository;
  29. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  30. class HomeController extends AbstractController
  31. {
  32.     public function __construct(EntityManagerInterface $managerBookingConstraintRepository $bookingConstraintRepoStaticData $staticsEnvironment $twig)
  33.     {
  34.         $this->manager    $manager;
  35.         $this->twig       $twig;
  36.         $this->statics    $statics->getStaticData();
  37.         $this->constraint $bookingConstraintRepo->findOneBy([]);
  38.     }
  39.     /**
  40.      * @Route("/", name="home")
  41.      */
  42.     public function index(Request $requestCheckRecaptcha $recaptchaHomeMainSliderImageRepository $sliderRepoAboutAreaRepository $aboutAreaRepoIntroAreaRepository $introAreaRepoVideoRepository $videoRepoHobbyAreaRepository $hobbyAreaRepoHobbySingleRepository $hobbySingleRepoGalleryAreaRepository $galleryAreaRepoGalleryCategoryRepository $galleryCategoryRepoServiceAreaRepository $serviceAreaRepoServiceCategoryRepository $serviceCatRepoTestimonialAreaRepository $testimonialAreaRepoTestimonialRepository $testimonialRepo): Response
  43.     {
  44.         $slides            $sliderRepo->findAll();
  45.         $introArea         $introAreaRepo->findOneBy([]);
  46.         $videoArea         $videoRepo->findOneBy([]);
  47.         $aboutArea         $aboutAreaRepo->findOneByIsHomeArea(true);
  48.         $hobbiesArea       $hobbyAreaRepo->findOneBy([]);
  49.         $hobbies           $hobbySingleRepo->findAll();
  50.         $galleryArea       $galleryAreaRepo->findOneBy([]);
  51.         $galleries         $galleryCategoryRepo->findAll();
  52.         $serviceArea       $serviceAreaRepo->findOneBy([]);
  53.         $serviceCategories $serviceCatRepo->findAll();
  54.         $testimonialArea   $testimonialAreaRepo->findOneBy([]);
  55.         $testimonials      $testimonialRepo->findBy([], ['createdAt' => 'ASC']);
  56.         #   Check availability 
  57.         $constraint $this->constraint;
  58.         $endDate    $this->getEndDate();
  59.         #   Création du formulaire de verification de disponibilité 
  60.         $bookingEntity = new Booking();
  61.         $checkForm     $this->createForm(CheckAvailabilityType::class, $bookingEntity);
  62.         #   Fomulaire d'avis
  63.         $testimonialEntity = new Testimonial();
  64.         $testimonialForm   $this->createForm(TestimonialType::class, $testimonialEntity);
  65.         $testimonialForm->handleRequest($request);
  66.         if ($testimonialForm->isSubmitted() && $testimonialForm->isValid()) {
  67.             
  68.             define('SITE_KEY','6Lf6ntcdAAAAAFIFOj0w_4Q3_q8fs-zXu7senO2n');
  69.             define('SECRETE_KEY','6Lf6ntcdAAAAAImt18bgJi8ajipSKwPYfIq3RQd3');
  70.             if ( $recaptcha->check($_POST['testimonial-recaptcha_response'], SECRETE_KEY) ){
  71.                 $data    $testimonialForm->getData();
  72.                 $statics $this->statics['data'];
  73.                 
  74.                 $testimonialEntity->setCreatedAt(new DateTimeImmutable())
  75.                                   ->setDisplay(false);
  76.                 #   Envoi d'email MailJet 
  77.                 #   client
  78.                 $mailjet = new Mailjet();
  79.                 $mail_content $this->renderView('components/mail/_testimonial_recap.html.twig'compact('data''statics'));
  80.                 $mailjet->send("caurettemarc@gmail.com""Colombine"$data->getEmail(), $data->getFirstName()." ".$data->getLastName(), 'Colombine | Merci pour votre avis !'$mail_contentfalsefalse3367969);
  81.                 #   Proprio
  82.                 $mailjet = new Mailjet();
  83.                 $mail_content $this->renderView('components/mail/_testimonial.html.twig'compact('data''statics'));
  84.                 $mailjet->send("caurettemarc@gmail.com"$data->getFirstName()." ".$data->getLastName(), "maximeavril.dev@gmail.com"$data->getFirstName()." ".$data->getLastName(), 'Colombine | Avis'$mail_content,falsefalse3367969);
  85.                 $this->manager->persist($testimonialEntity);
  86.                 $this->manager->flush();
  87.                 return $this->json(true);
  88.             }else{
  89.                 return $this->json(false);
  90.             }
  91.         }      
  92.         $response = new Response($this->twig->render('home/index.html.twig', [
  93.             'statics' => $this->statics['data'],
  94.             'slides' => $slides,
  95.             'introArea' => $introArea,
  96.             'videoArea' => $videoArea,
  97.             'aboutArea' => $aboutArea,
  98.             'hobbiesArea' => $hobbiesArea,
  99.             'hobbies' => $hobbies,
  100.             'galleryArea' => $galleryArea,
  101.             'galleries' => $galleries,
  102.             'serviceArea' => $serviceArea,
  103.             'serviceCategories' => $serviceCategories,
  104.             'testimonialArea' => $testimonialArea,
  105.             'testimonials' => $testimonials,
  106.             'checkForm' => $checkForm->createView(),
  107.             'testimonialForm' => $testimonialForm->createView(),
  108.             'constraint' => $constraint,
  109.             'endDate' => $endDate,
  110.         ]));
  111.         $response->setSharedMaxAge(3600);
  112.         return $response;
  113.     }
  114.      /** 
  115.      * Permet de récupérer la date la plus éloignée parmis les periodes des saisons en BDD
  116.      * Afin de bloquer les reservations en ligne après cette date
  117.      * 
  118.      * @Route("/booking/get-end-date", name="booking_end_date")
  119.      */
  120.     public function getEndDate(){
  121.         $saisons $this->constraint->getSaisons();
  122.         $endDates = [];
  123.         foreach ($saisons as $key => $saison) {
  124.             foreach ($saison->getPeriods() as $key => $period) {
  125.                 $endDates[] = date('U'strtotime($period->getEndDate()->format('Y-m-d')));
  126.             }
  127.         }
  128.         sort($endDatesSORT_NUMERIC);
  129.         $endDate date('d/m/Y'array_slice($endDates, -11)[0]); 
  130.         return $endDate;
  131.     }
  132. }