Esempio n. 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;
     }
 }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
 public function actionIndex($isTab = false)
 {
     Yii::import('site.common.modules.hotel.models.*');
     $hotelForm = new HotelForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'hotel-form') {
         echo CActiveForm::validate($hotelForm);
         Yii::app()->end();
     }
     if (isset($_POST['HotelForm'])) {
         $hotelForm->attributes = $_POST['HotelForm'];
         $rooms = array();
         if (isset($_POST['HotelRoomForm'])) {
             foreach ($_POST['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();
             $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'));
             Yii::app()->user->setState('hotel.cacheId', $cacheId);
             //die();
             $this->redirect('/booking/hotel/result/cacheId/' . $cacheId);
         } else {
             $this->render('index', array('items' => $this->generateItems(), 'hotelForm' => $hotelForm, 'autosearch' => false, 'cityName' => '', 'duration' => 1));
         }
     } else {
         if ($isTab) {
             $this->renderPartial('index', array('items' => $this->generateItems(), 'hotelForm' => $hotelForm, 'autosearch' => false, 'cityName' => '', 'duration' => 1));
         } else {
             $this->render('index', array('items' => $this->generateItems(), 'hotelForm' => $hotelForm, 'autosearch' => false, 'cityName' => '', 'duration' => 1));
         }
     }
 }
 private function coverageForCity($city)
 {
     $hotelSearchParams = new HotelSearchParams();
     $hotelSearchParams->checkIn = date('Y-m-d', strtotime('10.08.2012'));
     $hotelSearchParams->city = $city;
     $hotelSearchParams->duration = 1;
     $hotelSearchParams->addRoom(1, 0, false);
     $HotelClient = new HotelBookClient();
     $resultSearch = $HotelClient->fullHotelSearch($hotelSearchParams);
     Yii::app()->hotelsRating->injectRating($resultSearch->hotels, $hotelSearchParams->city);
     if (!@count($resultSearch['hotels'])) {
         return 'No results';
     }
     $total = 0;
     $rated = 0;
     foreach ($resultSearch['hotels'] as $hotel) {
         $total++;
         if ($hotel->rating && $hotel->rating !== '-') {
             $rated++;
         }
     }
     return "{$rated}/{$total}" . '=' . intval($rated / $total * 100) . '%';
 }