Exemple #1
0
 static function sendRequestToHotelProvider($hotelSearchParams)
 {
     Yii::import('site.frontend.models.*');
     Yii::import('site.frontend.components.*');
     $hotelClient = new HotelBookClient();
     $startTime = microtime(true);
     $variants = $hotelClient->fullHotelSearch($hotelSearchParams);
     $endTime = microtime(true);
     $startTime = microtime(true);
     self::storeToCache($hotelSearchParams, $variants);
     $endTime = microtime(true);
     $startTime = microtime(true);
     Yii::app()->hotelsRating->injectRating($variants->hotels, $hotelSearchParams->city);
     $endTime = microtime(true);
     //}
     $results = array();
     if ($variants->responseStatus == ResponseStatus::ERROR_CODE_NO_ERRORS) {
         $startTime = microtime(true);
         $stack = new HotelStack($variants);
         $results = $stack->groupBy('hotelId', 117501)->mergeStepV2()->groupBy('rubPrice')->getJsonObject(1);
         $stack->saveHotelDb();
         $nStack = new HotelStack();
         $nStack->_hotels = $stack->getHotels(1);
         $resultsHotels = $stack->getJsonObject();
         foreach ($resultsHotels['hotels'] as $i => $info) {
             $hotelInfo = $hotelClient->hotelDetail($info['hotelId']);
             if ($hotelInfo) {
                 $hotelsDetails[$info['hotelId'] . 'd'] = self::prepare($hotelInfo);
             }
         }
         /*
                     $query = array();
                     foreach ($resultsHotels['hotels'] as $i => $info)
                     {
                         $query[$info['hotelId']] = $hotelClient->hotelDetail($info['hotelId'], true);
                     }
         
                     $hotelClient->processAsyncRequests();
                     $endTime = microtime(true);
         
                     Header('ExecutionTimeSortAndDetails:' . ($endTime - $startTime));
         
                     $hotelsDetails = array();
                     foreach ($query as $hotelId => $responseId)
                     {
                         if (isset($hotelClient->requests[$responseId]['result']))
                         {
                             $hotelsDetails[$hotelId . 'd'] = self::prepare($hotelClient->requests[$responseId]['result']);
                             //Yii::app()->cache->set('HotelDetails-' . $hotelId, $hotelsDetails[$hotelId . 'd']);
                         }
                     }/**/
         $results['hotelsDetails'] = $hotelsDetails;
         return $results;
     } elseif ($variants->responseStatus == ResponseStatus::ERROR_CODE_EMPTY) {
         $results['hotels'] = array();
         return $results;
     } else {
         return false;
     }
 }
 public function run()
 {
     Yii::import('site.common.modules.hotel.models.*');
     $hotelForm = new HotelForm();
     if (isset($_REQUEST['HotelForm'])) {
         $hotelForm->attributes = $_REQUEST['HotelForm'];
         $rooms = array();
         if (isset($_REQUEST['HotelRoomForm'])) {
             foreach ($_REQUEST['HotelRoomForm'] as $i => $info) {
                 $room = new HotelRoomForm();
                 $room->attributes = $info;
                 if ($room->validate()) {
                     $rooms[] = $room;
                 }
             }
         }
         $hotelForm->rooms = $rooms;
         if ($hotelForm->validate()) {
             $hotelSearchParams = new HotelSearchParams();
             $hotelSearchParams->checkIn = date('Y-m-d', strtotime($hotelForm->fromDate));
             $hotelSearchParams->city = City::getCityByPk($hotelForm->cityId);
             $hotelSearchParams->duration = $hotelForm->duration;
             foreach ($hotelForm->rooms as $room) {
                 if ($room->childCount == 1) {
                     $hotelSearchParams->addRoom($room->adultCount, $room->cots, $room->childAge);
                 } else {
                     $hotelSearchParams->addRoom($room->adultCount, $room->cots, false);
                 }
             }
             $HotelClient = new HotelBookClient();
             $pCacheId = md5(serialize($hotelSearchParams));
             Yii::app()->pCache->set('hotelSearchParams' . $pCacheId, $hotelSearchParams, appParams('hotel_search_cache_time'));
             $resultSearch = $HotelClient->fullHotelSearch($hotelSearchParams);
             Yii::app()->hotelsRating->injectRating($resultSearch->hotels, $hotelSearchParams->city);
             $cacheId = substr(md5(uniqid('', true)), 0, 10);
             Yii::app()->cache->set('hotelResult' . $cacheId, $resultSearch, appParams('hotel_search_cache_time'));
             Yii::app()->cache->set('hotelSearchParams' . $cacheId, $hotelSearchParams, appParams('hotel_search_cache_time'));
             Yii::app()->cache->set('hotelForm' . $cacheId, $hotelForm, appParams('hotel_search_cache_time'));
             if ($resultSearch['hotels']) {
                 $hotelStack = new HotelStack($resultSearch);
                 $results = $hotelStack->groupBy('hotelId')->groupBy('roomSizeId')->groupBy('rubPrice')->sortBy('rubPrice', 2)->getJsonObject();
                 echo json_encode(array('pCacheId' => $pCacheId, 'cacheId' => $cacheId, 'hotels' => $results));
             } else {
                 echo json_encode(array('cacheId' => $cacheId, 'hotels' => array()));
             }
         } else {
             //invalid form
             throw new CHttpException(500, CHtml::errorSummary($hotelForm));
         }
         Yii::app()->end();
     } else {
         throw new CHttpException(404);
     }
 }
 public function hotelSearchFullDetails(HotelSearchParams $hotelSearchParams, $hotelId, $hotels = null)
 {
     $rooms = $hotelSearchParams->rooms;
     //Make combinations to combinations Array
     //uasort($rooms,'HotelBookClient::compareArrayAdultCount');
     $maxAdultCount = 0;
     foreach ($rooms as $room) {
         $count = $room['adultCount'] + $room['childCount'];
         if ($count > $maxAdultCount) {
             $maxAdultCount = $count;
         }
     }
     if ($maxAdultCount > 4) {
         $maxAdultCount = 4;
     }
     self::$groupId = substr(md5(uniqid('', true)), 0, 10);
     $i = 1;
     $j = 0;
     $end = false;
     $reqs = array();
     while (!$end) {
         $params = array('cityId' => $hotelSearchParams->city->hotelbookId, 'checkIn' => $hotelSearchParams->checkIn, 'duration' => $hotelSearchParams->duration, 'hotelId' => $hotelId);
         $params['rooms'] = array();
         $params['rooms'][] = array('roomSizeId' => self::$roomSizeRoomTypesMap[$i][$j], 'child' => 0, 'cots' => 0, 'roomNumber' => 1);
         $reqs[] = self::hotelSearch($params, true);
         if (count(self::$roomSizeRoomTypesMap[$i]) > $j + 1) {
             $j++;
         } elseif ($i < $maxAdultCount) {
             $i++;
             $j = 0;
         } else {
             $end = true;
         }
     }
     //run all requests
     $this->processAsyncRequests();
     //$hotelStacks = array();
     $hotels = array();
     foreach ($reqs as $requestId) {
         $hotelStack = new HotelStack();
         if ($this->requests[$requestId]['result']->hotels) {
             //print_r($this->requests[$requestId]['result']);die();
             foreach ($this->requests[$requestId]['result']->hotels as $hotel) {
                 $hotelStack->addHotel($hotel);
             }
             foreach ($hotelStack->_hotels as $key => $hotel) {
                 if (!isset($hotels[$key])) {
                     $hotels[$key] = $hotel;
                 }
             }
         }
         //$hotelStacks[] = $hotelStack;
     }
     return $hotels;
 }
