Ejemplo n.º 1
0
 public function run($isTab = false)
 {
     /** @var TourBuilderForm $tourForm */
     $tourForm = Yii::app()->user->getState('tourForm');
     $eventId = $tourForm->eventId;
     $startCities = Yii::app()->user->getState('startCities');
     $currentStartCityIndex = Yii::app()->user->getState('startCitiesIndex') - 1;
     $currentStartCity = City::model()->findByPk($startCities[$currentStartCityIndex]->id);
     $startCityId = $currentStartCity->id;
     $event = Event::model()->findByPk($eventId);
     $tripStorage = new TripStorage();
     $order = $tripStorage->saveOrder($event, $startCityId, 'Тур для события "' . $event->title . '" из ' . $currentStartCity->caseGen);
     $eventOrder = new EventOrder();
     $eventOrder->startCityId = $startCityId;
     $eventOrder->orderId = $order->id;
     $eventOrder->eventId = $event->id;
     $eventOrder->save();
     $eventPrice = EventPrice::model()->findByAttributes(array('eventId' => $eventId, 'cityId' => $startCityId));
     if (!$eventPrice) {
         $eventPrice = new EventPrice();
     }
     $eventPrice->eventId = $event->id;
     $eventPrice->cityId = $startCityId;
     $eventPrice->bestPrice = $tripStorage->getPrice();
     if (!$eventPrice->save()) {
         throw new CHttpException('Could not save price for event - city.' . CVarDumper::dumpAsString($eventPrice));
     }
     $this->controller->redirect($this->controller->createUrl('showEventTrip'));
 }
Ejemplo n.º 2
0
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     if (empty($params['language']) && Yii::app()->language !== 'ru') {
         $params['language'] = Yii::app()->language;
     }
     if (!isset(Yii::app()->controller->module->id)) {
         if (!strstr($route, 'register')) {
             if (isset($_POST['city'])) {
                 $cookie = new CHttpCookie('city', $_POST['city']);
                 Yii::app()->request->cookies['city'] = $cookie;
                 $cookie->expire = time() + 3600;
                 $c = City::model()->localized('ru')->findByPk($_POST['city'])->name;
                 $params['city'] = Settings::toLatin($c);
             } elseif (isset(Yii::app()->request->cookies['city'])) {
                 $c = City::model()->localized('ru')->findByPk(Yii::app()->request->cookies['city']->value)->name;
                 $params['city'] = Settings::toLatin($c);
             } else {
                 unset($params['city']);
             }
         } else {
             unset($params['city']);
         }
     }
     /*if (!strstr($route,'/')) {
           $route = '/cat/'.$route;
       }*/
     return Yii::app()->request->hostInfo . parent::createUrl($route, $params, $ampersand);
 }
Ejemplo n.º 3
0
 public function actionMore()
 {
     Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/enjoy.css');
     $city_id = Yii::app()->request->getQuery('city', 0);
     $time_sort = Yii::app()->request->getQuery('time_sort', 'DESC');
     $price_sort = Yii::app()->request->getQuery('lp_dol');
     $criteria = new CDbCriteria();
     $criteria->order = 'id DESC';
     if (!empty($city_id)) {
         $criteria->addCondition('city_id=' . $city_id);
     }
     if (!empty($time_sort)) {
         $criteria->order = 'accessDate ' . $time_sort;
     }
     if (!empty($price_sort)) {
         $criteria->order = 'lp_dol ' . $price_sort;
     }
     $criteria->addCondition('lp_dol>3000000');
     $count = House::model()->count($criteria);
     $pager = new CPagination($count);
     $pager->pageSize = 10;
     $pager->applyLimit($criteria);
     $house_list = House::model()->findAll($criteria);
     $subject_list = Subject::model()->findAll(array('order' => 'id DESC'));
     $cur_city = City::model()->findByPk($city_id);
     $data = array('house_list' => $house_list, 'subject_list' => $subject_list, 'cur_city' => $cur_city, 'count' => $count, 'time_sort' => $time_sort, 'price_sort' => $price_sort, 'pages' => $pager);
     $this->render('more', $data);
 }
