src/Controller/RechercheController.php line 142

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use App\Utils\IresaManager;
  12. use App\Utils\Destinations;
  13. use App\Entity\Destination;
  14. use App\Entity\Language;
  15. use App\Entity\Residence;
  16. /**
  17.  * @Route("/{_locale}", requirements={"_locale": "en|fr"})
  18.  */
  19. class RechercheController extends AbstractController
  20. {
  21.     /**
  22.      * @var EntityManagerInterface
  23.      */
  24.     private $em;
  25.     
  26.      /**
  27.      * @var SessionInterface
  28.      */
  29.     private $session;
  30.     private $flashbag;
  31.     private $iresaManager;
  32.     private $destinationService;
  33.     
  34.     function __construct(EntityManagerInterface $em,  SessionInterface $sessionIresaManager $iresaManagerDestinations $destinationService) {
  35.         $this->em $em;
  36.         $this->session $session;
  37.         $this->flashbag $this->session->getFlashBag();
  38.         $this->iresaManager $iresaManager;
  39.         $this->destinationService $destinationService;
  40.     }
  41.     
  42.     /**
  43.      * @Route("/recherche", name="ac_platform_recherche")
  44.      */
  45.     public function index(Request $request)
  46.     {
  47.         
  48.         $id_lieu $request->query->get("destination") == "" $request->query->get("destination");
  49.         $datearrivee $request->query->get("datearrivee");
  50.         $nbadultes $request->query->get("nbadultes");
  51.         $nbenfants $request->query->get("nbenfants");
  52.         $duree $request->query->get("duree");
  53.         $nbpax $nbadultes $nbenfants;
  54.        
  55.         
  56.         $destination =  $this->em->getRepository(Destination::class)->findOneByIdIresa($id_lieu);
  57.         
  58.         if ($destination) {
  59.             $slug $destination->getSlug();
  60.         } else {
  61.             $slug "lieu";
  62.         }
  63.         
  64.         $vars = [
  65.             'slug' => $slug
  66.             'aff_date' => true,
  67.             'datearrivee' => $datearrivee,
  68.             'nbadultes' => $nbadultes,
  69.             'nbenfants' => $nbenfants,
  70.             'nbpax' => $nbpax,
  71.             'duree' => $duree
  72.         ];
  73.         return $this->redirect($this->generateUrl('ac_platform_destination_slug'$vars));
  74.     }
  75.     
  76.     /**
  77.      * @Route("/destinations", name="ac_platform_destinations")
  78.      */
  79.     public function destinations(Request $request$type=null$id=null )
  80.     {
  81.         $params = [];
  82.         
  83.         $lang $this->em->getRepository(Language::class)->findOneByCode($request->getLocale());
  84.         
  85.         $destinations  $this->em->getRepository(Destination::class)->findAvailable($lang);
  86.         $residences $this->em->getRepository(Residence::class)->findEnabled($lang);
  87.         $destinationsArbo $this->destinationService->getDestinations($destinations$residencestrue);
  88.         
  89.         $params = [
  90.             "destinations" => $destinationsArbo,
  91.             "id" => $id,
  92.             "type" => $type
  93.         ];
  94.         $response $this->render('/front/Moteur/destinations_v2.html.twig'$params);
  95.         $response->setMaxAge(3600);
  96.         return $response;
  97.     }
  98.     private function prestationsLieux($destination$nbpax$duree$datearrivee,$locale$levelMax=3$level 1) {
  99.         $prestationsLieu $this->iresaManager->getPrestationsLieu($destination$nbpax$duree,$datearrivee);
  100.         if($prestationsLieu) {
  101.             $destination $prestationsLieu['idLieu'];
  102.            
  103.             if($prestationsLieu['prestations']) {
  104.                  return $prestationsLieu['prestations'];
  105.             }  elseif($levelMax $level) {
  106.                 $level++;
  107.                 $this->prestationsLieux($destination$nbpax$duree,$datearrivee,$locale$level$levelMax);
  108.             } else {
  109.                 return false;
  110.             }
  111.         } 
  112.         return false;
  113.     }
  114.     
  115.     public function duree($duree=0)
  116.     {
  117.         $listDurees = [];
  118.         for($k=1$k<=31$k++) {
  119.             $listDurees[] = $k;
  120.         }
  121.         return $this->render('/front/Recherche/duree.html.twig', ['listDurees' => $listDurees'duree' => $duree]);
  122.     }
  123.     public function adultes($nbadultes 1)
  124.     {
  125.         return $this->render('/front/Recherche/adultes.html.twig', ['nbadultes' => $nbadultes]);
  126.     }
  127.     
  128.     public function enfants($nbenfants 0)
  129.     {
  130.         return $this->render('/front/Recherche/enfants.html.twig', ['nbenfants' => $nbenfants]);
  131.     }
  132.     
  133. }