public function saveRow($cityId, $canonicalName, $rating, $name)
 {
     $hr = new HotelRating();
     $hr->city_id = $cityId;
     $hr->canonical_name = $canonicalName;
     $hr->rating = $rating;
     try {
         $hr->save();
     } catch (CDbException $exc) {
         $this->logError("duplicated canonical_name '" . $canonicalName . " | " . $name . "'");
     }
 }
 /**
  * Helper method, to inject user rating to search result
  * where possible
  * @param mixed &$resultSearch results from booking engine
  * @param City $city City model instance for this search
  */
 public function injectRating(&$resultSearchHotels, $city)
 {
     if (!$resultSearchHotels) {
         return;
     }
     $hotelNamesToFind = array();
     foreach ($resultSearchHotels as $hotel) {
         $hotelNamesToFind[$hotel->hotelName] = 1;
     }
     $hotelNamesToFind = array_keys($hotelNamesToFind);
     $nameToRating = HotelRating::model()->findByNames($hotelNamesToFind, $city);
     foreach ($resultSearchHotels as &$hotel) {
         $hotelName = $hotel->hotelName;
         if (isset($nameToRating[$hotelName])) {
             $hotel->rating = $nameToRating[$hotelName];
         }
     }
 }
示例#3
0
 public function saveHotelDb()
 {
     $hotels = $this->getJsonObject(0);
     if ($hotels) {
         $city = City::getCityByPk($hotels['hotels'][0]['cityId']);
         $hotelNames = array();
         foreach ($hotels['hotels'] as $hotelInfo) {
             $hotelNames[$hotelInfo['hotelName']] = $hotelInfo['hotelName'];
         }
         $ratingNames = HotelRating::model()->findByNames($hotelNames, $city);
         foreach ($hotels['hotels'] as $hotelInfo) {
             $hotelDb = HotelDb::lazySaveHotelDb(array('id' => $hotelInfo['hotelId'], 'name' => $hotelInfo['hotelName'], 'stars' => $hotelInfo['categoryId'], 'cityId' => $city->id, 'countryId' => $city->countryId, 'rating' => isset($ratingNames[$hotelInfo['hotelName']]) ? $ratingNames[$hotelInfo['hotelName']] : null, 'minPrice' => $hotelInfo['rubPrice']));
         }
         HotelDb::lazySave();
     }
 }
示例#4
0
 public function actionHotelInfo($hotelId)
 {
     Yii::import('site.common.modules.hotel.models.*');
     $hotelClient = new HotelBookClient();
     $criteria = new CDbCriteria();
     //$criteria->addInCondition('`cityId`',$cityIds);
     $criteria->addCondition('id = ' . $hotelId);
     $hc = HotelDb::model()->find($criteria);
     $hotelsInfo = array();
     if ($hc) {
         $hotelInfo = $hotelClient->hotelDetail($hc->id);
         $hotelInfo->price = $hc->minPrice;
         $hotelInfo->hotelName = $hc->name;
         $hotelInfo->hotelId = $hc->id;
         $city = City::getCityByPk($hc->cityId);
     } else {
         $hotelInfo = $hotelClient->hotelDetail($hotelId);
         if ($hotelInfo->city) {
             $city = $hotelInfo->city;
         }
     }
     if ($city) {
         $rating = new HotelRating();
         $ratings = $rating->findByNames(array($hotelInfo->hotelName), $city);
         if ($ratings) {
             foreach ($ratings as $rate) {
                 break;
             }
             $hotelInfo->rating = $rate;
         }
     }
     $serviceGroupIcons = array('Сервис' => 'service', 'Спорт и отдых' => 'sport', 'Туристам' => 'turist', 'Интернет' => 'internet', 'Развлечения и досуг' => 'dosug', 'Парковка' => 'parkovka', 'Дополнительно' => 'dop', 'В отеле' => 'in-hotel');
     $serviceList = array();
     if ($hotelInfo->hotelGroupServices) {
         foreach ($hotelInfo->hotelGroupServices as $grName => $group) {
             $serviceList[] = array('name' => $grName, 'icon' => $serviceGroupIcons[$grName], 'elements' => $group);
         }
     }
     //print_r($serviceList);die();
     $this->layout = 'static';
     $this->render('hotelInfo', array('hotelInfo' => $hotelInfo, 'serviceList' => $serviceList));
 }