src/Controller/HomeController.php line 39

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.             define('SITE_KEY''6LecwkQsAAAAAJ2fiCGD_CZeXV-v5UlIpBG57OmE');
  68.             define('SECRETE_KEY''6Lf6ntcdAAAAAImt18bgJi8ajipSKwPYfIq3RQd3');
  69.             if ($recaptcha->check($_POST['testimonial-recaptcha_response'], SECRETE_KEY)) {
  70.                 $data $testimonialForm->getData();
  71.                 $statics $this->statics['data'];
  72.                 $testimonialEntity->setCreatedAt(new DateTimeImmutable())
  73.                     ->setDisplay(false);
  74.                 #   Envoi d'email MailJet 
  75.                 #   client
  76.                 $mailjet = new Mailjet();
  77.                 $mail_content $this->renderView('components/mail/_testimonial_recap.html.twig'compact('data''statics'));
  78.                 $mailjet->send("caurettemarc@gmail.com""Colombine"$data->getEmail(), $data->getFirstName() . " " $data->getLastName(), 'Colombine | Merci pour votre avis !'$mail_contentfalsefalse7650701);
  79.                 #   Proprio
  80.                 $mailjet = new Mailjet();
  81.                 $mail_content $this->renderView('components/mail/_testimonial.html.twig'compact('data''statics'));
  82.                 $mailjet->send("caurettemarc@gmail.com"$data->getFirstName() . " " $data->getLastName(), "maximeavril.dev@gmail.com"$data->getFirstName() . " " $data->getLastName(), 'Colombine | Avis'$mail_contentfalsefalse7650701);
  83.                 $this->manager->persist($testimonialEntity);
  84.                 $this->manager->flush();
  85.                 return $this->json(true);
  86.             } else {
  87.                 return $this->json(false);
  88.             }
  89.         }
  90.         $response = new Response($this->twig->render('home/index.html.twig', [
  91.             'statics' => $this->statics['data'],
  92.             'slides' => $slides,
  93.             'introArea' => $introArea,
  94.             'videoArea' => $videoArea,
  95.             'aboutArea' => $aboutArea,
  96.             'hobbiesArea' => $hobbiesArea,
  97.             'hobbies' => $hobbies,
  98.             'galleryArea' => $galleryArea,
  99.             'galleries' => $galleries,
  100.             'serviceArea' => $serviceArea,
  101.             'serviceCategories' => $serviceCategories,
  102.             'testimonialArea' => $testimonialArea,
  103.             'testimonials' => $testimonials,
  104.             'checkForm' => $checkForm->createView(),
  105.             'testimonialForm' => $testimonialForm->createView(),
  106.             'constraint' => $constraint,
  107.             'endDate' => $endDate,
  108.         ]));
  109.         $response->setSharedMaxAge(3600);
  110.         return $response;
  111.     }
  112.     /** 
  113.      * Permet de récupérer la date la plus éloignée parmis les periodes des saisons en BDD
  114.      * Afin de bloquer les reservations en ligne après cette date
  115.      * 
  116.      * @Route("/booking/get-end-date", name="booking_end_date")
  117.      */
  118.     public function getEndDate()
  119.     {
  120.         $saisons $this->constraint->getSaisons();
  121.         $endDates = [];
  122.         foreach ($saisons as $key => $saison) {
  123.             foreach ($saison->getPeriods() as $key => $period) {
  124.                 $endDates[] = date('U'strtotime($period->getEndDate()->format('Y-m-d')));
  125.             }
  126.         }
  127.         sort($endDatesSORT_NUMERIC);
  128.         $endDate date('d/m/Y'array_slice($endDates, -11)[0]);
  129.         return $endDate;
  130.     }
  131. }