src/Controller/DetailController.php line 138

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Interfaces\CountriesInterface;
  4. use App\Interfaces\IHotels;
  5. use App\Interfaces\RegionInterface;
  6. use App\Interfaces\StaticDataInterface;
  7. use App\Vendor\Helper;
  8. use App\Vendor\Symfony\MAbstractController;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. #[Route('/detail/{_locale}'name'app_detail_')]
  16. class DetailController extends MAbstractController
  17. {
  18.     #[Route('/{id}'name'hotel_detail'methods: ['GET','POST'])]
  19.     public function hotelDetail(string $idRequest $requestIHotels $hotelServiceRegionInterface $regionServiceTranslatorInterface $translatorStaticDataInterface $staticDataServiceCountriesInterface $countries): Response
  20.     {
  21.         Helper::clearSession($request);
  22.         $params $this->getParams();
  23.         if(isset($params['newParams'])){
  24.             $params $params["newParams"];
  25.             $request->query->set('search'$params[0]["search"]);
  26.             $request->query->remove("newParams");
  27.         }
  28.         unset($params["path"]);
  29.         $regionData = [];
  30.         $country $countries->getCurrentCountry();
  31.         if(isset($params[0]) && isset($params[0]["search"])){
  32.             $params["search"] = $params[0]["search"];
  33.             unset($params[0]);
  34.             if(empty($params["search"]["guests"][0]["children"])){
  35.                 $params["search"]["guests"][0]["children"][0] = "NaN";
  36.             }
  37.             if(count($params["search"]["guests"]) > 1){
  38.                 foreach ($params["search"]["guests"] as &$guest){
  39.                     if(!isset($guest["children"])){
  40.                         $guest["children"] = ["NaN"];
  41.                     }
  42.                 }
  43.             }
  44.             if(empty($params["search"]["checkin"]) || empty($params["search"]["checkout"])){
  45.                 $currentDay date("Y-m-d");
  46.                 $params["search"]["checkin"] = date("Y-m-d"strtotime($currentDay ' +1 day'));
  47.                 $params["search"]["checkout"] =  date("Y-m-d"strtotime($currentDay ' +2 day'));
  48.             }
  49.             if(is_numeric($params["search"]["location"])){
  50.                 $region $regionService->getRegionById((int)$params["search"]["location"]);
  51.                 if(!empty($region)){
  52.                     $regionData["id"] = $region[0]["id"];
  53.                     $regionData["name"] = $region[0]["name"][$request->getLocale()];
  54.                 }
  55.             } else {
  56.                 $region $hotelService->getByHotelId($params["search"]["location"], $request->getLocale());
  57.                 if(!empty($region)){
  58.                     $regionData["id"] = $region[0]["id"];
  59.                     $regionData["name"] = $region[0]["name"];
  60.                 }
  61.             }
  62.             $checkIn =  empty($params["search"]["checkin"]) ? date("Y-m-d") : $params["search"]["checkin"];
  63.             $params["search"]["checkin"] =$checkIn;
  64.             $params["search"]["checkout"] = empty($params["search"]["checkout"]) ? date('Y-m-d'strtotime($checkIn ' +1 day'))  : $params["search"]["checkout"];
  65.             $hotelService->guestsRoomsDaysCount($params);
  66.             if(!empty($params["search"]["guests"])){
  67.                 foreach ($params["search"]["guests"] as &$guest){
  68.                     $children = ["NaN"];
  69.                     if(!empty($guest["children"]) && $guest["children"][0] != "NaN"){
  70.                         $children explode(','$guest["children"][0]);
  71.                         foreach ($children as &$child){
  72.                             $child intval($child);
  73.                         }
  74.                     }
  75.                     $guest["children"] = $children;
  76.                 }
  77.             }
  78.             if(!empty($params["search"]["residency"])){
  79.                 $country $countries->getCountryByCode($params["search"]["residency"], $request->getLocale());
  80.             }
  81.         }
  82.         $hotel $hotelService->hotelPage($id$request);
  83.         $metapolicyIncludedData = [];
  84.         $metapolicyNoIncludedData = [];
  85.         if(!empty($hotel)){
  86.             foreach ($hotel["metapolicy_struct"] as $key=>$mStruct){
  87.                 $tkey $key;
  88.                 foreach ($mStruct as $item){
  89.                     if(!empty($item["inclusion"])){
  90.                         if($item["inclusion"] == "included"){
  91.                             $metapolicyIncludedData[$tkey][] = $item;
  92.                         }else{
  93.                             if($key == "meal" || $key == "children_meal" ){
  94.                                 $item["meal_type_t"] = $staticDataService->getMeal($item["meal_type"], $request->getLocale());
  95.                             }
  96.                             $metapolicyNoIncludedData[$tkey][] = $item;
  97.                         }
  98.                     }
  99.                     if(!empty($item["availability"]) && $item["availability"] == "available"){
  100.                         $metapolicyNoIncludedData[$tkey][] = $item;
  101.                     }
  102.                     if(!isset($item["inclusion"]) && !isset($item["availability"]) ){
  103.                         if($key == "no_show"){
  104.                             continue;
  105.                         }
  106.                         $metapolicyNoIncludedData[$tkey][] = $item;
  107.                     }
  108.                 }
  109.                 if(!isset($item["inclusion"]) && !isset($item["availability"]) ){
  110.                     if($key == "no_show"){
  111.                         $metapolicyNoIncludedData["no_show"][] = $translator->trans('no_show', ['{time}' => $mStruct["time"]]);
  112.                     }
  113.                 }
  114.             }
  115.             $hotel["metapolicyIncludedData"] = $metapolicyIncludedData;
  116.             $hotel["metapolicyNoIncludedData"] = $metapolicyNoIncludedData;
  117.         }
  118.         if($request->getMethod() == "POST"){
  119.             return new JsonResponse($hotel);
  120.         }
  121.         $session $request->getSession();
  122.         if($session->has('hotel')){
  123.             $session->remove('hotel');
  124.         }
  125.         $session->set('hotel'serialize($hotel));
  126.         if(empty($this->getUser())){
  127.             $params["id"] = $id;
  128.             $session->set('back_url'$this->generateUrl($request->get("_route"), $params));
  129.         }
  130.         return $this->render('detail/hotel_detail.html.twig', [
  131.             'controller_name' => 'DetailController',
  132.             'hotel' => $hotel,
  133.             'params' => $params,
  134.             'region' => $regionData,
  135.             'country' => $country
  136.         ]);
  137.     }
  138.     #[Route('/room'name'room_detail')]
  139.     public function roomDetail(): Response
  140.     {
  141.         return $this->render('detail/room_detail.html.twig', [
  142.             'controller_name' => 'DetailController',
  143.         ]);
  144.     }
  145. }