public function actionCity($query, $airport_req = false, $hotel_req = false) { $cacheKey = 'apiAutocompleteCities4' . md5(serialize(array($query, $airport_req, $hotel_req))); $citiesCache = Yii::app()->cache->get($cacheKey); if ($citiesCache) { $this->send($citiesCache); Yii::app()->end(); } if ($airport_req && $hotel_req) { if ($airport_req > $hotel_req) { $cities = CityManager::getCitiesWithAirportsAndHotels($query); } else { $cities = CityManager::getCitiesWithHotelsAndAirports($query); } } elseif ($airport_req) { $cities = CityManager::getCitiesWithAirports($query); } elseif ($hotel_req) { $cities = CityManager::getCitiesWithHotels($query); } else { $cities = CityManager::getCities($query); } $cities = $this->addMoreInfo($cities); $result = $this->buildResult($query, $cities); Yii::app()->cache->set($cacheKey, $result, appParams('autocompleteCacheTime')); $this->send($result); }
public function actionCityForHotel($query, $return = false) { $cities = CityManager::getCitiesWithHotels($query); if ($return) { return $cities; } else { $this->send($cities); } }
/** * @param string city * @param string checkIn d.m.Y date * @param int duration # of nights inside hotel * @param array $rooms * [Х][adt] - amount of adults inside room, * [Х][chd] - amount of childs inside room, * [Х][chdAge] - age of child inside room, * [Х][cots] - cots inside room (0 or 1), */ public function actionDefault($city, $checkIn, $duration, array $rooms, $format = 'json') { $hotelSearchParams = new HotelSearchParams(); $hotelSearchParams->checkIn = date('Y-m-d', strtotime($checkIn)); $possibleCities = CityManager::getCitiesWithHotels($city); if (!empty($possibleCities)) { $hotelSearchParams->city = City::model()->findByPk($possibleCities[0]['id']); } else { $city = CityManager::getCities($city); if (!empty($city)) { $hotelSearchParams->city = City::model()->findByPk($city[0]['id']); } } $hotelSearchParams->duration = $duration; foreach ($rooms as $i => $room) { if ($room['chd'] == 1) { $hotelSearchParams->addRoom($room['adt'], $room['cots'], $room['chdAge']); } elseif ($room['chd'] == 0) { $hotelSearchParams->addRoom($room['adt'], $room['cots'], false); } else { $this->sendError(200, 'Only 0 or 1 child at one hotel room accepted'); Yii::app()->end(); } } if (empty($possibleCities)) { $this->results = array('hotels' => array(), 'hotelsDetails' => array()); } else { $this->results = HotelManager::sendRequestToHotelProvider($hotelSearchParams); if (!$this->results) { $this->results = array(); } } $cacheId = md5(serialize($hotelSearchParams)); $this->results['cacheId'] = $cacheId; $this->results['searchParams'] = $hotelSearchParams->getJsonObject(); if ($format == 'json') { $this->sendJson($this->results); } elseif ($format == 'xml') { $this->sendXml($this->results, 'hotelSearchResults'); } else { $this->sendError(400, 'Incorrect response format'); Yii::app()->end(); } }