Ejemplo n.º 4
0
 public function process($fh)
 {
     // skip und check header
     $line = trim(fgets($fh));
     if ($line != "rating,name,locality,url,country,name_alt,address,lat,lng,postal,address_ext") {
         $this->logError("Wrong fingerprint \n");
         echo $this->getHelp();
         Yii::app()->end();
     }
     while (!feof($fh)) {
         $data = fgetcsv($fh);
         if ($data !== false) {
             $rating = $this->parseRating($data[0]);
             //! Use english for canonical names
             $name = $data[5] == "" ? $data[1] : $data[5];
             //mihan007: just minor thing.. what is 5 and 1? don't like magic numbers.
             $cityName = $data[2];
             $city = City::model()->guess($cityName);
             if (count($city) == 0) {
                 $this->logError("Problem mapping city " . $data[2]);
                 continue;
             }
             $city = $city[0];
             $canonicalName = UtilsHelper::canonizeHotelName($name, $city->localEn);
             $this->saveRow($city->id, $canonicalName, $rating, $name);
         }
     }
 }
Ejemplo n.º 5
0
 public function run()
 {
     $country = Country::model()->findAll(['order' => 'country_order']);
     $region = Regions::model()->findAllByAttributes(['id_country' => $this->model['countries']]);
     $city = City::model()->findAllByAttributes(['id_region' => $this->model['region']]);
     $this->render('main', ['model' => $this->model, 'title' => $this->title, 'prefix_name' => $this->prefixName, 'country' => $country, 'region' => $region, 'city' => $city]);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return City the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = City::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 7
0
 public function run()
 {
     $city = City::model()->findAll();
     $type = InvestType::model()->findAll();
     $aim = InvestAim::model()->findAll();
     $data = array('city' => $city, 'type' => $type, 'aim' => $aim);
     $this->render('evaluate', $data);
 }
Ejemplo n.º 8
0
 public function run($args)
 {
     $cities = City::model()->findAll("hotelbookid IS NOT NULL");
     foreach ($cities as $city) {
         echo $city->localEn;
         echo "\n";
     }
 }
Ejemplo n.º 9
0
 public function setCityName($value)
 {
     $items = CityManager::getCities($value);
     if (isset($items[0])) {
         $this->cityModel = City::model()->findByPk($items[0]['id']);
     } else {
         throw new CException('Cannot define city by city name:' . $value);
     }
 }
Ejemplo n.º 10
0
 private function generateHotelDescription(OrderHotel $hotel)
 {
     $city = City::model()->findByPk($hotel->cityId);
     $hotel = @unserialize($hotel->object);
     if (is_object($hotel)) {
         $description = 'Отель ' . $hotel->hotelName . ' в ' . $city->casePre;
     } else {
         $description = 'Отель в ' . $city->casePre;
     }
     return $description;
 }
Ejemplo n.º 11
0
 public function beforeAction($action)
 {
     $domain = Yii::app()->request->getParam('city');
     if ($domain) {
         $this->city = City::model()->withUrl($domain)->find();
     }
     if (!$this->city) {
         //	$this->redirect('http://'.Yii::app()->params['serverName']);
     }
     return true;
 }
Ejemplo n.º 12
0
 public static function saveProAddress(UserProudctAddress $userprodaddress, $user_id)
 {
     $_POST['UserProudctAddress']['province'] = 'xx';
     $_POST['UserProudctAddress']['city'] = 'xx';
     $_POST['UserProudctAddress']['area'] = 'xx';
     $_POST['UserProudctAddress']['sysaddress'] = 'xx';
     if (isset($_POST['province'])) {
         $_POST['UserProudctAddress']['province'] = $_POST['province'];
         $provincename = Province::model()->find("provinceID=:proid", array(":proid" => $_POST['UserProudctAddress']['province']));
         if ($provincename) {
             $_POST['UserProudctAddress']['sysaddress'] = $provincename->province;
         }
     }
     if (isset($_POST['city'])) {
         $_POST['UserProudctAddress']['city'] = $_POST['city'];
         $cityname = City::model()->find("cityID=:cityid", array(":cityid" => $_POST['UserProudctAddress']['city']));
         if ($cityname) {
             $_POST['UserProudctAddress']['sysaddress'] .= $cityname->city;
         }
     }
     if (isset($_POST['area'])) {
         $_POST['UserProudctAddress']['area'] = $_POST['area'];
         $areaname = Area::model()->find("areaID=:areaid", array(":areaid" => $_POST['UserProudctAddress']['area']));
         if ($areaname) {
             $_POST['UserProudctAddress']['sysaddress'] .= $areaname->area;
         }
     }
     $_POST['UserProudctAddress']['user_id'] = $user_id;
     $userprodaddress->setAttributes($_POST['UserProudctAddress']);
     foreach ((array) $_POST['UserProudctAddress'] as $key => $value) {
         if (trim($value) == '') {
             $userprodaddress->addError($key, "字段不能为空");
             break;
         }
     }
     if (!$userprodaddress->getErrors()) {
         $userprodaddress->setAttribute('addtime', time());
         $userprodaddress->setAttribute('addip', Yii::app()->request->userHostAddress);
         if ($userprodaddress->validate()) {
             if ($userprodaddress->isNewRecord) {
                 $result = $userprodaddress->save();
             } else {
                 $result = $userprodaddress->update();
             }
             if (!$result) {
                 $userprodaddress->addError("realname", "更新失败");
             }
         } else {
             $userprodaddress->addError("realname", "更新失败");
         }
     }
     return $userprodaddress;
 }
Ejemplo n.º 13
0
 public function duplicatedName($attribute, $params)
 {
     if ($this->isNewRecord) {
         if (count(City::model()->findAll('name=:name and department_id=:department_id', array("name" => $this->name, "department_id" => $this->department_id))) > 0) {
             $this->addError($attribute, "Ya existe una ciudad la ciudad {$this->name} en el departamento seleccionado");
         }
     } else {
         if (count(City::model()->findAll('id <> :id and name=:name and department_id=:department_id', array("name" => $this->name, "department_id" => $this->department_id, "id" => $this->id))) > 0) {
             $this->addError($attribute, "Ya existe una ciudad la ciudad {$this->name} en el departamento seleccionado");
         }
     }
 }
Ejemplo n.º 14
0
 public function beforeDelete()
 {
     $city = City::model()->findAll();
     foreach ($city as $id => $item) {
         $citys = explode('|', $item->state_id);
         if (in_array($this->state_id, array_values($citys))) {
             Yii::app()->setFlashMessage('Can not delete, State in use in city master', 'error');
             return false;
         }
     }
     return parent::beforeDelete();
 }
 private function ifCityUndefined($userStep, $cityName)
 {
     if (City::model()->cityNotExist($cityName)) {
         if (!WikiUtils::checkCityByWiki($cityName) && !WikiUtils::checkCityByWiki($cityName . "_(город)")) {
             $userStep->error = GameUtils::ERROR_CITY_UNDEFINED;
             return true;
         }
         $city = new City();
         $city->name = $cityName;
         $city->save();
         return false;
     }
 }
Ejemplo n.º 16
0
Archivo: City.php Proyecto: righ22/Xata
 public static function check($_cpt, $_cntry)
 {
     $city = City::model()->find('country_id=:cntry AND caption=:cpt', array(':cntry' => $_cntry, ':cpt' => $_cpt));
     if ($city !== null) {
         return $city->getPrimaryKey();
     }
     $city = new City();
     $city->attributes = array('caption' => $_cpt, 'country_id' => $_cntry);
     if ($city->save()) {
         return $city->getPrimaryKey();
     }
     return false;
 }
Ejemplo n.º 17
0
 public function actionCity()
 {
     $term = \Yii::app()->request->getQuery('term');
     $criteria = new \CDbCriteria();
     $criteria->limit = 10;
     $criteria->addSearchCondition('ru_name', $term . '%', false);
     $criteria->order = 'ru_name DESC';
     $cities = \City::model()->findAll($criteria);
     $lists = array();
     foreach ($cities as $city) {
         $lists[] = ['code' => $city->geonameid, 'value' => $city->ru_name];
     }
     echo json_encode($lists);
 }
Ejemplo n.º 18
0
 public function actionIndex()
 {
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->order = 'name ASC';
     $this->pages = new CPagination(City::model()->count($criteria));
     $this->pages->pageSize = 50;
     $this->pages->applyLimit($criteria);
     $this->pages->route = "/city";
     $this->pages->params = array();
     $this->offset = $this->pages->getOffset();
     $this->allRec = City::model()->findAll($criteria);
     $this->render('index');
 }
 public function actionloadConcessioner()
 {
     $city = City::model()->findByPk($_POST['city_id']);
     $return = array();
     foreach ($city->concessioners as $z => $concessioner) {
         if ($concessioner->id != 3 && $concessioner->id != 4 && $concessioner->id != 14) {
             $return[$z]['id'] = $concessioner->id;
             $return[$z]['name'] = $concessioner->name;
             $return[$z]['address'] = $concessioner->address;
             $return[$z]['phone'] = $concessioner->phone;
         }
     }
     echo json_encode($return);
 }
Ejemplo n.º 20
0
 public function generateItems()
 {
     Yii::app()->user->setState('lastSearches', null);
     $elements = Yii::app()->user->getState('lastSearches');
     $items = array();
     if (!is_array($elements)) {
         return $items;
     }
     foreach ($elements as $element) {
         $item = array('label' => City::model()->getCityByPk($element[0])->localRu . '&nbsp;&rarr;&nbsp;' . City::model()->getCityByPk($element[1])->localRu . '<br>(' . $element[2] . ')', 'url' => '/admin/booking/flight/search/from/' . $element[0] . '/to/' . $element[1] . '/date/' . $element[2], 'encodeLabel' => false);
         $items[] = $item;
     }
     return $items;
 }
 /**
  * Ajax-подгрузка городов в список
  */
 public function actionAjaxGetPlaces($term, $key = 'id')
 {
     if (Yii::app()->request->isAjaxRequest) {
         $criteria = new CDbCriteria();
         $criteria->addSearchCondition('t.city', $term . '%', false);
         $criteria->order = 't.city';
         $cities = City::model()->findAll($criteria);
         $data = array();
         foreach ($cities as $city) {
             $data[] = array($key => $city->id, 'text' => $city->fullTitle);
         }
         echo CJSON::encode($data);
         Yii::app()->end();
     }
 }
Ejemplo n.º 22
0
 protected function validateAttribute($object, $attribute)
 {
     $name = trim($object->{$attribute});
     if (!empty($name)) {
         if (!is_numeric($name)) {
             $city = City::model()->findByAttributes(array('name' => $name));
             if ($city) {
                 $object->{$attribute} = $city->id;
             } else {
                 $this->addError($object, $attribute, 'Город не найден');
             }
         }
     } else {
         $object->{$attribute} = null;
     }
 }
Ejemplo n.º 23
0
 public function city($attr)
 {
     $name = trim($this->{$attr});
     if (!empty($name)) {
         if (!is_numeric($name)) {
             $city = City::model()->findByAttributes(array('name' => $name));
             if ($city) {
                 $this->{$attr} = $city->id;
             } else {
                 $this->addError($attr, Yii::t('main', 'Город не найден'));
             }
         }
     } else {
         $this->{$attr} = null;
     }
 }
Ejemplo n.º 24
0
 /**
  * Shows an event with full information
  */
 public function actionEvent()
 {
     $eventFound = false;
     $request = Yii::app()->getRequest();
     $eventId = $request->getParam('id', null);
     if ($eventId !== null && is_numeric($eventId)) {
         $event = Event::model()->find('id = :id', array(':id' => $eventId));
         if ($event !== null) {
             $this->render('event', array('event' => $event, 'objCities' => City::model()->findAll()));
             $eventFound = true;
         }
     }
     if (!$eventFound) {
         $this->redirect('/site/search');
     }
 }
Ejemplo n.º 25
0
 public static function compAnswer()
 {
     $answer = array();
     $lastLetter = Gamestep::model()->getLastLetter();
     //запрос, все выбранные города помещаются в массив $potentialAnswers
     $potentialAnswers = City::model()->findPossibleCities($lastLetter);
     //найти в $potentialAnswers город, еще не использованный в игре
     $firstCityIsNotInGame = self::findCityIsNotInGame($potentialAnswers);
     //сделать ход, или сдаться
     if ($firstCityIsNotInGame == -1) {
         $answer['message'] = self::COMP_LOSER;
     } else {
         $answer['city'] = $firstCityIsNotInGame;
     }
     return $answer;
 }
Ejemplo n.º 26
0
 /**
  *用户有可能输入四种情况:
  * 1.景点名
  * 2.城市名
  * 3.国家名
  * 4.省的名字
  * 5.一个数据库没有的名字
  * 6.要从行政数据库里面查找名字
  */
 public function authenticate($location)
 {
     //先判断这是否是一个景点名
     if ($this->find('name=:name', array(':name' => $location))) {
         return $this->_flag = self::SECENIC;
     } else {
         if (City::model()->loadModel($location)) {
             return $this->_flag = self::CITY;
         } else {
             if (Province::model()->loadModel($location)) {
                 return $this->_flag = self::PROVINCE;
             } else {
                 return $this->_flag = self::INVAILD;
             }
         }
     }
 }
Ejemplo n.º 27
0
public function actionFile($id){

        $id   = (int)$id;
        $model = City::model()->findByPk($id); 
        if(!$model)
            throw new CHttpException(404, Yii::t('site','Page not found'));

       // if(Yii::app()->user->isGuest && $model->issue->is_public !== true)
       //     Yii::app()->user->loginRequired();

        $available_mime = Yii::app()->params['mime_fileview'];

        $filename = $model->filename;
        $realname = $model->realname;

        $uploadPath = $model->getFileFolder();    

        if(file_exists($uploadPath.$filename )) {

            $type = CFileHelper::getMimeType($uploadPath.$filename); // get yii framework mime
            
            if(in_array($type, $available_mime)){

                //.. get the content of the requested file 
                $content=file_get_contents($uploadPath.$filename);
                //.. send appropriate headers
                header('Content-Type:' . $type);
                header("Content-Length: ". filesize($uploadPath.$filename));

                header('Content-Disposition: inline; filename="' . $realname . '"');
                header('Content-Transfer-Encoding: binary');
                header('Accept-Ranges: bytes');

                echo $content;
                exit; 
                
            } else {
                throw new CHttpException(404, Yii::t('site','Page not found'));
            }
        }
        else{
            throw new CHttpException(404, Yii::t('site','Page not found'));
        }   

    }
 /**
  * @param string|null $cityName
  * @param string|null $countryName
  */
 public function actionGetInfoForByCityName($cityName = null, $countryName = null)
 {
     $criteria = new CDbCriteria();
     if ($cityName) {
         $criteria->join = 'RIGHT JOIN ' . Country::tableName() . ' country ON country.id_country=t.id_country';
         $criteria->condition = 't.city_name_ru = :city AND country.country_name_ru = :country';
         $criteria->params = array(':city' => $cityName, ':country' => $countryName);
         $model = City::model()->find($criteria);
         echo json_encode(array('id_country' => $model->id_country, 'id_region' => $model->id_region, 'id_city' => $model->id_city));
     } else {
         if ($countryName) {
             $criteria->condition = 'country_name_ru = :country';
             $criteria->params = array(':country' => $countryName);
             $model = Country::model()->find($criteria);
             echo json_encode(array('id_country' => $model->id_country, 'id_region' => 0, 'id_city' => 0));
         }
     }
 }
Ejemplo n.º 29
0
 public static function getCityInRadius($geonameid, $radKm)
 {
     $gradus = $radKm / 111.144;
     $City = City::model()->findByPk($geonameid);
     $criteria = new CDbCriteria();
     $criteria->addBetweenCondition('latitude', $City->latitude - $gradus, $City->latitude + $gradus);
     $criteria->addBetweenCondition('longitude', $City->longitude - $gradus, $City->longitude + $gradus);
     $criteria->select = 'geonameid,latitude,longitude';
     $result = City::model()->findAll($criteria);
     $return = [$geonameid];
     foreach ($result as $row) {
         $dist = self::getDistance($City->latitude, $City->longitude, $row['latitude'], $row['longitude']);
         if ($dist < $radKm * 1000) {
             $return[] = $row['geonameid'];
         }
     }
     return $return;
 }
Ejemplo n.º 30
0
 /**
  * @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();
     }
 }