public function getNonCurrentRegions() { if (null === $this->_nonCurrentRegions) { $this->_nonCurrentRegions = Region::model()->findAll('id != :regionId', array(':regionId' => $this->currentRegion->id)); } return $this->_nonCurrentRegions; }
public function loadRegion($id) { $model = Region::model()->findByPk($id); if (null === $model) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }
public function utcToLocal($datetime) { $region = Region::model()->findByPk(Yii::app()->session['region']); $timeZoneName = $region->time_zone; $timezone = new DateTimeZone($timeZoneName); $offset = $timezone->getOffset(new DateTime()); return strtotime($datetime) + $offset; }
public function beginRequest() { Yii::import('application.widgets.LanguageSelector'); LanguageSelector::setLanguage(); if (null === Yii::app()->session['region'] || !Region::model()->exists('id = :id', array(':id' => Yii::app()->session['region']))) { Yii::app()->session['region'] = Region::model()->getDefault()->id; assert(null !== Yii::app()->session['region']); } }
public function parseUrl($manager, $request, $pathInfo, $rawPathInfo) { $region = Region::model()->findByAttributes(array('slug' => $pathInfo)); if (null === $region) { return FALSE; } $_GET['id'] = $region->id; return 'location/map'; }
public static function getNameById($id) { if (empty(self::$nameById[$id])) { $c = Region::model()->findByPk($id); if ($c) { self::$nameById[$id] = $c->name; } } return self::$nameById[$id]; }
/** * 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 the ID of the model to be loaded */ public function loadModel($id) { if (Yii::app()->getLanguage() == "ru") { $lang = "ru"; } else { $lang = "ua"; } $model = Region::model()->findByPk(array('id' => $id, 'lang' => $lang)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * 根据id获取地区名详细数组. * @param $ids * @return bool|string */ public function getRegionInfoByIds($ids) { if (empty($ids) || !is_array($ids)) { return false; } $list = Region::model()->findAllByAttributes(array('id' => $ids)); if (empty($list)) { return false; } $data = array(); foreach ($list as $row) { $data[$row->id] = $row->getAttributes(); } return $data; }
public function actionIndex() { $this->pageTitle = Yii::t('common', '品牌中心') . SEPARATOR . Setting::getValueByCode('inside_title', true); $criteria = new CDbCriteria(); $criteria->compare('t.is_released', 1); $criteria->order = 'sort_order ASC'; $brands = Brand::model()->localized()->findAll($criteria); // 广告图 $criteria = new CDbCriteria(); $criteria->compare('t.banner_position_id', 2); $banner = Banner::model()->localized()->find($criteria); $codes = BrandI18n::model()->getFirstCode(); $this->layout = 'main'; $regions = Region::model()->getSelects(); $this->render('index', array('brands' => $brands, 'regions' => $regions, 'banner' => $banner, 'codes' => $codes)); }
public function parseUrl($manager, $request, $pathInfo, $rawPathInfo) { if (!preg_match('%^(\\w+)/resources(/(.+)s)?$%', $pathInfo, $matches)) { return FALSE; } $regionSlug = $matches[1]; $region = Region::model()->findByAttributes(array('slug' => $regionSlug)); $type = isset($matches[3]) ? $matches[3] : null; if (null === $region) { return FALSE; } $_GET['region'] = $region->id; if (null !== $type) { $_GET['type'] = $type; } return 'resource/list'; }
/** * 根据用户id获取用户的地址信息列表数组. * @param $userId * @return array|bool */ public function getUserAddressList($userId) { $map = array(); $map['user_id'] = $userId; $list = Address::model()->findAllByAttributes($map); if (empty($list)) { return false; } $newList = array(); $is_default = false; $first_key = 0; foreach ($list as $val) { $temp = $val->getAttributes(); if ($temp['is_default'] && $is_default == false) { $is_default = true; } else { $temp['is_default'] = 0; } if (!$first_key) { $first_key = $temp['id']; } $ids = array(); $ids[] = intval($val['province']); $ids[] = intval($val['city']); $ids[] = intval($val['district']); $map = array(); $map['id'] = $ids; $addList = Region::model()->findAllByAttributes($map); if (empty($addList)) { continue; } $regionList = array(); foreach ($addList as $row) { $regionList[$row['id']] = $row->getAttributes(); } $temp['province_name'] = isset($regionList[$val['province']]) ? $regionList[$val['province']]['region_name'] : ''; $temp['city_name'] = isset($regionList[$val['city']]) ? $regionList[$val['city']]['region_name'] : ''; $temp['district_name'] = isset($regionList[$val['district']]) ? $regionList[$val['district']]['region_name'] : ''; $newList[$val->id] = $temp; } if ($is_default == false && !$first_key) { $newList[$first_key]['is_default'] = 1; } return $newList; }
/** * Action to search ads by key words */ public function actionSearch($id = null, $word = null, $city_id = null, $page = null) { $criteria = new CDbCriteria(); $criteria->condition = "status='published'"; $criteria->order = 'added DESC'; $form = new EavSearchForm(); if ($id) { $category = Category::model()->findByPk($id); $childrenIds = $category ? $category->getDescendantIds() : null; if ($childrenIds) { $criteria->addInCondition('category_id', $childrenIds); } else { $criteria->addCondition('category_id=:category_id'); $criteria->params[':category_id'] = intval($id); } $form->model->attachEavSet($category->set_id); $form->eav = $form->model->getEavAttributes(); if (isset($_GET['search'])) { $form->fill(); $this->buildEavCriteria($criteria); } } if ($word) { try { $ids = $this->sphinxSearch($word); $criteria->addInCondition('t.id', $ids); } catch (Exception $e) { $criteria->addCondition('title LIKE :word1 OR description LIKE :word2'); $criteria->params[':word1'] = "%{$word}%"; $criteria->params[':word2'] = "%{$word}%"; } } if ($city_id) { $criteria->addCondition('city_id=:city_id'); $criteria->params[':city_id'] = intval($city_id); } $regions = Region::model()->getRegionList(); $dp = new EavActiveDataProvider('Ad', array('criteria' => $criteria, 'countCriteria' => array('condition' => $criteria->condition, 'params' => $criteria->params), 'pagination' => array('pageSize' => 10))); $this->render('search', array('dataProvider' => $dp, 'form' => $form, 'regions' => $regions)); }
public function parseUrl($manager, $request, $pathInfo, $rawPathInfo) { if (!preg_match('%^([\\w-]+)/([\\w-]+)?$%', $pathInfo, $matches)) { return FALSE; } $regionSlug = $matches[1]; $actionOrLocationSlug = $matches[2]; $region = Region::model()->findByAttributes(array('slug' => $regionSlug)); if (null === $region) { return FALSE; } if ('spaces' === $actionOrLocationSlug) { $_GET['id'] = $region->id; return 'location/list'; } $location = Location::model()->findByAttributes(array('slug' => $actionOrLocationSlug, 'region_id' => $region->id)); if (null === $location) { return FALSE; } $_GET['id'] = $location->id; return 'location/view'; }
public function actionFindRegion() { $q = $_GET['term']; if (isset($q)) { $lang = Yii::app()->getLanguage(); if ($lang == "uk_ua") { $lang = "ua"; } $criteria = new CDbCriteria(); $criteria->params = array(':q' => '%' . trim($q) . '%'); $criteria->condition = 'name LIKE (:q) and lang="' . $lang . '"'; $regions = Region::model()->findAll($criteria); if (!empty($regions)) { $out = array(); foreach ($regions as $p) { $out[] = array('label' => $p->name, 'value' => $p->name, 'id' => $p->id); } echo CJSON::encode($out); Yii::app()->end(); } } }
<div class="localidad col-md-12"> <input type="hidden" class="val" value="<?php echo $i; ?> "> <div class="col-md-3"> <?php echo $form->dropDownListGroup($localidad, 'region_id', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('data' => CHtml::listData(Region::model()->findAll(), 'id', 'nombre'), 'htmlOptions' => array('class' => 'region', 'name' => 'Localidad[' . $i . '][region_id]', 'prompt' => 'Seleccione Region')))); ?> </div> <div class="col-md-3"> <?php echo $form->dropDownListGroup($localidad, 'comuna_id', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('data' => CHtml::listData(Comuna::model()->findAllByAttributes(array('region_id' => $localidad->region_id), array("select" => "nombre,id")), 'id', 'nombre'), 'htmlOptions' => array('class' => 'comuna', 'name' => 'Localidad[' . $i . '][comuna_id]', 'prompt' => 'Seleccione Comuna')))); ?> </div> <div class="col-md-3"> <?php echo $form->textFieldGroup($localidad, 'direccion', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('htmlOptions' => array('name' => 'Localidad[' . $i . '][direccion]')))); ?> </div> <?php
<?php echo $form->error($model, 'pais_id'); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'region_id', array('class' => 'control-label')); ?> <div class="controls <?php echo $model->isAttributeRequired('region_id') ? 'required' : ''; ?> "> <?php echo $form->dropDownList($model, 'region_id', CHtml::listData(Region::model()->findAllByAttributes(array('pais_id' => $model->pais_id), array('order' => 'nombre ASC')), 'id', 'nombre'), array('prompt' => 'Selecciona una región', 'disabled' => is_null($model->pais_id) ? true : false)); ?> <?php echo $form->error($model, 'region_id'); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'ciudad_id', array('class' => 'control-label')); ?> <div class="controls <?php echo $model->isAttributeRequired('ciudad_id') ? 'required' : ''; ?> ">
/** * Test action * * * [username] => lianzhan [password] => lianzhan [repassword] => lianzhan [email] => lianzhan@163.com [firstname] => 连战 [lastname] => 兄弟 [birth] => 11/17/1964 [gender] => 0 [region] => 2492-2695-2701- [agree] => 1 [verifyCode] => bbuupa */ public function actionTest() { $this->layout = '//layouts/main'; $user = User::model()->find(array('order' => 'id DESC')); // UtilHelper::dump($user->profiles->attributes); $region = $user->profiles->province . '-' . $user->profiles->manicipal . '-' . $user->profiles->county . '-'; Region::model()->addForerunner($user, $region); }
public static function addNewCity($city) { $trueCity = null; if(!empty($city)){ // добавляем город $trueCity = new City; $trueCity->title = $city; $trueCity->alternative_title = $city; $address_city = $city; $params = array( 'geocode' => $address_city, // координаты 'format' => 'json', // формат ответа 'results' => 1, // количество выводимых результатов 'kind'=>'locality' // 'key' => '...', // ваш api key ); $trueRegion = $result_region = null; $response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&'))); if ($response && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0) { $result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos; if($result){ $exp_str1 = explode(" ", $result); $trueCity->latitude = $exp_str1[1]; $trueCity->longitude = $exp_str1[0]; } $result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->name; if($result){ $trueCity->title = $result; $trueCity->alternative_title = $result; } $result_region = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->metaDataProperty->GeocoderMetaData->AddressDetails->Country->AdministrativeArea->AdministrativeAreaName; if($result_region){ $trueRegion = Region::model()->find('LOWER(title)=:title',array(':title'=>MHelper::String()->toLower($result_region))); if(!$trueRegion){ $trueRegion = new Region; $trueRegion->title = $result_region; $trueRegion->save(); } } } if($trueCity->latitude) { // склонение $params = array( 'format' => 'json', // формат ответа 'name'=>$trueCity->title ); $response = CJSON::decode(@file_get_contents('http://export.yandex.ru/inflect.xml?' . http_build_query($params, '', '&'))); if ($response) { if(isset($response[2])) $trueCity->rodpad = $response[2]; if(isset($response[6])) $trueCity->mestpad = $response[6]; } if($trueRegion){ $trueCity->region = $trueRegion->id; } $trueCity->pos = 0; $trueCityCheck = City::model()->find('LOWER(title)=:title or LOWER(alternative_title)=:alternative_title',array(':title'=>MHelper::String()->toLower($trueCity->title),':alternative_title'=>MHelper::String()->toLower($trueCity->title))); if($trueCityCheck) // потому-что ввести могут что угодно, а город обозначится только после запроса к яндексу. return $trueCityCheck; if($trueCity->save()){ } else { if($trueCity->errors && isset($trueCity->errors['title'])){ if($trueCity->errors['title'][0] == 'Город с таким названием уже существует.'){ $trueCity = City::model()->find('LOWER(title)=:title or LOWER(alternative_title)=:alternative_title',array(':title'=>MHelper::String()->toLower($trueCity->title),':alternative_title'=>MHelper::String()->toLower($trueCity->title))); } } } } } return $trueCity; }
public function import($content) { $header_cols = array('name' => 0, 'school_category_id' => 1, 'level_of_education' => 2, 'post' => 3, 'postal_code' => 4, 'municipality_id' => 5, 'region_id' => 6, 'country_id' => 7); header('Content-Type: text/html; charset=utf-8'); $lines = explode("\n", $content); for ($i = 1; $i < count($lines); ++$i) { if (trim($lines[$i]) == '') { continue; } $cols = explode(";", $lines[$i]); // država $country_id = 0; $country = Country::model()->find('country=:country', array(':country' => trim($cols[$header_cols['country_id']]))); if ($country == null) { echo Yii::t('app', 'Country does not exist! Country: ') . trim($cols[$header_cols['country_id']]); die; } $country_id = $country->id; // regija $region = Region::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['region_id']]), ':country_id' => $country_id)); if ($region == null) { $region = new Region(); $region->country_id = $country_id; $region->name = trim($cols[$header_cols['region_id']]); $region->save(); } $region_id = $region->id; // občina $municipality = Municipality::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['municipality_id']]), ':country_id' => $country_id)); if ($municipality == null) { $municipality = new Municipality(); $municipality->country_id = $country_id; $municipality->name = trim($cols[$header_cols['municipality_id']]); $municipality->save(); } $municipality_id = $municipality->id; $school_name = trim($cols[$header_cols['name']]); if ($school_name[0] == '"') { $school_name = mb_substr($school_name, 1, mb_strlen($school_name, 'UTF-8') - 2, 'UTF-8'); } $school_name = str_replace('""', '"', $school_name); $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => $school_name, ':country_id' => $country_id)); if ($school == null) { $school = new School(); $school->name = $school_name; $school->country_id = $country_id; $school->municipality_id = $municipality_id; $school->region_id = $region_id; $school->post = trim($cols[$header_cols['post']]); $school->postal_code = trim($cols[$header_cols['postal_code']]); $school->school_category_id = (int) trim($cols[$header_cols['school_category_id']]); $school->level_of_education = (int) trim($cols[$header_cols['level_of_education']]); $school->save(); echo 'Imported: ', $school_name, "<br />\n"; if (count($school->errors) > 0) { print_r($school->errors); die; } } else { echo 'Already imported: ', $school_name, "<br />\n"; } } }
public static function SyncZavodiWhereKategorijaActive() { $schoolCategories = SchoolCategory::model()->findAll('active=:active', array(':active' => 1)); $kategorije = array(); $kategorija_map = array(); foreach ($schoolCategories as $schoolCategory) { $kategorije[] = $schoolCategory->name; $kategorija_map[$schoolCategory->name] = $schoolCategory->id; } echo "Current categories for sync:<br />"; pre_print($kategorije); $list = self::GetRegZavod(); if (!isset($list['return'])) { return array(); } $list = $list['return']; echo "Current schools to sync:<br />"; $country = Country::model()->find('country=:country', array(':country' => 'Slovenija')); if ($country == null) { echo "Add country Slovenija!<br />\n"; die; } $country_id = $country->id; // cache all občine $municipalities = Municipality::model()->findAll('country_id=:country_id', array(':country_id' => $country_id)); $municipality_map = array(); foreach ($municipalities as $municipality) { $municipality_map[$municipality->name] = $municipality->id; } // cache all regije $regions = Region::model()->findAll('country_id=:country_id', array(':country_id' => $country_id)); $region_map = array(); foreach ($regions as $region) { $region_map[$region->name] = $region->id; } $counter = 0; $updated = 0; $inserted = 0; for ($i = 0; $i < count($list); ++$i) { if (in_array($list[$i]['KATEGORIJA'], $kategorije)) { $counter++; $el = $list[$i]; $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => trim($el['ZAVOD_NAZIV']), ':country_id' => $country_id)); if ($school == null) { $school = new School(); $school->name = trim($el['ZAVOD_NAZIV']); $school->country_id = $country_id; $inserted++; } $school->school_category_id = $kategorija_map[trim($el['KATEGORIJA'])]; // občina if (!isset($municipality_map[trim($el['OBCINANAZIV'])])) { $municipality = new Municipality(); $municipality->name = trim($el['OBCINANAZIV']); $municipality->country_id = $country_id; $municipality->save(); $municipality_map[trim($el['OBCINANAZIV'])] = $municipality->id; } $school->municipality_id = $municipality_map[trim($el['OBCINANAZIV'])]; // regija if (!isset($region_map[trim($el['REGIJANAZIV'])])) { $region = new Region(); $region->name = trim($el['REGIJANAZIV']); $region->country_id = $country_id; $region->save(); $region_map[trim($el['REGIJANAZIV'])] = $region->id; } $school->region_id = $region_map[trim($el['REGIJANAZIV'])]; $school->post = trim($el['POSTANAZIV']); $school->postal_code = trim($el['POSTASIFRA']); $school->identifier = trim($el['ZAVPRS']); $school->headmaster = trim($el['ZAVRAVN']); if (isset($el['ZAVDAVST'])) { $school->tax_number = trim($el['ZAVDAVST']); } if ($school->save()) { $updated++; } } } echo 'Found schools to sync: ', $counter, "<br />\n"; echo 'New schools imported: ', $inserted, "<br />\n"; echo 'Updated schools: ', $updated - $inserted, "<br />\n"; }
display:inline-block; border:1px solid grey; padding:1px; margin:2px; } </style> <div id="regionContent"> <div id="regionNav"> <a href="<?php echo $this->createUrl('/region/regioninfo', array('id' => 0)); ?> " onclick="eaddress($(this));return false;">家乡</a> </div> <div id="regionNode"> <?php echo Region::model()->generateRegionLinks(0, '/region/regioninfo', array('onclick' => 'eaddress($(this));return false;')); ?> </div> <div id="regionAdd" class="row hide"> <label>新添地区</label> <input type="text" id="regionField"> <span class="button"><a href="javascript:void();" onclick="regionAdd();">提交</a></span> <a href="javascript:void();" onclick="$(this).parent().hide();">收起</a> </div> </div> <input type="hidden" id="lastInputRegion" /> <script type="text/javascript"> <!-- function eaddress(object) { var result = '';
display:inline-block; border:1px solid grey; padding:1px; margin:2px; } </style> <div id="regionContent"> <div id="regionNav"> <a href="<?php echo $this->createUrl('/archiver/euniversity'); ?> " onclick="$('#cuniversity').trigger('click');return false;">大学</a> </div> <div id="regionNode"> <?php echo Region::model()->generateRegionLinks(0, '/college/collegeinfo', array('onclick' => 'eaddress($(this));return false;'), false); ?> </div> <div id="regionAdd" class="row hide"> <label>新添学校</label> <input type="text" id="schoolField"> <span class="button"><a href="javascript:void();" onclick="collegeAdd();">提交</a></span> <a href="javascript:void();" onclick="$(this).parent().hide();">收起</a> </div> </div> <input type="hidden" id="lastInputRegion" /> <input type="hidden" id="schoolType" value="<?php echo College::COLLEGE_TYPE_PUBEN; ?> " /> <script type="text/javascript">
<?php echo $form->labelEx($model, 'country_id'); ?> <?php $data = Country::model()->GetCountriesICanEdit(); echo CHtml::activeDropDownList($model, 'country_id', CHtml::listData($data, 'id', 'country'), array('empty' => Yii::t('app', 'choose'))); echo $form->error($model, 'country_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'region_id'); ?> <?php $data = Region::model()->GetRegionsICanEdit(); echo CHtml::activeDropDownList($model, 'region_id', CHtml::listData($data, 'id', 'name'), array('empty' => Yii::t('app', 'choose'))); echo $form->error($model, 'region_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'municipality_id'); ?> <?php $data = Municipality::model()->GetMunicipalityICanEdit(); echo CHtml::activeDropDownList($model, 'municipality_id', CHtml::listData($data, 'id', 'name'), array('empty' => Yii::t('app', 'choose'))); echo $form->error($model, 'municipality_id'); ?> </div>
public function actionExport() { $model = new $this->modelName(); $photosExport = array(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'export-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST[$this->modelName])) { $model->attributes = $_POST[$this->modelName]; $arrSel = ''; if (isset($_POST[$this->modelName]['itemsSelectedExport']) && $_POST[$this->modelName]['itemsSelectedExport']) { $arrSel = explode(',', $_POST[$this->modelName]['itemsSelectedExport']); $arrSel = array_map("intval", $arrSel); } if (!$arrSel || !count($arrSel)) { Yii::app()->user->setFlash('error', tt('Please select ads for export.')); $this->redirect('viewExport'); } else { $backUrl = $this->createUrl('viewExport', array($this->modelName . '_sel' => $arrSel)); $isZip = isset($_POST[$this->modelName]['isZip']) ? $_POST[$this->modelName]['isZip'] : 0; $fileName = date('Y_m_d_s') . rand(0, 9) . '_export.csv'; $filePath = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; $fileLine = array(); $fileLine[0] = $this->mask; $i = 1; foreach ($arrSel as $v) { // get needed info $apartment = Apartment::model()->cache(param('cachingTime', 1209600), Apartment::getFullDependency($v))->with('windowTo', 'images')->findByPk($v); // set values $type = $apartment->type; $priceType = $apartment->price_type; $objType = $apartment->obj_type_id; $countryName = $regionName = $cityName = ''; if (issetModule('location')) { // country if (isFree()) { if ($apartment->loc_country) { $countryInfo = Country::model()->findByPk($apartment->loc_country); if ($countryInfo && isset($countryInfo->name)) { $countryName = $countryInfo->name; } } } else { if ($apartment->loc_country) { Yii::app()->setLanguage($this->defLang); $countryInfo = Country::model()->findByPk($apartment->loc_country); if ($countryInfo && isset($countryInfo->name)) { $countryName = $countryInfo->name; } Yii::app()->setLanguage($this->currLang); } } // region if (isFree()) { if ($apartment->loc_region) { $regionInfo = Region::model()->findByPk($apartment->loc_region); if ($regionInfo && isset($regionInfo->name)) { $regionName = $regionInfo->name; } } } else { if ($apartment->loc_region) { Yii::app()->setLanguage($this->defLang); $regionInfo = Region::model()->findByPk($apartment->loc_region); if ($regionInfo && isset($regionInfo->name)) { $regionName = $regionInfo->name; } Yii::app()->setLanguage($this->currLang); } } // city if (isFree()) { if ($apartment->loc_city) { $cityInfo = City::model()->findByPk($apartment->loc_city); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } } } else { if ($apartment->loc_city) { Yii::app()->setLanguage($this->defLang); $cityInfo = City::model()->findByPk($apartment->loc_city); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } Yii::app()->setLanguage($this->currLang); } } } else { if (isFree()) { if ($apartment->city_id) { Yii::import('application.modules.apartmentCity.models.ApartmentCity'); $cityInfo = ApartmentCity::model()->findByPk($apartment->city_id); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } } } else { if ($apartment->city_id) { Yii::app()->setLanguage($this->defLang); Yii::import('application.modules.apartmentCity.models.ApartmentCity'); $cityInfo = ApartmentCity::model()->findByPk($apartment->city_id); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } Yii::app()->setLanguage($this->currLang); } } } $isPricePoa = $apartment->is_price_poa; $price = $apartment->price; $priceTo = $apartment->price_to; $numberRooms = $apartment->num_of_rooms; $floor = $apartment->floor; $floorTotal = $apartment->floor_total; $square = $apartment->square; $landSquare = $apartment->land_square; $sleeps = $apartment->berths; // get title, description, near, address, exchange $title = $description = $near = $address = $exchangeTo = ''; if (isFree()) { $titleField = 'title_' . Yii::app()->language; $title = $this->clearHtml($apartment->{$titleField}); $descrField = 'description_' . Yii::app()->language; $description = $this->clearHtml($apartment->{$descrField}); $descrNearField = 'description_near_' . Yii::app()->language; $near = $this->clearHtml($apartment->{$descrNearField}); $addressField = 'address_' . Yii::app()->language; $address = $this->clearHtml($apartment->{$addressField}); $exchangeToField = 'exchange_to_' . Yii::app()->language; $exchangeTo = $this->clearHtml($apartment->{$exchangeToField}); } else { if ($this->allLangs) { $title = $description = $near = $address = $exchangeTo = array(); foreach ($this->allLangs as $lang) { $titleField = 'title_' . $lang->name_iso; $descrField = 'description_' . $lang->name_iso; $descrNearField = 'description_near_' . $lang->name_iso; $addressField = 'address_' . $lang->name_iso; $exchangeToField = 'exchange_to_' . $lang->name_iso; $title[$lang->name_iso] = $this->clearHtml($apartment->{$titleField}); $description[$lang->name_iso] = $this->clearHtml($apartment->{$descrField}); $near[$lang->name_iso] = $this->clearHtml($apartment->{$descrNearField}); $address[$lang->name_iso] = $this->clearHtml($apartment->{$addressField}); $exchangeTo[$lang->name_iso] = $this->clearHtml($apartment->{$exchangeToField}); } } } // get coords $lat = $apartment->lat; $lng = $apartment->lng; // get photos $photos = $apartment->images(); if ($photos) { foreach ($photos as $key => $value) { if ($isZip) { $photos[$key] = $value->file_name; $photosExport["{$apartment->id}_{$key}"] = $model->csvPath . DIRECTORY_SEPARATOR . $value->file_name; copy(Yii::getPathOfAlias('webroot.uploads.objects.' . $apartment->id . '.original') . DIRECTORY_SEPARATOR . $value->file_name, $model->csvPath . DIRECTORY_SEPARATOR . $value->file_name); } else { $photos[$key] = Yii::app()->getBaseUrl(true) . '/uploads/objects/' . $apartment->id . '/original/' . $value->file_name; } } } // get reference info $refInfo = $this->getReferenceInfo($v); $comfort = $refInfo['comfort']; $bathroom = $refInfo['bathroom']; $kitchen = $refInfo['kitchen']; $employment = $refInfo['employment']; $safety = $refInfo['safety']; $entertainment = $refInfo['entertainment']; $terms = $refInfo['terms']; $services = $refInfo['services']; // insert $fileLine[$i] = $type . $this->separator . $priceType . $this->separator . $objType . $this->separator; $fileLine[$i] .= $countryName . $this->separator . $regionName . $this->separator . $cityName . $this->separator . $isPricePoa . $this->separator . $price . $this->separator; $fileLine[$i] .= $priceTo . $this->separator . $numberRooms . $this->separator . $floor . $this->separator; $fileLine[$i] .= $floorTotal . $this->separator . $square . $this->separator . $landSquare . $this->separator . $this->deleteChars($sleeps) . $this->separator; if (isFree()) { $fileLine[$i] .= $this->deleteChars($title) . $this->separator . $this->deleteChars($description) . $this->separator; $fileLine[$i] .= $this->deleteChars($near) . $this->separator . $this->deleteChars($address) . $this->separator; $fileLine[$i] .= $this->deleteChars($exchangeTo) . $this->separator; } else { array_walk($title, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $title) . $this->separator; array_walk($description, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $description) . $this->separator; array_walk($near, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $near) . $this->separator; array_walk($address, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $address) . $this->separator; array_walk($exchangeTo, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $exchangeTo) . $this->separator; } $fileLine[$i] .= $bathroom . $this->separator . $safety . $this->separator; $fileLine[$i] .= $comfort . $this->separator . $kitchen . $this->separator; $fileLine[$i] .= $employment . $this->separator . $entertainment . $this->separator; $fileLine[$i] .= $services . $this->separator . $terms . $this->separator; $fileLine[$i] .= is_array($photos) ? implode($this->separatorElem, $photos) . $this->separator : '' . $this->separator; $fileLine[$i] .= $lat . $this->separator . $lng; $i++; } // write in file $handle = fopen($filePath, "w+"); foreach ($fileLine as $item) { fputs($handle, $item); fputs($handle, "\r\n"); } fclose($handle); if ($isZip) { include_once $model->libraryPath . DIRECTORY_SEPARATOR . 'pclzip.lib.php'; $arrFile = $photosExport; $arrFile[] = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; $archive = new PclZip($model->csvPath . DIRECTORY_SEPARATOR . str_replace(".csv", "", $fileName) . ".zip"); $list = $archive->create($arrFile, PCLZIP_OPT_REMOVE_ALL_PATH); if ($list == 0) { Yii::app()->user->setFlash('error', $archive->errorInfo(true)); //$this->redirect('viewExport'); $this->redirect($backUrl); } // unlink all files foreach ($arrFile as $item) { @unlink($item); } $fileName = str_replace('.csv', '.zip', $fileName); $filePath = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; header("Content-Type: application/zip"); } else { header("Content-Type: application/csv"); } header("Content-Disposition: attachment; filename={$fileName}"); header("Content-Transfer-Encoding: binary"); header("Pragma: no-cache"); header("Expires: 0"); readfile($filePath); Yii::app()->end(); } } }
public function actionBatchDelete() { if (Yii::app()->user->checkAccess('deleteRegion') == false) { throw new CHttpException(403); } $idList = Yii::app()->request->getPost('data_id', array()); if (count($idList) > 0) { $criteria = new CDbCriteria(); $criteria->addInCondition('data_id', $idList); $datas = Region::model()->findAll($criteria); $flag = 0; foreach ($datas as $data) { if ($data->delete()) { $flag++; } } if ($flag > 0) { $this->setFlashMessage('品牌地区已成功删除'); } else { $this->setFlashMessage('品牌地区删除失败', 'warn'); } } else { $this->setFlashMessage('没有记录被选中', 'warn'); } $this->redirect(array('index')); }
public function getUserHomeAddress($id) { $model = User::model()->findByPk($id); $result = ''; if ($model->profiles) { $address = explode('-', $model->profiles->homeaddressdetail); foreach ($address as $region) { $result .= Region::model()->getRegion($region) . ' '; } } else { $result .= '地址不详'; } return $result; }
</div> </div>--> <?php if ($model->isNewRecord) { $model_pais = Pais::model()->findAll(); $model_region = new Region(); $model_provincia = new Provincia(); $model_ciudad = new Ciudad(); } else { $model->pais_id = $model->ciudad->provincia->region->pais->id; $model->region_id = $model->ciudad->provincia->region->id; $model->provincia_id = $model->ciudad->provincia->id; $model->ciudad_id = $model->ciudad->id; $model_pais = Pais::model()->findAll(); $model_region = Region::model()->findAll(array("condition" => "pais_id =:pais_id ", "order" => "nombre", "params" => array(':pais_id' => $model->ciudad->provincia->region->pais->id))); $model_provincia = Provincia::model()->findAll(array("condition" => "region_id =:region_id ", "order" => "nombre", "params" => array(':region_id' => $model->ciudad->provincia->region->id))); $model_ciudad = Ciudad::model()->findAll(array("condition" => "provincia_id =:provincia_id ", "order" => "nombre", "params" => array(':provincia_id' => $model->ciudad->provincia->id))); } ?> <?php echo $form->select2Row($model, 'pais_id', array('asDropDownList' => true, 'data' => CHtml::listData($model_pais, 'id', 'nombre'), 'options' => array('placeholder' => '-- Seleccione --'))); echo $form->select2Row($model, 'region_id', array('asDropDownList' => true, 'data' => CHtml::listData($model_region, 'id', 'nombre'), 'options' => array('placeholder' => '-- Seleccione --'))); echo $form->select2Row($model, 'provincia_id', array('asDropDownList' => true, 'data' => CHtml::listData($model_provincia, 'id', 'nombre'), 'options' => array('placeholder' => '-- Seleccione --'))); echo $form->select2Row($model, 'ciudad_id', array('asDropDownList' => true, 'data' => CHtml::listData($model_ciudad, 'id', 'nombre'), 'options' => array('placeholder' => '-- Seleccione --'))); ?> <?php // echo $form->dropDownListRow($model, 'ciudad_id', array('' => ' -- Seleccione -- ') + CHtml::listData(Ciudad::model()->findAll(), 'id', Ciudad::representingColumn())) ?> <?php echo $form->textFieldRow($model, 'nombre', array('maxlength' => 45));
public function actionUpdate($id) { if (Yii::app()->user->checkAccess('updateBrand') == false) { throw new CHttpException(403); } $brand = Brand::model()->multilingual()->findByPk($id); if (is_null($brand)) { throw new CHttpException(404); } if (isset($_POST['Brand'])) { $brand->attributes = Yii::app()->request->getPost('Brand'); $brand->brandFile = CUploadedFile::getInstance($brand, 'brandFile'); foreach (I18nHelper::getFrontendLanguages() as $lang => $attr) { $brand->i18nFormData['brandFile_' . $lang] = CUploadedFile::getInstance($brand, 'i18nFormData[brandFile_' . $lang . ']'); } if ($brand->save()) { $this->setFlashMessage(strtr('<strong>{link}</strong> 品牌修改成功', array('{link}' => CHtml::link(CHtml::encode($brand->title), array('view', 'id' => $brand->primaryKey))))); $this->redirect($this->getReturnUrl()); } } $regionOptions = Region::model()->getOptions(); $this->breadcrumbs = array('品牌' => array('index'), '修改'); $this->render('create', array('brand' => $brand, 'regionOptions' => $regionOptions, 'returnUrl' => $this->getReturnUrl())); }
public function actionHole() { $lang = $this->language; $msg = ""; $model = new Hole(); // uncomment the following code to enable ajax-based validation /* if(isset($_POST['ajax']) && $_POST['ajax']==='hole-hole-form') { echo CActiveForm::validate($model); Yii::app()->end(); } */ if (isset($_POST['Hole'])) { $a = $_POST['Hole']; $reg = Region::model()->findByPk(array('id' => $a['region'], 'lang' => $lang)); $holetype = HoleTypes::model()->findByPk(array('id' => $a['holetype'], 'lang' => $lang)); if ($this->debug) { echo $reg->name . ":" . $holetype->name . "<br>"; } $result = $this->getAllAuth($reg, $holetype, $lang); $msg = $this->renderPartial('holeform', array('result' => $result, 'holetype' => $holetype, 'region' => $reg, 'lang' => $lang, 'hole_id' => 1), true); // return; } if (isset($_POST['Print'])) { $print = $_POST['Print']; $auth = AuthorityType::model()->findByPk(array('lang' => $lang, 'id' => $print['auth']))->alias; $htype = HoleTypes::model()->findByPk(array('lang' => $lang, 'id' => $print['holetype']))->alias; $tmpl = $auth . "_" . $htype . '_' . $print['lang']; $printer = Yii::app()->Printer; if (file_exists(YiiBase::getPathOfAlias($printer->params['templates']) . "/dyplates/{$tmpl}.php")) { $css = file_get_contents(YiiBase::getPathOfAlias($printer->params['templates']) . "/dyplates/" . $auth . "_" . $htype . '.css'); $html = $this->renderFile(YiiBase::getPathOfAlias($printer->params['templates']) . "/dyplates/{$tmpl}.php", array(), true); $outname = "ukryama-" . date("Y-m-d_G-i-s"); echo $printer->printH2P($html, $css, $outname); return; } else { $msg = "Шаблон не найден"; } } $region = Region::model()->findByPk(array("id" => 1, "lang" => $lang)); $holetype = HoleTypes::model()->findAll("lang=:lang", array(":lang" => $lang)); $this->render('hole', array('model' => $model, 'region' => $region, 'holetype' => $holetype, 'msg' => $msg)); }
public function actionGetRegions() { if (Yii::app()->request->isAjaxRequest) { $data = Region::model()->findAll('sublocationID=:sublocationID', array(':sublocationID' => (int) $_GET['sublocationID'])); $data = CHtml::listData($data, 'id', 'name'); $chooseTranslate = Yii::t('common', 'Select region'); $new_data = array(); $new_data[0] = $chooseTranslate; foreach ($data as $key => $value) { $new_data[$key] = $value; } foreach ($new_data as $value => $name) { echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true); } } else { return 0; } }