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 actionInfo($hotelId, $hotelResult, $cacheId = null, $format = 'json') { $hotelClient = new HotelBookClient(); $response = array(); $response['hotel'] = array(); $response['hotel']['oldHotels'] = array(); $response['hotel']['details'] = array(); $hotelResultIDS = explode(',', $hotelResult); $hotelResult = array(); foreach ($hotelResultIDS as $hotelStr) { list($resultId, $searchId) = explode(':', $hotelStr); $hotelResult[$resultId] = $searchId; } foreach ($hotelResult as $resultId => $searchId) { $response['hotel']['oldHotels'][] = new Hotel(array('searchId' => $searchId, 'resultId' => $resultId, 'hotelId' => $hotelId)); } if (isset($response)) { $null = null; $hotelClient->hotelSearchDetails($null, $response['hotel']['oldHotels']); if ($format == 'json') { $this->sendJson($response); } elseif ($format == 'xml') { $this->sendXml($response, 'hotelSearchResults'); } Yii::app()->end(); } $this->sendError(200, 'No hotel with given hotelId found'); }
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); } }
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) . '%'; }
/** * Manages all models. */ public function actionAdmin() { /*$roomSizes = array( 'Одноместный %s', 'Двухместный %s', 'Двухместный Твин %s', 'Двухместный %s с одноместным размещением', 'Трехместный %s', 'Четырехместный %s', ); $roomTypes = array( 'большой номер', 'номер студия', 'семейный номер', 'семейный номер студия', 'номер Сьюит', 'улучшеный номер', 'Эконом', 'Бизнес', 'номер De luxe', 'номер для молодожёнов', 'номер с балконом', ); foreach($roomTypes as $roomType){ foreach($roomSizes as $roomSize){ $name = sprintf($roomSize,$roomType); $roomName = new RoomNamesRus(); $roomName->roomNameRus = $name; $roomName->save(); } }*/ /*$criteria = new CDbCriteria(); $criteria->group = 'sizeName,typeName,roomNameCanonical'; $roomSizes = array('DBL'=>2,'SGL'=>1,'TWIN'=>3,'TWIN for Single use'=>4,'TRPL'=>5,'QUAD'=>6,'DBL for Single use'=>7,'DBL OR TWIN'=>8); echo 'найдено комбинаций: '.HotelRoomDb::model()->count($criteria); $rooms = HotelRoomDb::model()->findAll($criteria); /** @var $rooms HotelRoomDb[] */ /*foreach($rooms as $room){ if($room->roomNameCanonical){ $nemoRoom = new RoomNamesNemo(); $nemoRoom->roomTypeId = $room->typeId; $nemoRoom->roomSizeId = $roomSizes[$room->sizeName]; $nemoRoom->roomNameCanonical = $room->roomNameCanonical; $nemoRoom->save(); } }*/ /* * связи для таблиц */ //двухместные апартаменты /*$criteria = new CDbCriteria(); $criteria->addSearchCondition('roomNameCanonical', '%apartment%', false); $criteria->addSearchCondition('roomSizeId',6); //$criteria->group = 'sizeName,typeName,roomNameCanonical'; //$roomSizes = array('DBL'=>2,'SGL'=>1,'TWIN'=>3,'TWIN for Single use'=>4,'TRPL'=>5,'QUAD'=>6,'DBL for Single use'=>7,'DBL OR TWIN'=>8); echo 'найдено комбинаций: '.RoomNamesNemo::model()->count($criteria).'<br />'; $rooms = RoomNamesNemo::model()->findAll($criteria); $rusRoomName = RoomNamesRus::model()->findByAttributes(array('roomNameRus'=>'Четырехместные апартаменты')); VarDumper::dump($rusRoomName);*/ /** @var $rooms RoomNamesNemo[] */ /*foreach($rooms as $room){ echo "{$rusRoomName->roomNameRus} {$rusRoomName->id}<br />"; if($room->roomNameCanonical){ echo $room->roomSizeId.' '.$room->roomNameCanonical.' <br />'; $room->roomNameRusId = $rusRoomName->id; $room->save(); //$nemoRoom = new RoomNamesNemo(); //$nemoRoom->roomTypeId = $room->typeId; //$nemoRoom->roomSizeId = $roomSizes[$room->sizeName]; //$nemoRoom->roomNameCanonical = $room->roomNameCanonical; //$nemoRoom->save(); } }*/ //семейные /*$criteria = new CDbCriteria(); $criteria->addSearchCondition('roomNameCanonical', '%family%', false); $criteria->addSearchCondition('roomSizeId',3); //$criteria->group = 'sizeName,typeName,roomNameCanonical'; //$roomSizes = array('DBL'=>2,'SGL'=>1,'TWIN'=>3,'TWIN for Single use'=>4,'TRPL'=>5,'QUAD'=>6,'DBL for Single use'=>7,'DBL OR TWIN'=>8); echo 'найдено комбинаций: '.RoomNamesNemo::model()->count($criteria).'<br />'; $rooms = RoomNamesNemo::model()->findAll($criteria); $rusRoomName = RoomNamesRus::model()->findByAttributes(array('roomNameRus'=>'Двухместный Твин семейный номер')); VarDumper::dump($rusRoomName);*/ /** @var $rooms RoomNamesNemo[] */ /*foreach($rooms as $room){ echo "{$rusRoomName->roomNameRus} {$rusRoomName->id}<br />"; if($room->roomNameCanonical){ echo $room->roomSizeId.' '.$room->roomNameCanonical.' <br />'; $room->roomNameRusId = $rusRoomName->id; $room->save(); } }*/ //studio /*$criteria = new CDbCriteria(); $criteria->addSearchCondition('roomNameCanonical', '%suite%', false); $criteria->addSearchCondition('roomSizeId',6); //$criteria->group = 'sizeName,typeName,roomNameCanonical'; //$roomSizes = array('DBL'=>2,'SGL'=>1,'TWIN'=>3,'TWIN for Single use'=>4,'TRPL'=>5,'QUAD'=>6,'DBL for Single use'=>7,'DBL OR TWIN'=>8); echo 'найдено комбинаций: '.RoomNamesNemo::model()->count($criteria).'<br />'; $rooms = RoomNamesNemo::model()->findAll($criteria); $rusRoomName = RoomNamesRus::model()->findByAttributes(array('roomNameRus'=>'Четырехместный большой номер')); VarDumper::dump($rusRoomName); /** @var $rooms RoomNamesNemo[] */ /*foreach($rooms as $room){ echo "{$rusRoomName->roomNameRus} {$rusRoomName->id}<br />"; if($room->roomNameCanonical){ echo $room->roomSizeId.' '.$room->roomNameCanonical.' <br />'; //$room->roomNameRusId = $rusRoomName->id; //$room->save(); } } //studio /*$criteria = new CDbCriteria(); $criteria->addSearchCondition('roomNameCanonical', '%tive suite%', false); $criteria->addSearchCondition('roomSizeId',3); //$criteria->group = 'sizeName,typeName,roomNameCanonical'; //$roomSizes = array('DBL'=>2,'SGL'=>1,'TWIN'=>3,'TWIN for Single use'=>4,'TRPL'=>5,'QUAD'=>6,'DBL for Single use'=>7,'DBL OR TWIN'=>8); echo 'найдено комбинаций: '.RoomNamesNemo::model()->count($criteria).'<br />'; $rooms = RoomNamesNemo::model()->findAll($criteria); $rusRoomName = RoomNamesRus::model()->findByAttributes(array('roomNameRus'=>'Двухместный Твин улучшеный номер')); VarDumper::dump($rusRoomName);*/ /** @var $rooms RoomNamesNemo[] */ /*foreach($rooms as $room){ echo "{$rusRoomName->roomNameRus} {$rusRoomName->id}<br />"; if($room->roomNameCanonical){ echo $room->roomSizeId.' '.$room->roomNameCanonical.' <br />'; //$room->roomNameRusId = $rusRoomName->id; //$room->save(); } }*/ //распечатать все /*$rusRoomNames = RoomNamesRus::model()->findAll(); foreach($rusRoomNames as $room){ echo "{$room->id} {$room->roomNameRus} <br />"; }*/ Yii::import('site.common.modules.hotel.models.*'); $hbc = new HotelBookClient(); $rts = $hbc->getRoomTypes(); $roomTypes = array(); foreach ($rts as $rt) { $roomTypes[$rt['id']] = $rt['name']; } VarDumper::dump($roomTypes); }
public static function updateRoomTypes($pk) { Yii::import('site.common.modules.hotel.models.*'); $hotelClient = new HotelBookClient(); $roomTypes = $hotelClient->getRoomTypes(); RoomTypeHotelbook::model()->deleteAll(); foreach ($roomTypes as $roomType) { $roomTypeHotelbook = new RoomTypeHotelbook(); $roomTypeHotelbook->id = $roomType['id']; $roomTypeHotelbook->name = $roomType['name']; $roomTypeHotelbook->save(); } }
public function synchronize($forced = false) { if (!$this->isSynchronized or $forced) { self::$lastRequestMethod = 'unixtime'; $diff = Yii::app()->cache->get('hotelbookDifferenceTimestamp'); if ($diff === false or $forced) { $unixtime = $this->request(Yii::app()->params['HotelBook']['uri'] . 'unix_time'); $this->differenceTimestamp = $unixtime - time(); Yii::app()->cache->set('hotelbookDifferenceTimestamp', $this->differenceTimestamp, 30 * 60); } else { $this->differenceTimestamp = $diff; } $this->isSynchronized = true; } }
/** * @static * @param $roomNameCanonical * @param null $roomSizeId * @param null $roomTypeId * @return RoomNamesNemo */ public static function &getNamesByParams($roomNameCanonical, $roomSizeId = null, $roomTypeId = null) { $startTime = microtime(true); HotelBookClient::$countFunc++; $roomParamsKey = ($roomNameCanonical ? $roomNameCanonical : '') . '|' . ($roomSizeId ? $roomSizeId : '') . '|' . ($roomTypeId ? $roomTypeId : ''); if ($roomParamsKey != '||') { if (isset(RoomNamesNemo::$paramsIdMap[$roomParamsKey])) { $endTime = microtime(true); $fullTime = $endTime - $startTime; if ($fullTime > HotelBookClient::$maxMicrotime) { HotelBookClient::$maxMicrotime = $fullTime; } HotelBookClient::$totalMicrotime += $fullTime; return RoomNamesNemo::$roomNames[RoomNamesNemo::$paramsIdMap[$roomParamsKey]]; } else { self::$needLoading = true; self::$roomNames[self::$lazyIndex] = new RoomNamesNemo(); self::$roomNames[self::$lazyIndex]->roomNameCanonical = $roomNameCanonical; self::$roomNames[self::$lazyIndex]->roomSizeId = $roomSizeId; self::$roomNames[self::$lazyIndex]->roomTypeId = $roomTypeId; self::$paramsIdMap[$roomParamsKey] = self::$lazyIndex; self::$lazyLoadObjectsIds[self::$lazyIndex] = self::$lazyIndex; //$newRoomNameNemo = new RoomNamesNemo(); //$newRoomNameNemo->roomNameCanonical = $roomNameCanonical; //$newRoomNameNemo->roomSizeId = $this->sizeId; //$newRoomNameNemo->roomTypeId = $this->typeId; //$roomNameNemo = RoomNamesNemo::model()->findByAttributes(array( // 'roomNameCanonical' => $roomNameCanonical, // 'roomSizeId'=> $roomSizeId, // 'roomTypeId'=> $roomTypeId //)); self::$lazyIndex++; HotelBookClient::$countSql++; //return $roomParamsKey; return self::$roomNames[self::$lazyIndex - 1]; } /*}elseif($roomNameCanonical){ if(isset(RoomNamesNemo::$nameIdMap[$roomNameCanonical])) { $endTime = microtime(true); $fullTime = $endTime - $startTime; if($fullTime > HotelBookClient::$maxMicrotime) HotelBookClient::$maxMicrotime = $fullTime; HotelBookClient::$totalMicrotime += $fullTime; return RoomNamesNemo::$roomNames[RoomNamesNemo::$nameIdMap[$roomNameCanonical]]; } else { $roomNameNemo = RoomNamesNemo::model()->findByAttributes(array( 'roomNameCanonical' => $roomNameCanonical )); HotelBookClient::$countSql++; }*/ } else { $endTime = microtime(true); $fullTime = $endTime - $startTime; if ($fullTime > HotelBookClient::$maxMicrotime) { HotelBookClient::$maxMicrotime = $fullTime; } HotelBookClient::$totalMicrotime += $fullTime; return false; } /*if($roomNameNemo) { RoomNamesNemo::$roomNames[$roomNameNemo->id] = $roomNameNemo; $roomParamsKey = $roomNameNemo->roomNameCanonical.'|'.$roomNameNemo->roomSizeId.'|'.$roomNameNemo->roomTypeId; if($roomParamsKey){ RoomNamesNemo::$paramsIdMap[$roomParamsKey] = $roomNameNemo->id; } if($roomNameNemo->roomNameCanonical){ RoomNamesNemo::$nameIdMap[$roomNameNemo->roomNameCanonical] = $roomNameNemo->id; } $endTime = microtime(true); $fullTime = $endTime - $startTime; if($fullTime > HotelBookClient::$maxMicrotime) HotelBookClient::$maxMicrotime = $fullTime; HotelBookClient::$totalMicrotime += $fullTime; return $roomNameNemo; }else{ $endTime = microtime(true); $fullTime = $endTime - $startTime; if($fullTime > HotelBookClient::$maxMicrotime) HotelBookClient::$maxMicrotime = $fullTime; HotelBookClient::$totalMicrotime += $fullTime; return false; }*/ }
public function addHotelTripElement($hotel, $hotelSearchParams) { $hotelTripElement = new HotelTripElement(); $hotelTripElement->fillFromSearchParams($hotelSearchParams); Yii::import('site.common.modules.hotel.models.*'); $hotelClient = new HotelBookClient(); $hotelClient->hotelSearchDetails($hotel); $hotelTripElement->hotel = $hotel; Yii::app()->shoppingCart->put($hotelTripElement); }
/** * Execute the action. * @param array command line parameters specific for this command */ public function actionIndex($type = 'hotels', $filename = '', $countryStartId = null, $cityStartId = null) { if ($type == 'hotels') { echo Yii::app()->params['HotelBook']['uri'] . "\n"; echo Yii::app()->params['HotelBook']['login'] . "\n"; echo Yii::app()->params['HotelBook']['password'] . "\n"; //die(); Yii::import('site.common.modules.hotel.models.*'); $HotelClient = new HotelBookClient(); $HotelClient->synchronize(true); $countries = $HotelClient->getCountries(); $countryStart = false; $cityStart = false; foreach ($countries as $country) { if ($countryStartId && !$countryStart) { if ($countryStartId == $country['id']) { $countryStart = true; } else { continue; } } else { $countryStart = true; } echo "process country with id: {$country['id']}\n"; $hotelCities = $HotelClient->getCities($country['id']); foreach ($hotelCities as $hotelCity) { if ($cityStartId && !$cityStart) { if ($cityStartId == $hotelCity['id']) { $cityStart = true; } else { continue; } } else { $cityStart = true; } echo "process city with id: {$hotelCity['id']}\n"; echo "Memory usage: {peak:" . ceil(memory_get_peak_usage() / 1024) . "kb , now: " . ceil(memory_get_usage() / 1024) . "kb }\n"; $cityHotels = $HotelClient->getHotels($hotelCity['id']); foreach ($cityHotels as $hotel) { $tryAgain = 3; while ($tryAgain) { $hotelDetail = $HotelClient->hotelDetail($hotel['id']); if (!$hotelDetail) { echo "Cant get hotelDetail for hotelId:{$hotel['id']} cityId:{$hotelCity['id']}\n"; $tryAgain--; $cachePath = Yii::getPathOfAlias('cacheStorage'); $cacheSubDir = md5('HotelDetail' . $hotel['id'] . '.xml'); $cacheSubDir = substr($cacheSubDir, -3); $cacheFilePath = $cachePath . '/' . $cacheSubDir . '/HotelDetail' . $hotel['id'] . '.xml'; if (file_exists($cacheFilePath)) { unlink($cacheFilePath); } unset($cachePath); unset($cacheSubDir); unset($cacheFilePath); if (!$tryAgain) { echo "HotelError hotelId:{$hotel['id']} cityId:{$hotelCity['id']}\n"; } } else { $tryAgain = 0; if (!$tryAgain) { echo "HotelOK hotelId:{$hotel['id']} cityId:{$hotelCity['id']}\n"; } } usleep(200000); } } unset($cityHotels); //echo count($cityHotels) . " hotel completed\n"; } unset($hotelCities); echo "Memory usageB: {peak:" . ceil(memory_get_peak_usage() / 1024) . "kb , now: " . ceil(memory_get_usage() / 1024) . "kb }\n"; } } }
/** * Execute the action. * @param array command line parameters specific for this command */ public function actionIndex($type = 'airports', $filename = '') { if ($type == 'airports') { if ($filename) { $path = Yii::getPathOfAlias('application.runtime'); if (file_exists($filename)) { $fp = fopen($filename, 'r'); $outfp = fopen($path . '/' . basename($filename), 'w'); if (!$outfp) { echo "Cant open file " . $path . '/' . basename($filename) . " for writing\n"; die; } $formatLine = fgets($fp); $formatLine = str_replace(array("\r", "\n"), array(''), $formatLine); $columnNames = explode('|', $formatLine); //print_r($formatLine);die(); $column = array(); foreach ($columnNames as $i => $columnName) { $column[$columnName] = $i; } //print_r($column); $skipAll = false; while (!feof($fp)) { $lineData = fgets($fp); $lineData = str_replace(array("\r", "\n"), array(''), $lineData); $lineData = iconv("cp1251", "UTF-8", $lineData); $data = explode('|', $lineData); $needSave = true; $country = Country::getCountryByCode($data[$column['country_code']]); if ($country) { $cities = $this->getCities($country->id, $data[$column['city_en']], $data[$column['city_ru']]); if (!$cities) { $cities = City::model()->findAllByAttributes(array('countryId' => $country->id, 'code' => $data[$column['iata_code']])); } $abort = false; while (!$abort) { if ($cities) { if (count($cities) > 1) { $citiesTmp = City::model()->findAllByAttributes(array('countryId' => $country->id, 'code' => $data[$column['iata_code']])); if ($citiesTmp && count($citiesTmp) == 1) { $cities = $citiesTmp; } } if (count($cities) > 1) { echo "Found " . count($cities) . " cities for line: {$lineData}\n"; echo str_pad('code', 5, " ", STR_PAD_RIGHT) . str_pad('localRu', 15, " ", STR_PAD_LEFT) . str_pad('localEn', 15, " ", STR_PAD_LEFT) . "\n"; foreach ($cities as $city) { echo str_pad($city->code, 5, " ", STR_PAD_RIGHT) . str_pad($city->localRu, 15, " ", STR_PAD_LEFT) . str_pad($city->localEn, 15, " ", STR_PAD_LEFT) . "\n"; } echo "Type code of the selected city:\n"; $name = trim(fgets(STDIN)); $cities = $this->getCities($country->id, $name); } else { $this->selectAirport($data, $column, $lineData, $outfp, $cities[0]); $abort = true; } } else { echo "City not found in Db. Type s - skip, c - create, f - try find in db:\n"; echo "{$lineData}\n"; //$char = trim(fgets(STDIN)); $char = 's'; if ($char == 's') { echo "Dont found any same city. Skipping line: {$lineData} \n"; fwrite($outfp, $lineData . "|nocity\n"); $abort = true; } elseif ($char == 'c') { $city = new City(); echo "Creating new city...\n"; $city->countryId = $country->id; if (!$data[$column['city_ru']]) { $data[$column['city_ru']] = $data[$column['city_en']]; } echo "City name rus (default {$data[$column['city_ru']]}):\n"; $newName = trim(fgets(STDIN)); if ($newName) { $city->localRu = $newName; } else { $city->localRu = $data[$column['city_ru']]; } echo "City name eng (default {$data[$column['city_en']]}):\n"; $newName = trim(fgets(STDIN)); if ($newName) { $city->localEn = $newName; } else { $city->localEn = $data[$column['city_en']]; } echo "City code:\n"; $newCode = trim(fgets(STDIN)); if ($newCode) { $city->code = $newCode; } else { continue; } $city->position = 0; $city->save(); $city->id = $city->getPrimaryKey(); $this->selectAirport($data, $column, $lineData, $outfp, $city); } else { echo "Type part of city name:\n"; $name = trim(fgets(STDIN)); $cities = $this->getCities($country->id, $name); } } } } else { echo "Country not found, skipping line: {$lineData} \n"; fwrite($outfp, $lineData . "|nocountry\n"); } } fclose($fp); fclose($outfp); } else { echo 'Import file not found on path: ' . $filename; } } else { echo 'Option --filename cant be empty'; } } if ($type == 'airlineWeight') { echo 'INN'; if ($filename) { $path = Yii::getPathOfAlias('application.runtime'); if (file_exists($filename)) { $airlinessxe = simplexml_load_string(file_get_contents($filename)); foreach ($airlinessxe->Item as $item) { $airlineCode = (string) $item['id']; $modified = false; try { $airline = Airline::getAirlineByCode($airlineCode); } catch (CException $e) { $airline = false; } if ($airline) { $airlineLocalRu = (string) $item['rusname']; $airlineLocalEn = (string) $item['name']; if (UtilsHelper::countRussianCharacters($airline->localRu) <= 0) { $airline->localRu = $airlineLocalRu; $modified = true; } else { echo "o_O !!! " . $airline->localRu; } if (!$airline->localEn && $airlineLocalEn) { $airline->localEn = $airlineLocalEn; $modified = true; } $economPrice = (string) $item->luggage->econom->price; $economFreeWeight = (string) $item->luggage->econom->weight; if ($airline->economFreeWeight && $economFreeWeight) { if ($economPrice == 'charge') { $airline->economFreeWeight = 0; } else { $airline->economFreeWeight = str_replace('kg', '', $economFreeWeight); } $modified = true; } $businessPrice = (string) $item->luggage->business->price; $businessFreeWeight = (string) $item->luggage->business->weight; if ($airline->businessFreeWeight && $businessFreeWeight) { if ($businessPrice == 'charge') { $airline->businessFreeWeight = 0; } else { $airline->businessFreeWeight = str_replace('kg', '', $businessFreeWeight); } $modified = true; } $economDescription = (string) $item->luggage->econom->description; if ($airline->economDescription && $economDescription) { $economDescription = substr($economDescription, strpos($economDescription, 'Багаж не должен')); $airline->economDescription = trim($economDescription); $modified = true; } $businessDescription = (string) $item->luggage->business->description; if ($airline->businessDescription && $businessDescription) { $businessDescription = substr($businessDescription, strpos($businessDescription, 'Багаж не должен')); $airline->businessDescription = trim($businessDescription); echo "try modyf "; $modified = true; } if ($modified) { $airline->save(); } } else { echo "!!!! NOT FOUND {$airlineCode}"; $airline = new Airline(); $airline->code = $airlineCode; $airlineLocalRu = (string) $item['rusname']; $airlineLocalEn = (string) $item['name']; if (UtilsHelper::countRussianCharacters($airline->localRu) <= 0) { $airline->localRu = $airlineLocalRu; $airline->localEn = $airlineLocalEn; $modified = true; } $economFreeWeight = (string) $item->luggage->econom->weight; if (!$airline->economFreeWeight && $economFreeWeight) { $airline->economFreeWeight = str_replace('kg', '', $economFreeWeight); $modified = true; } $businessFreeWeight = (string) $item->luggage->business->weight; if (!$airline->businessFreeWeight && $businessFreeWeight) { $airline->businessFreeWeight = str_replace('kg', '', $businessFreeWeight); $modified = true; } $economDescription = (string) $item->luggage->econom->description; if (!$airline->economDescription && $economDescription) { $airline->economDescription = $economDescription; $modified = true; } $businessDescription = (string) $item->luggage->business->description; if (!$airline->businessDescription && $businessDescription) { $airline->businessDescription = $businessDescription; $modified = true; } if (!$airline->save()) { CVarDumper::dump($airline->getErrors()); } } echo "airline {$airlineCode} {$airlineLocalRu} {$economFreeWeight}\n"; } echo 'ютф?'; //CVarDumper::dump($airlinessxe); } } } if ($type == 'iconv') { if ($filename) { $path = Yii::getPathOfAlias('application.runtime'); if (file_exists($filename)) { $data = file_get_contents($filename); echo iconv('cp1251', 'UTF-8', $data); } } } if ($type == 'test') { $cities = City::model()->findAllByAttributes(array('code' => 'LED', 'countryId' => 174)); if ($cities) { echo "Found " . count($cities) . " cities for line: \n"; echo str_pad('code', 5, " ", STR_PAD_RIGHT) . str_pad('localRu', 19, " ", STR_PAD_LEFT) . str_pad('localEn', 19, " ", STR_PAD_LEFT) . "\n"; foreach ($cities as $city) { echo str_pad($city->code, 5, " ", STR_PAD_RIGHT) . str_pad($city->localRu, 19, " ", STR_PAD_LEFT) . str_pad($city->localEn, 19, " ", STR_PAD_LEFT) . ' ' . $city->country->id . "\n"; } } } if ($type == 'hotelbookCountries') { Yii::import('site.common.modules.hotel.models.*'); $HotelClient = new HotelBookClient(); $countries = $HotelClient->getCountries(); print_r($countries); foreach ($countries as $hotelCountry) { $nameRu = $hotelCountry['nameRu']; $name = $hotelCountry['nameEn']; $ourCountries = $this->getCountries($name, $nameRu); if ($ourCountries) { if (count($ourCountries) > 1) { echo "Found " . count($ourCountries) . " countries for nameEn:{$hotelCountry['nameEn']} nameRu:{$hotelCountry['nameRu']} \n"; echo str_pad('code', 5, " ", STR_PAD_RIGHT) . str_pad('localRu', 19, " ", STR_PAD_LEFT) . str_pad('localEn', 19, " ", STR_PAD_LEFT) . "\n"; foreach ($ourCountries as $country) { echo str_pad($country->code, 5, " ", STR_PAD_RIGHT) . str_pad($country->localRu, 19, " ", STR_PAD_LEFT) . str_pad($country->localEn, 19, " ", STR_PAD_LEFT) . ' ' . $country->id . "\n"; } echo "Enter id of country or 's' - for skip \n"; $oldId = trim(fgets(STDIN)); if ($oldId !== 's') { $country = Country::getCountryByPk(intval($oldId)); $country->hotelbookId = $hotelCountry['id']; $country->save(); } } else { $country = $ourCountries[0]; if (!$country->hotelbookId) { $country->hotelbookId = $hotelCountry['id']; $country->save(); } } } else { $nameRu = substr($hotelCountry['nameRu'], 0, strpos($hotelCountry['nameRu'], ' ')); $name = substr($hotelCountry['nameEn'], 0, strpos($hotelCountry['nameRu'], ' ')); $ourCountries = $this->getCountries($name, $nameRu); if ($ourCountries) { if (count($ourCountries) > 1) { echo "Found " . count($ourCountries) . " countries for nameEn:{$hotelCountry['nameEn']} nameRu:{$hotelCountry['nameRu']} \n"; echo str_pad('code', 5, " ", STR_PAD_RIGHT) . str_pad('localRu', 19, " ", STR_PAD_LEFT) . str_pad('localEn', 19, " ", STR_PAD_LEFT) . "\n"; foreach ($ourCountries as $country) { echo str_pad($country->code, 5, " ", STR_PAD_RIGHT) . str_pad($country->localRu, 19, " ", STR_PAD_LEFT) . str_pad($country->localEn, 19, " ", STR_PAD_LEFT) . ' ' . $country->id . "\n"; } echo "Enter id of country or 's' - for skip \n"; $oldId = trim(fgets(STDIN)); if ($oldId !== 's') { $country = Country::getCountryByPk(intval($oldId)); $country->hotelbookId = $hotelCountry['id']; $country->save(); } } else { if (!$country->hotelbookId) { $country = $ourCountries[0]; $country->hotelbookId = $hotelCountry['id']; $country->save(); } } } } } } if ($type == 'geonames') { $criteria = new CDbCriteria(); $criteria->condition = 'hotelbookId IS NOT NULL'; //$criteria->params=array(':postID'=>10); $start = false; $countries = Country::model()->findAll($criteria); $formatLine = 'geonameid|name_mixed|name|names|latitude|longitude|feature|feature_code|country_code|country_codes|state_code|admin2_code|admin3_code|admin4_code|population|elevation|dem|timezone|modification_date'; $formatLine = str_replace(array("\r", "\n"), array(''), $formatLine); $columnNames = explode('|', $formatLine); //print_r($formatLine);die(); $column = array(); foreach ($columnNames as $i => $columnName) { $column[$columnName] = $i; } foreach ($countries as $country) { $filename = '/srv/www/oleg.voyanga/public_html/console/data_files/' . $country->code . '.txt'; if (!$start) { if ($country->code == 'HR') { $start = true; } else { continue; } } if ($filename) { $path = Yii::getPathOfAlias('application.runtime'); if (file_exists($filename)) { echo "Starting parse " . $country->code . ".txt\n"; $fp = fopen($filename, 'r'); //$countryCode = basename($filename); //$countryCode = substr($countryCode,0,strpos($countryCode,'.')); $outfp = fopen($path . '/' . basename($filename), 'w'); if (!$outfp) { echo "Cant open file " . $path . '/' . basename($filename) . " for writing\n"; die; } //print_r($column); $skipAll = false; $lineCount = 0; $addedCount = 0; $haveAltNames = 0; $haveRuName = 0; $haveIataCode = 0; echo str_pad('Parsed', 10, " ", STR_PAD_RIGHT) . str_pad('Added', 10, " ", STR_PAD_RIGHT) . str_pad('AltNames', 10, " ", STR_PAD_RIGHT) . str_pad('RuName', 10, " ", STR_PAD_RIGHT) . str_pad('IataCode', 10, " ", STR_PAD_RIGHT) . "\n"; while (!feof($fp)) { $lineData = fgets($fp); $lineData = str_replace(array("\r", "\n"), array(''), $lineData); $data = explode("\t", $lineData); if (!$data) { continue; } if (count($data) <= 11) { continue; } $lineCount++; $geoNames = new GeoNames(); if ($data[$column['feature_code']]) { if ($data[$column['feature_code']] == 'PPL' || $data[$column['feature_code']] == 'PPLA' || $data[$column['feature_code']] == 'PPLC' || $data[$column['feature_code']] == 'AIRP') { $geoNames->type = $data[$column['feature_code']]; $geoNames->nameEn = $data[$column['name']]; $geoNames->soundexEn = UtilsHelper::soundex($geoNames->nameEn); $geoNames->countryCode = $data[$column['country_code']]; $geoNames->latitude = $data[$column['latitude']]; $geoNames->longitude = $data[$column['longitude']]; if (in_array($data[$column['country_code']], self::$sng)) { $geoNames->nameRu = UtilsHelper::fromTranslite($geoNames->nameEn); $ruFactor = 6; } else { $geoNames->nameRu = UtilsHelper::ruTranscript($geoNames->nameEn); $ruFactor = 12; } if ($data[$column['state_code']]) { $geoNames->stateCode = $data[$column['state_code']]; } if ($data[$column['names']]) { $names = explode(',', $data[$column['names']]); $rusWord = array('index' => 0, 'count' => 0, 'replacements' => 20); $manyRusWords = false; $altNames = array(); $iataCode = ''; foreach ($names as $ind => $altName) { $altNames[] = $altName; if ($this->isIataCode($altName)) { if ($altName != mb_strtoupper($data[$column['name']])) { $iataCode = $altName; $geoNames->iataCode = $iataCode; $haveIataCode++; unset($altNames[$ind]); continue; } } $n = UtilsHelper::countRussianCharacters($altName); if ($n > 0) { $altCase = mb_convert_case($altName, MB_CASE_TITLE, "UTF-8"); $k = levenshtein($geoNames->nameRu, $altName); $l = levenshtein($geoNames->nameRu, $altCase); if ($l < $k) { $k = $l; $altNames[$ind] = $altCase; $names[$ind] = $altCase; } } if ($n > 0 && $k < $rusWord['replacements']) { if ($rusWord['count'] > 0) { $manyRusWords = true; } $rusWord['index'] = $ind; $rusWord['replacements'] = $k; $rusWord['count'] = $n; } } if ($manyRusWords) { fwrite($outfp, "{$geoNames->latitude}|{$geoNames->longitude}|{$data[$column['name']]}|{$names[$rusWord['index']]}\n"); } if ($rusWord['count'] > 0) { if ($rusWord['replacements'] < $ruFactor) { $geoNames->nameRu = $names[$rusWord['index']]; $haveRuName++; //unset($altNames[$rusWord['index']]); } } $geoNames->alternateNames = implode(',', $altNames); unset($names); unset($altNames); unset($rusWord); $haveAltNames++; } $geoNames->soundexRu = UtilsHelper::soundex($geoNames->nameRu, 'RU'); $geoNames->metaphoneRu = UtilsHelper::ruMetaphone($geoNames->nameRu); $geoNames->save(); $addedCount++; } } unset($geoNames); unset($lineData); unset($data); if ($lineCount % 30000 == 0) { echo str_pad($lineCount, 10, " ", STR_PAD_RIGHT) . str_pad($addedCount, 10, " ", STR_PAD_RIGHT) . str_pad($haveAltNames, 10, " ", STR_PAD_RIGHT) . str_pad($haveRuName, 10, " ", STR_PAD_RIGHT) . str_pad($haveIataCode, 10, " ", STR_PAD_RIGHT) . "\n"; } } echo str_pad($lineCount, 10, " ", STR_PAD_RIGHT) . str_pad($addedCount, 10, " ", STR_PAD_RIGHT) . str_pad($haveAltNames, 10, " ", STR_PAD_RIGHT) . str_pad($haveRuName, 10, " ", STR_PAD_RIGHT) . str_pad($haveIataCode, 10, " ", STR_PAD_RIGHT) . "\n"; fclose($outfp); } else { echo "Not found " . $country->code . ".txt\n"; } } //endif filename } //endforeach countries } if ($type == 'hotelbookCities') { Yii::import('site.common.modules.hotel.models.*'); $HotelClient = new HotelBookClient(); $criteria = new CDbCriteria(); $criteria->condition = 'hotelbookId IS NOT NULL'; $path = Yii::getPathOfAlias('application.runtime'); //$criteria->params=array(':postID'=>10); $countries = Country::model()->findAll($criteria); $start = false; foreach ($countries as $country) { if (!$start) { /*if($country->code == 'UA') { $start = true; }else{ continue; }/**/ if ($country->code == 'US') { continue; } } $hotelCities = $HotelClient->getCities($country->hotelbookId); $oneResult = 0; $someResult = 0; $manyResult = 0; $noResult = 0; $outfp = fopen($path . '/' . $country->code . '-hotel-log.txt', 'w'); if (!$outfp) { echo "Cant open file " . $path . '/' . $country->code . "-hotel-log.txt for writing\n"; die; } foreach ($hotelCities as $hotelCity) { if (in_array($country->code, self::$sng)) { $hotelCity['nameRu'] = UtilsHelper::fromTranslite($hotelCity['nameEn']); } else { $hotelCity['nameRu'] = UtilsHelper::ruTranscript($hotelCity['nameEn']); } $hotelCity['metaphoneRu'] = UtilsHelper::ruMetaphone($hotelCity['nameRu']); $hotelCity['sondexEn'] = UtilsHelper::soundex($hotelCity['nameEn']); $hotels = $HotelClient->getHotels($hotelCity); if (count($hotels) == 0) { //We are don't need empty cities continue; } $cnt = 0; $haveCoordinates = false; foreach ($hotels as $hotelObj) { $cnt++; $query[$hotelObj['id']] = $HotelClient->hotelDetail($hotelObj['id'], true); if ($cnt > 10) { break; } } $HotelClient->processAsyncRequests(); foreach ($query as $hotelId => $responseId) { if (isset($HotelClient->requests[$responseId]['result'])) { if (isset($HotelClient->requests[$responseId]['result']->latitude, $HotelClient->requests[$responseId]['result']->longitude) && $HotelClient->requests[$responseId]['result']->latitude && $HotelClient->requests[$responseId]['result']->longitude) { $haveCoordinates = true; $possibleLatitude = $HotelClient->requests[$responseId]['result']->latitude; $possibleLongitude = $HotelClient->requests[$responseId]['result']->longitude; break; } } } $cityCriteria = new CityFindCriteria(); $cityCriteria->paramValues = array('countryCode' => $country->code, 'nameEn' => $hotelCity['nameEn'], 'metaphoneRu' => $hotelCity['metaphoneRu'], 'soundexEn' => $hotelCity['sondexEn']); //$prevCriteria = null; //$prevCount = 0; $currCriteria = null; $count = 0; $findEnd = false; $needSave = false; while (!$findEnd) { $prevCriteria = $currCriteria; $prevCount = $count; $currCriteria = $cityCriteria->getCriteria(); $count = GeoNames::model()->count($currCriteria); $findGeo = null; echo "Params: " . implode(',', $cityCriteria->paramUsed) . ' count:' . $count . "\n"; if ($haveCoordinates && $count < 15) { $geoNames = GeoNames::model()->findAll($currCriteria); foreach ($geoNames as $geoName) { if ($geoName->latitude && $geoName->longitude) { $distance = intval(UtilsHelper::calculateTheDistance($geoName->latitude, $geoName->longitude, $possibleLatitude, $possibleLongitude)); if ($distance < 10000) { $findGeo = $geoName; $count = 1; } } } } if ($count > 1) { $findEnd = !$cityCriteria->setPlus(); } elseif ($count < 1) { $findEnd = !$cityCriteria->setMinus(); } else { $findEnd = true; } } if ($count < 1) { if ($count < $prevCount) { $currCriteria = $prevCriteria; $count = $prevCount; $needSave = true; } } else { $needSave = true; } if ($needSave) { if ($count > 6) { echo "Many results for city {$hotelCity['nameEn']} - {$count}\n"; $manyResult++; fwrite($outfp, "{$hotelCity['nameEn']}|{$hotelCity['nameRu']}|{$hotelCity['id']}|{$count}\n"); } elseif ($count > 1) { //echo "Many results for city {$hotelCity['nameEn']} - $count\n"; $geoName = GeoNames::model()->find($currCriteria); echo "Possible by city name city {$hotelCity['nameEn']} City: {$geoName->nameEn} Ru: {$geoName->nameRu} IATA: {$geoName->iataCode} coords: {$geoName->longitude} {$geoName->latitude}\n"; $someResult++; fwrite($outfp, "{$hotelCity['nameEn']}|{$hotelCity['nameRu']}|{$hotelCity['id']}|{$count}\n"); } else { if ($findGeo) { $geoName = $findGeo; } else { $geoName = GeoNames::model()->find($currCriteria); } echo "Found by city name city {$hotelCity['nameEn']} City: {$geoName->nameEn} Ru: {$geoName->nameRu} IATA: {$geoName->iataCode} coords: {$geoName->longitude} {$geoName->latitude}" . ($findGeo ? " ByCoords" : "") . "\n"; if ($geoName->iataCode) { $city = City::model()->findByAttributes(array('code' => $geoName->iataCode, 'countryId' => $country->id)); if (!$city) { $city = new City(); $city->localEn = $geoName->nameEn; $city->localRu = $geoName->nameRu; $city->countryId = $country->id; $city->code = $geoName->iataCode; } $city->latitude = $geoName->latitude; $city->longitude = $geoName->longitude; $city->metaphoneRu = $geoName->metaphoneRu; $city->hotelbookId = $hotelCity['id']; if ($geoName->stateCode) { $city->stateCode = $geoName->stateCode; } $city->save(); } else { $city = City::model()->findByAttributes(array('localEn' => $geoName->nameEn, 'localRu' => $geoName->nameRu, 'countryId' => $country->id)); if (!$city) { $city = new City(); $city->localEn = $geoName->nameEn; $city->localRu = $geoName->nameRu; $city->countryId = $country->id; $city->code = $geoName->iataCode; } $city->latitude = $geoName->latitude; $city->longitude = $geoName->longitude; $city->metaphoneRu = $geoName->metaphoneRu; $city->hotelbookId = $hotelCity['id']; if ($geoName->stateCode) { $city->stateCode = $geoName->stateCode; } $city->save(); } $oneResult++; } } else { echo "Dont found anything for city {$hotelCity['nameEn']}\n"; $noResult++; fwrite($outfp, "{$hotelCity['nameEn']}|{$hotelCity['nameRu']}|{$hotelCity['id']}|{$count}\n"); } //$criteria = new EMongoCriteria(array('conditions'=>array('countryCode'=>array('equals'=>$country->code)) )); //$criteria->limit(10); //$geoNames = GeoNames::model()->findAll($criteria); } echo "NoResults:{$noResult} OneResult:{$oneResult} SomeResults:{$someResult} ManyResults: {$manyResult}\n"; fclose($outfp); //break; } } if ($type == 'iataCode') { $criteria = new CDbCriteria(); $criteria->condition = 'hotelbookId IS NOT NULL'; $path = Yii::getPathOfAlias('application.runtime'); //$criteria->params=array(':postID'=>10); $countries = Country::model()->findAll($criteria); $start = false; foreach ($countries as $country) { if (!$start) { /* if($country->code == 'RU') { $start = true; }else{ continue; }/**/ /*if($country->code == 'US') { continue; }/**/ } $criteriaCity = new CDbCriteria(); $criteriaCity->addCondition('code IS NOT NULL'); $criteriaCity->addCondition('countryId=' . $country->id); $path = Yii::getPathOfAlias('application.runtime'); //$criteria->params=array(':postID'=>10); $countCities = City::model()->count($criteriaCity); echo "Start parsing for country {$country->code} {$countCities} results\n"; $pageLimit = 20; $n = ceil($countCities / $pageLimit); $criteriaCity->limit = $pageLimit; $oneResult = 0; $modifyCount = 0; $noResult = 0; $lineCount = 0; $outfp = fopen($path . '/' . $country->code . '-iata-log.txt', 'w'); if (!$outfp) { echo "Cant open file " . $path . '/' . $country->code . "-hotel-log.txt for writing\n"; die; } for ($i = 0; $i < $n; $i++) { $criteriaCity->offset = $i * $pageLimit; //print_r($criteriaCity); //echo "\n"; $cities = City::model()->findAll($criteriaCity); foreach ($cities as $city) { $lineCount++; if (UtilsHelper::countRussianCharacters($city->localRu)) { $nameRu = $city->localRu; } else { if (in_array($country->code, self::$sng)) { $nameRu = UtilsHelper::fromTranslite($city->localEn); } else { $nameRu = UtilsHelper::ruTranscript($city->localEn); } } $metaphoneRu = UtilsHelper::ruMetaphone($nameRu); $sondexEn = UtilsHelper::soundex($city->localEn); $cityCriteria = new CityFindCriteria(); $cityCriteria->states = array('value' => array('iata')); $cityCriteria->states[0] = array('value' => array('nameEn')); $cityCriteria->states[1] = array('value' => array('iata', 'nameEn')); $cityCriteria->states[1][0] = array('value' => array('iata', 'metaphoneRu')); $cityCriteria->states[1][1] = array('value' => array('iata', 'nameEn', 'metaphoneRu')); $cityCriteria->states[0][1] = array('value' => array('nameEn', 'metaphoneRu')); $cityCriteria->states[0][0] = array('value' => array('metaphoneRu')); $cityCriteria->paramUsed = $cityCriteria->states['value']; $cityCriteria->paramValues = array('countryCode' => $country->code, 'nameEn' => $city->localEn, 'metaphoneRu' => $metaphoneRu, 'soundexEn' => $sondexEn, 'iata' => $city->code); $currCriteria = null; $count = 0; $findEnd = false; while (!$findEnd) { //$prevCriteria = $currCriteria; //$prevCount = $count; $currCriteria = $cityCriteria->getCriteria(); $count = GeoNames::model()->count($currCriteria); //echo "Params: ".implode(',',$cityCriteria->paramUsed).' count:'.$count."\n"; if ($count > 1) { $findEnd = !$cityCriteria->setPlus(); } elseif ($count < 1) { $findEnd = !$cityCriteria->setMinus(); } else { $findEnd = true; } } if ($count == 1) { $oneResult++; $geoName = GeoNames::model()->find($currCriteria); $needSave = false; if (!$city->latitude) { $city->latitude = $geoName->latitude; $city->longitude = $geoName->longitude; $needSave = true; } if (!UtilsHelper::countRussianCharacters($city->localRu)) { $city->localRu = $geoName->nameRu; $needSave = true; } if (!$city->metaphoneRu) { $city->metaphoneRu = $geoName->metaphoneRu; $needSave = true; } if (!$city->stateCode) { $city->stateCode = $geoName->stateCode; $needSave = true; } if ($needSave) { $modifyCount++; $city->save(); } } else { $noResult++; fwrite($outfp, "{$city->localEn}|{$city->code}|{$city->id}|{$count}\n"); } if ($lineCount % 30000 == 0) { echo "NoResults:{$noResult} OneResult:{$oneResult}\n"; } } } echo "Total NoResults:{$noResult} OneResult:{$oneResult} ModifyCount: {$modifyCount} line count: {$lineCount}\n"; fclose($outfp); //break; } } if ($type == 'updateMetaphone') { $criteria = new CDbCriteria(); $criteria->condition = 'hotelbookId IS NOT NULL'; //$criteria->params=array(':postID'=>10); $countries = Country::model()->findAll($criteria); $start = false; foreach ($countries as $country) { if (!$start) { if ($country->code == 'UA') { $start = true; } else { continue; } } echo 'Update ' . $country->code . " metaphone\n"; $criteria = new EMongoCriteria(array('conditions' => array('countryCode' => array('equals' => $country->code)))); //$criteria->limit(10); $geoNames = GeoNames::model()->findAll($criteria); $k = 0; foreach ($geoNames as $geoName) { $geoName->metaphoneRu = UtilsHelper::ruMetaphone($geoName->nameRu); $geoName->save(); $k++; if ($k % 30000 == 0) { echo "Updated {$k} lines\n"; } } echo "{$country->code} complete. Updated {$k} lines\n"; //break; } //$criteria = new EMongoCriteria(array('conditions'=>array('countryCode'=>array('equals'=>$country),'metaphoneRu'=>array('equals'=>$metaphoneRu)) )); //VarDumper::dump(GeoNames::model()->find($criteria)); } }
public function checkValid() { $hotelBookClient = new HotelBookClient(); return $hotelBookClient->checkHotel($this->hotel); }
public static function injectAdditionalInfo(&$element) { Yii::import('site.common.modules.hotel.models.*'); $hotelClient = new HotelBookClient(); $element['isFlight'] = isset($element['flightKey']); $element['isHotel'] = !isset($element['flightKey']); if ($element['isHotel']) { $element['hotelDetails'] = $hotelClient->hotelDetail($element['hotelId']); } if ($element['isFlight']) { $elements = FlightManager::injectForBe(array($element), $element['searchParams']); $element = $elements[0]; } }
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/'); } }
public function actionRTFlight($countryCode = '', $cityCodeFrom = '', $cityCodeTo = '') { if (!($country = $this->testCountry($countryCode))) { return false; } $this->morphy = Yii::app()->morphy; $countryUp = mb_strtoupper($country->localRu, 'utf-8'); $countryMorph = array('caseAcc' => $this->getCase($countryUp, 'ВН')); if (!$cityCodeFrom) { $currentCity = City::getCityByCode('LED'); } else { $currentCity = City::getCityByCode($cityCodeFrom); } $city = City::getCityByCode($cityCodeTo); $citiesFrom = array(); $this->addCityFrom($citiesFrom, 4466); // Moscow $this->addCityFrom($citiesFrom, 5185); // Spb $this->addCityFrom($citiesFrom, $currentCity->id); Yii::import('site.common.modules.hotel.models.*'); $hotelClient = new HotelBookClient(); /*$criteria = new CDbCriteria(); $criteria->addCondition('countAirports > 0'); $criteria->addCondition('countryId = '.$country->id); $cities = City::model()->findAll($criteria); $cityIds = array(); foreach($cities as $city){ $cityIds[$city->id] = $city->id; } if(isset($cityIds[$currentCity->id])){ unset($cityIds[$currentCity->id]); }*/ $criteria = new CDbCriteria(); $criteria->addCondition('`to` = ' . $city->id); $criteria->addCondition('`from` = ' . $currentCity->id); //$criteria->group = 'dateBack'; //$criteria->addCondition('`from` = '.$currentCity->id); $criteria->addCondition('`dateFrom` >= ' . date("'Y-m-d'")); $criteria->addCondition('`dateFrom` <= ' . date("'Y-m-d'", time() + 3600 * 24 * 18)); $criteria->addCondition('`dateBack` >= ' . date("'Y-m-d'")); $criteria->addCondition('`dateBack` <= ' . date("'Y-m-d'", time() + 3600 * 24 * 18)); //$criteria->addCondition("`dateBack` <> '0000-00-00'"); $criteria->order = 'priceBestPrice'; //$criteria->limit = 18; $flightCache = FlightCache::model()->findAll($criteria); /*$sortFc = array(); foreach($flightCache as $fc){ $k = strtotime($fc->dateFrom); $sortFc[$k] = $fc;//array('price'=>$fc->priceBestPrice,'date'=>$fc->dateFrom,'dateBack'=>$fc->dateBack); } ksort($sortFc);*/ //$sortFc = array_slice($sortFc,0,18); $minPrice = false; $maxPrice = false; $activeMin = null; $activeMax = null; foreach ($flightCache as $k => $fc) { $k = strtotime($fc->dateFrom); if (!$minPrice) { $minPrice = $fc->priceBestPrice; $maxPrice = $fc->priceBestPrice; } else { if ($fc->priceBestPrice < $minPrice) { $minPrice = $fc->priceBestPrice; $activeMin = $k; } if ($fc->priceBestPrice > $maxPrice) { $maxPrice = $fc->priceBestPrice; $activeMax = $k; } } } $sortFc = array(); foreach ($flightCache as $fc) { //$k = strtotime($fc->dateFrom); $sortFc[] = array('price' => $fc->priceBestPrice, 'date' => $fc->dateFrom, 'dateBack' => $fc->dateBack); } //print_r($flightCache);die(); $criteria = new CDbCriteria(); //$criteria->addInCondition('`cityId`',$cityIds); $criteria->addCondition('cityId = ' . $city->id); $criteria->limit = 15; $hotelCache = HotelDb::model()->findAll($criteria); $hotelsInfo = array(); foreach ($hotelCache as $hc) { $hotelInfo = $hotelClient->hotelDetail($hc->id); $hotelInfo->price = $hc->minPrice; $hotelInfo->hotelName = $hc->name; $hotelInfo->hotelId = $hc->id; $hotelsInfo[] = $hotelInfo; } $criteria = new CDbCriteria(); //$criteria->addInCondition('`to`',$cityIds); $criteria->addCondition('`from` = ' . $currentCity->id); $criteria->addCondition('`dateFrom` > \'' . date('Y-m-d') . "'"); $criteria->order = 'priceBestPrice'; $criteria->limit = 14; $criteria->group = '`to`'; $flightCacheFromCurrent = FlightCache::model()->findAll($criteria); $this->layout = 'static'; //$this->render('landing'); $this->render('rtflight', array('city' => $city, 'citiesFrom' => $citiesFrom, 'hotelsInfo' => $hotelsInfo, 'currentCity' => $currentCity, 'flightCache' => $sortFc, 'maxPrice' => $maxPrice, 'minPrice' => $minPrice, 'activeMin' => $activeMin, 'flightCacheFromCurrent' => $flightCacheFromCurrent)); }
public function getIsValid() { $request = new HotelBookClient(); return $request->checkHotel($this); }