<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use App\Utils\IresaManager;
use App\Utils\Destinations;
use App\Entity\Destination;
use App\Entity\Language;
use App\Entity\Residence;
/**
* @Route("/{_locale}", requirements={"_locale": "en|fr"})
*/
class RechercheController extends AbstractController
{
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var SessionInterface
*/
private $session;
private $flashbag;
private $iresaManager;
private $destinationService;
function __construct(EntityManagerInterface $em, SessionInterface $session, IresaManager $iresaManager, Destinations $destinationService) {
$this->em = $em;
$this->session = $session;
$this->flashbag = $this->session->getFlashBag();
$this->iresaManager = $iresaManager;
$this->destinationService = $destinationService;
}
/**
* @Route("/recherche", name="ac_platform_recherche")
*/
public function index(Request $request)
{
$id_lieu = $request->query->get("destination") == "" ? 0 : $request->query->get("destination");
$datearrivee = $request->query->get("datearrivee");
$nbadultes = $request->query->get("nbadultes");
$nbenfants = $request->query->get("nbenfants");
$duree = $request->query->get("duree");
$nbpax = $nbadultes + $nbenfants;
$destination = $this->em->getRepository(Destination::class)->findOneByIdIresa($id_lieu);
if ($destination) {
$slug = $destination->getSlug();
} else {
$slug = "lieu";
}
$vars = [
'slug' => $slug,
'id' => $id_lieu,
'aff_date' => true,
'datearrivee' => $datearrivee,
'nbadultes' => $nbadultes,
'nbenfants' => $nbenfants,
'nbpax' => $nbpax,
'duree' => $duree
];
return $this->redirect($this->generateUrl('ac_platform_destination', $vars));
}
/**
* @Route("/destinations", name="ac_platform_destinations")
*/
public function destinations(Request $request, $type=null, $id=null )
{
$params = [];
$lang = $this->em->getRepository(Language::class)->findOneByCode($request->getLocale());
$residences = $this->em->getRepository(Residence::class)->findEnabled($lang);
$destinations = $this->em->getRepository(Destination::class)->findAvailable($lang);
$destinationsArbo = $this->destinationService->getDestinations($destinations, $residences );
$params = [
"destinations" => $destinationsArbo,
"id" => $id,
"type" => $type
];
$response = $this->render('/front/Moteur/destinations_v2.html.twig', $params);
$response->setMaxAge(3600);
return $response;
}
private function prestationsLieux($destination, $nbpax, $duree, $datearrivee,$locale, $levelMax=3, $level = 1) {
$prestationsLieu = $this->iresaManager->getPrestationsLieu($destination, $nbpax, $duree,$datearrivee);
if($prestationsLieu) {
$destination = $prestationsLieu['idLieu'];
if($prestationsLieu['prestations']) {
return $prestationsLieu['prestations'];
} elseif($levelMax > $level) {
$level++;
$this->prestationsLieux($destination, $nbpax, $duree,$datearrivee,$locale, $level, $levelMax);
} else {
return false;
}
}
return false;
}
public function duree($duree=0)
{
$listDurees = [];
for($k=1; $k<=31; $k++) {
$listDurees[] = $k;
}
return $this->render('/front/Recherche/duree.html.twig', ['listDurees' => $listDurees, 'duree' => $duree]);
}
public function adultes($nbadultes = 1)
{
return $this->render('/front/Recherche/adultes.html.twig', ['nbadultes' => $nbadultes]);
}
public function enfants($nbenfants = 0)
{
return $this->render('/front/Recherche/enfants.html.twig', ['nbenfants' => $nbenfants]);
}
}