/**
  * 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];
         }
     }
 }
示例#2
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();
     }
 }