Exemple #4
0
 public function sortBy($sKey = '', $deep = 0)
 {
     if ($sKey) {
         self::$sortParam = $sKey;
         if (self::$sortParam != $this->groupKey) {
             if ($this->_hotels) {
                 uasort($this->_hotels, 'HotelStack::compareHotelsByHotelsParams');
             } elseif ($this->hotelStacks) {
                 if ($deep != 0) {
                     foreach ($this->hotelStacks as $i => $hotelStack) {
                         $this->hotelStacks[$i]->sortBy($sKey, $deep - 1);
                     }
                 }
                 //echo "sorting hotelStacks<br>";
                 try {
                     uasort($this->hotelStacks, 'HotelStack::compareStacksByHotelsParams');
                 } catch (CException $e) {
                     //echo "group: {$this->groupKey}";
                     print_r($this->hotelStacks);
                 }
             } else {
                 return false;
             }
         }
     }
     return $this;
 }
 public function actionInfo($cacheId, $hotelId)
 {
     Yii::import('site.common.modules.hotel.models.*');
     Yii::trace('my great message here', 'hotelController');
     $hotelSearchParams = Yii::app()->cache->get('hotelSearchParams' . $cacheId);
     $resultSearch = Yii::app()->cache->get('hotelResult' . $cacheId);
     if ($resultSearch) {
         $hotelStack = new HotelStack($resultSearch);
         $hotelStack->groupBy('hotelId')->groupBy('roomShowName')->groupBy('rubPrice')->sortBy('rubPrice', 2);
         $resultsRecommended = $hotelStack->hotelStacks[$hotelId]->getAsJson();
         $HotelClient = new HotelBookClient();
         $hotels = $HotelClient->hotelSearchFullDetails($hotelSearchParams, $hotelId);
         $hotelStackFull = new HotelStack(array('hotels' => $hotels));
         $resultsAll = $hotelStackFull->getAsJson();
         $hotelInfo = $HotelClient->hotelDetail($hotelId);
         $this->render('resultInfo', array('items' => $this->generateItems(), 'autosearch' => false, 'cityName' => $hotelSearchParams->city->localRu, 'hotelInfo' => $hotelInfo, 'resultsRecommended' => $resultsRecommended, 'resultsAll' => $resultsAll, 'cacheId' => $cacheId));
     } else {
         $this->redirect('/booking/hotel/');
     }
 }