src/Controller/HotelController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\Otpusk\GeoSeoUrlRepository;
  4. use App\Services\PageGenerator;
  5. use App\Services\HotelService;
  6. use Doctrine\ORM\EntityManager;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class HotelController extends AbstractController
  15. {
  16.     private $em;
  17.     private $hotelService;
  18.     public function __construct(EntityManager $entityManagerHotelService $hotelService)
  19.     {
  20.         $this->em $entityManager;
  21.         $this->hotelService $hotelService;
  22.     }
  23.     /**
  24.      * @Route(
  25.      *     "/sitemaps/hotels/{page}",
  26.      *     name="app_hotel_sitemaps",
  27.      *     methods={"GET"},
  28.      *     priority="99",
  29.      *     requirements={"page": "(|\d+)"},
  30.      *     defaults={"page": "1"}
  31.      *     )
  32.      */
  33.     public function sitemapsHotels(Request $request)
  34.     {
  35.         return $this->render('hotel/sitemaps.html.twig', [
  36.             'data' => $this->hotelService->getSitemapsHotelsData(($request->get('page'1) != "") ? $request->get('page'1) : 1),
  37.             'seo' => $this->hotelService->getSeoSitemaps($request->getLocale()),
  38.         ]);
  39.     }
  40.     /**
  41.      * @Route(
  42.      *     "/hotel/{hotelId}-{hotelSlug}",
  43.      *     name="app_hotel",
  44.      *     methods={"GET"},
  45.      *     priority="100"
  46.      *     )
  47.      */
  48.     public function hotel(Request $request$hotelId$hotelSlug)
  49.     {
  50.         $market $request->getSession()->get('market');
  51.         $locale $request->getLocale();
  52.         $offerId $request->get('offerId');
  53.         $robotsRequest = (is_null($request->get('_escaped_fragment_'))) ? false true;
  54.         $noIndex = isset($offerId) && $offerId || $robotsRequest;
  55.         try {
  56.             $hotel $this->hotelService->getHotelInfo($market$hotelId$locale);
  57.         } catch (\Exception $exception) {
  58.             throw new NotFoundHttpException('This page not found.');
  59.         }
  60.         $seo $this->hotelService->getSeo($hotel$locale$noIndex);
  61. //        $exchangeRates = $this->hotelService->getExchangeRates();
  62. //        $cityNames = $this->hotelService->getCityNames($market);
  63.         $mainServices $this->hotelService->getMainServices($market$hotel$locale);
  64.         $similars $this->hotelService->getSimilars($market$hotel$locale);
  65.         $nearests $this->hotelService->getNearests($market$hotel$locale);
  66.         $recommended $this->hotelService->getRecommended($market$hotel$locale);
  67.         $recommended array_slice($recommended05);
  68.         $reviewsData $this->hotelService->getReviews($hotel$locale);
  69.         $reasons $this->hotelService->getReasons($hotel$locale);
  70.         $chartsDesktop $this->hotelService->getCharts($market$hotelId);
  71.         $chartsMobile $this->getChartsMobile($chartsDesktop);
  72.         $dateNextDesktop = new \DateTime();
  73.         $dateNextDesktop $dateNextDesktop->modify('+15 days')->format('Y-m-d');
  74.         $dateNextMobile = new \DateTime();
  75.         $dateNextMobile $dateNextMobile->modify('+9 days')->format('Y-m-d');
  76.         $response = new Response($this->renderView('hotel/index.html.twig', [
  77.             'hotel' => $hotel,
  78.             'hotelId' => $hotelId,
  79.             'seo' => $seo,
  80. //            'exchangeRates' => $exchangeRates,
  81. //            'countryCurrency' => $market['currency']['code'],
  82. //            'currencyAliases' => HotelService::$currencyAliases,
  83. //            'cityNames' => $cityNames,
  84.             'mainServices' => $mainServices,
  85.             'similars' => $similars,
  86.             'nearests' => $nearests,
  87.             'recommended' => $recommended,
  88.             'reviewsData' => $reviewsData,
  89.             'reasons' => $reasons,
  90.             'chartsDesktop' => $chartsDesktop,
  91.             'chartsMobile' => $chartsMobile,
  92.             'dateNextDesktop' => $dateNextDesktop,
  93.             'dateNextMobile' => $dateNextMobile,
  94.         ]), 200);
  95.         if ($noIndex$response->headers->set('X-Robots-Tag''noindex');
  96.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  97.         return $response;
  98.     }
  99.     /**
  100.      * @Route("/getCharts", name="app_get_charts", methods={"POST"})
  101.      */
  102.     public function getHotels(Request $request)
  103.     {
  104.         $market $request->getSession()->get('market');
  105.         $hotelId $request->get('hotelId');
  106.         $countryId $request->get('countryId');
  107.         $date $request->get('date');
  108.         $count $request->get('count');
  109.         if (empty($count) || $count<0$count=1;
  110.         $dateNext = new \DateTime($date);
  111.         $dateNext $dateNext->modify('+' $count ' days')->format('Y-m-d');
  112.         $charts $this->hotelService->getCharts($market$hotelId$date$count);
  113.         $charts $this->renderView('hotel/parts/charts.html.twig', [
  114.             'charts'    => $charts,
  115.             'hotelId'   => $hotelId,
  116.             'countryId' => $countryId,
  117.             'market'    => $market,
  118.         ]);
  119.         return new JsonResponse([
  120.             'charts' => $charts,
  121.             'dateNext' => $dateNext,
  122.         ]);
  123.     }
  124.     public function getChartsMobile($chartsDesktop)
  125.     {
  126.         $countMobile 9;
  127.         $chartsMobile = [];
  128.         $i 1;
  129.         foreach ($chartsDesktop as $k => $v) {
  130.             if ($i == && count($v) >= $countMobile) {
  131.                 $chartsMobile[$k] = array_slice($v0$countMobile);
  132.                 break;
  133.             } else {
  134.                 if ($i == 1) {
  135.                     $chartsMobile[$k] = $v;
  136.                     $countFirst count($v);
  137.                 } elseif ($i == 2) {
  138.                     $chartsMobile[$k] = array_slice($v0$countMobile $countFirst);
  139.                 }
  140.             }
  141.             $i++;
  142.         }
  143.         return $chartsMobile;
  144.     }
  145. }