src/Controller/RechercheController.php line 146

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.             'id' => $id_lieu,
  67.             'aff_date' => true,
  68.             'datearrivee' => $datearrivee,
  69.             'nbadultes' => $nbadultes,
  70.             'nbenfants' => $nbenfants,
  71.             'nbpax' => $nbpax,
  72.             'duree' => $duree
  73.         ];
  74.         return $this->redirect($this->generateUrl('ac_platform_destination'$vars));
  75.     }
  76.     
  77.     /**
  78.      * @Route("/destinations", name="ac_platform_destinations")
  79.      */
  80.     public function destinations(Request $request$type=null$id=null )
  81.     {
  82.         $params = [];
  83.         
  84.         $lang $this->em->getRepository(Language::class)->findOneByCode($request->getLocale());
  85.         
  86.         $residences $this->em->getRepository(Residence::class)->findEnabled($lang);
  87.         $destinations  $this->em->getRepository(Destination::class)->findAvailable($lang);
  88.         
  89.         $destinationsArbo $this->destinationService->getDestinations($destinations$residences );
  90.         
  91.         $params = [
  92.             "destinations" => $destinationsArbo,
  93.             "id" => $id,
  94.             "type" => $type
  95.         ];
  96.         $response $this->render('/front/Moteur/destinations_v2.html.twig'$params);
  97.         $response->setMaxAge(3600);
  98.         return $response;
  99.     }
  100.     
  101.     private function prestationsLieux($destination$nbpax$duree$datearrivee,$locale$levelMax=3$level 1) {
  102.         $prestationsLieu $this->iresaManager->getPrestationsLieu($destination$nbpax$duree,$datearrivee);
  103.         if($prestationsLieu) {
  104.             $destination $prestationsLieu['idLieu'];
  105.            
  106.             if($prestationsLieu['prestations']) {
  107.                  return $prestationsLieu['prestations'];
  108.             }  elseif($levelMax $level) {
  109.                 $level++;
  110.                 $this->prestationsLieux($destination$nbpax$duree,$datearrivee,$locale$level$levelMax);
  111.             } else {
  112.                 return false;
  113.             }
  114.         } 
  115.         return false;
  116.     }
  117.     
  118.     public function duree($duree=0)
  119.     {
  120.         $listDurees = [];
  121.         for($k=1$k<=31$k++) {
  122.             $listDurees[] = $k;
  123.         }
  124.         return $this->render('/front/Recherche/duree.html.twig', ['listDurees' => $listDurees'duree' => $duree]);
  125.     }
  126.     public function adultes($nbadultes 1)
  127.     {
  128.         return $this->render('/front/Recherche/adultes.html.twig', ['nbadultes' => $nbadultes]);
  129.     }
  130.     
  131.     public function enfants($nbenfants 0)
  132.     {
  133.         return $this->render('/front/Recherche/enfants.html.twig', ['nbenfants' => $nbenfants]);
  134.     }
  135.     
  136. }