Beispiel #1
0
 /**
  * @Route("/pdj/{slug}/{region}/{city}/{rateSlug}", name="hotel_pdj", defaults={"rateSlug": null}, options={"label"="Fiche Hôtel - PDJ", "parameters"={
  *      {"name"="slug", "field"="slug", "type"="SehBundle:Hotel", "repoMethod"="findActivePdj", "children"={"region", "city"}}
  * }})
  * @Route("/ih/{slug}/{region}/{city}/{rateSlug}", name="hotel_ih", defaults={"rateSlug": null}, options={"label"="Fiche Hôtel - IH", "parameters"={
  *      {"name"="slug", "field"="slug", "type"="SehBundle:Hotel", "repoMethod"="findActiveIh", "children"={"region", "city"}}
  * }})
  * @Route("/qys/{slug}/{country}/{region}/{city}/{rateSlug}", name="hotel_qys", defaults={"rateSlug": null}, options={"label"="Fiche Hôtel - QYS", "parameters"={
  *      {"name"="slug", "field"="slug", "type"="SehBundle:Hotel", "repoMethod"="findActiveQys", "children"={"country","region", "city"}}
  * }})
  * @Route("/rds/{slug}/{country}/{region}/{rateSlug}", name="hotel_rds", defaults={"rateSlug": null}, options={"label"="Fiche Hôtel - RDS", "parameters"={
  *      {"name"="slug",     "field"="slug", "type"="SehBundle:Hotel", "repoMethod"="findActiveRds", "children"={"country", "region"}}
  * }})
  */
 public function showAction($slug, $rateSlug)
 {
     $logger = $this->get('monolog.logger.seh');
     $hotelRepo = $this->getRepository('SehBundle:Hotel');
     $hotelQuery = $hotelRepo->getValidQueryBuilder();
     $hotelQuery->andWhere('h.slug = :slug')->setParameter(':slug', $slug);
     $query = $hotelQuery->getQuery();
     $time = microtime(true);
     /** @var Hotel $hotel */
     $hotel = $query->getOneOrNullResult();
     $logger->info(sprintf('Hotel Show : SQL query in %s', microtime(true) - $time));
     if (!$hotel) {
         throw new NotFoundHttpException();
     }
     $locale = $this->container->get('bigfoot_context')->get('language');
     $selectedRate = null;
     if ($rateSlug = str_replace($this->get('translator')->trans('seo.url.hotel.special_rate.prefix') . '-', '', $rateSlug)) {
         $selectedRate = $this->getRepository('SehBundle:Reservit\\Rate')->findOneBySlugI18n($rateSlug, $locale);
     }
     $requestData = $this->getRequest()->attributes;
     // Validate Country / Region / City
     if ($requestData->get('city') && $requestData->get('city') != $hotel->getCity()->getSlug()) {
         throw new NotFoundHttpException();
     } else {
         if ($requestData->get('region') && $requestData->get('region') != $hotel->getRegion()->getSlug()) {
             throw new NotFoundHttpException();
         } else {
             if ($requestData->get('country') && $requestData->get('country') != $hotel->getRegion()->getCountry()->getSlug()) {
                 throw new NotFoundHttpException();
             }
         }
     }
     $this->saveIntoViewedHotel($hotel->getId());
     $hotelServices = $hotel->getSortServicesByType();
     $hotelLinkedCities = $hotel->getLinkedCities();
     $hotelHighlights = $hotel->getHighlights();
     $hotelPois = $hotel->getHotelPois();
     if ($hotelLinkedCities) {
         foreach ($hotelLinkedCities as &$linkedCity) {
             if ($linkedCity->getLatitude() && $linkedCity->getLongitude() && $hotel->getLatitude() && $hotel->getLongitude()) {
                 $distance = GeolocManager::calculateDistance($linkedCity->getLatitude(), $linkedCity->getLongitude(), $hotel->getLatitude(), $hotel->getLongitude());
                 $linkedCity->setDistance($distance);
             }
         }
     }
     $tempHotelPois = array();
     $tabTempHotelPois = array();
     foreach ($hotelPois as $hotelPoi) {
         if (!in_array($hotelPoi->getPoi()->getSlug(), $tempHotelPois)) {
             $tempHotelPois[$hotelPoi->getPoi()->getPoiCategory()->getId()][] = $hotelPoi->getPoi()->getSlug();
             $tabTempHotelPois[$hotelPoi->getPoi()->getPoiCategory()->getId()][] = $hotelPoi;
         }
     }
     $hotelPois = $tabTempHotelPois;
     $currentBrandContext = $this->container->get('bigfoot_context')->get('brand', true);
     $brandHotelContext = $this->container->get('bigfoot_context')->get('brand', true, strtolower($hotel->getBrand()->getArtsysID()));
     $crossPage = $currentBrandContext['key'] == $brandHotelContext['key'] ? false : true;
     $activeComments = $this->container->get('doctrine')->getRepository('QualitelisBundle:QualitelisCommentaire')->findAllByActiveSortByCurrentLang($hotel, $this->getRequest()->getLocale());
     $currentLang = $this->getRequest()->getLocale();
     $em = $this->getDoctrine()->getManager();
     $region = $hotel->getRegion();
     $country = $hotel->getRegion()->getCountry();
     $region->setTranslatableLocale($currentLang);
     $em->refresh($region);
     $regionSlug = $region->getSlug();
     $country->setTranslatableLocale($currentLang);
     $em->refresh($country);
     $countrySlug = $country->getSlug();
     $ratesHotelHl = array();
     $ratesHotel = array();
     $ratesChain = array();
     $ratesUnlimited = array();
     $ratesLimited = array();
     /** @var Rate $rate */
     foreach ($hotel->getValidRates(false) as $rate) {
         if ($rate->getChainRate()) {
             $ratesChain[] = $rate;
         } else {
             $ratesHotelHl[] = $rate;
             $ratesHotel[] = $rate;
         }
         if ($rate->getBookingPeriodType() == Rate::BOOKING_PERIOD_TYPE_LIMITED && $rate->getBookingPeriodStart()) {
             $ratesLimited[$rate->getBookingPeriodStart()->format('Y-m-d')] = $rate;
         } elseif ($rate->getBookingPeriodType() == Rate::BOOKING_PERIOD_TYPE_UNLIMITED) {
             $ratesUnlimited[] = $rate;
         }
     }
     shuffle($ratesChain);
     shuffle($ratesHotel);
     shuffle($ratesHotelHl);
     shuffle($ratesUnlimited);
     ksort($ratesLimited);
     $ratesHotel = $ratesHotelHl + $ratesHotel;
     $restaurant = '';
     /** @var Hotel\Restaurant $resto */
     foreach ($hotel->getRestaurants() as $resto) {
         if ($resto->getName() != '') {
             $restaurant = $resto;
             break;
         }
     }
     $referer = $this->getRequest()->headers->get('referer');
     //reset map query in referer
     $referer = str_replace('?map=true', '', $referer);
     $parse = parse_url($referer);
     if ($this->getRequest()->query->get('map') == true) {
         $referer .= '?map=true';
     } elseif ($this->getRequest()->query->get('referer') != '') {
         $bookingStep = $this->getRequest()->query->get('referer');
         $bookingId = $this->getRequest()->query->get('bookingId');
         if (in_array($bookingStep, array('booking_step_one', 'booking_step_two', 'booking_step_three', 'booking_step_four', 'booking_step_five'))) {
             $referer = $this->generateUrl($bookingStep) . '?bookingId=' . $bookingId;
         } else {
             $referer = $this->get('router')->generate('homepage');
         }
     } elseif (!isset($parse['host']) || $parse['host'] != $this->getRequest()->getHost()) {
         $referer = $this->get('router')->generate('homepage');
     }
     return $this->renderWithCache('MobileBundle:hotel:base.html.twig', array('crossPage' => $crossPage, 'activeComments' => $activeComments, 'hotel' => $hotel, 'hotelBrand' => strtolower($hotel->getBrand()->getArtsysID()), 'hotelServices' => $hotelServices, 'hotelLinkedCities' => $hotelLinkedCities, 'hotelHighlights' => $hotelHighlights, 'hotelPois' => $hotelPois, 'regionSlug' => $regionSlug, 'countrySlug' => $countrySlug, 'ratesChain' => array_slice($ratesChain, 0, 1), 'ratesHotel' => array_slice($ratesHotel, 0, 3), 'restaurant' => $restaurant, 'selectedRate' => $selectedRate, 'ratesLimited' => $ratesLimited, 'ratesUnlimited' => $ratesUnlimited, 'referer' => $referer), $this->container->getParameter('cache.hotel'));
 }
Beispiel #2
0
 /**
  * Get linkedCity
  *
  * @return City
  */
 public function getLinkedCityLowestDistance()
 {
     /** @var array $toReturn */
     $toReturn = array();
     /** @var City $linkedCity */
     foreach ($this->linkedCities as $linkedCity) {
         if ($linkedCity->getId() != $this->city->getId()) {
             $distance = 0;
             if ($linkedCity->getLatitude() && $linkedCity->getLongitude() && $this->latitude && $this->longitude) {
                 $distance = GeolocManager::calculateDistance($linkedCity->getLatitude(), $linkedCity->getLongitude(), $this->latitude, $this->longitude);
             }
             if ($distance > 0) {
                 $linkedCity->setDistance($distance);
                 $toReturn[] = $linkedCity;
             }
         }
     }
     usort($toReturn, function ($a, $b) {
         if ($a->getDistance() > $b->getDistance()) {
             return 1;
         } elseif ($a->getDistance() < $b->getDistance()) {
             return -1;
         }
         return 0;
     });
     return array_shift($toReturn);
 }