/** * Integrates the regions registries. */ protected function integrateRegions() { $regions = [['_id' => 1, 'name' => 'Álava'], ['_id' => 2, 'name' => 'Albacete'], ['_id' => 3, 'name' => 'Alicante'], ['_id' => 4, 'name' => 'Almería'], ['_id' => 5, 'name' => 'Ávila'], ['_id' => 6, 'name' => 'Badajoz'], ['_id' => 7, 'name' => 'Islas Baleares'], ['_id' => 8, 'name' => 'Barcelona'], ['_id' => 9, 'name' => 'Burgos'], ['_id' => 10, 'name' => 'Cáceres'], ['_id' => 11, 'name' => 'Cádiz'], ['_id' => 12, 'name' => 'Castellón'], ['_id' => 13, 'name' => 'Ciudad Real'], ['_id' => 14, 'name' => 'Córdoba'], ['_id' => 15, 'name' => 'A Coruña'], ['_id' => 16, 'name' => 'Cuenca'], ['_id' => 17, 'name' => 'Girona'], ['_id' => 18, 'name' => 'Granada'], ['_id' => 19, 'name' => 'Guadalajara'], ['_id' => 20, 'name' => 'Gipuzkoa'], ['_id' => 21, 'name' => 'Huelva'], ['_id' => 22, 'name' => 'Huesca'], ['_id' => 23, 'name' => 'Jaén'], ['_id' => 24, 'name' => 'León'], ['_id' => 25, 'name' => 'Lleida'], ['_id' => 26, 'name' => 'La Rioja'], ['_id' => 27, 'name' => 'Lugo'], ['_id' => 28, 'name' => 'Madrid'], ['_id' => 29, 'name' => 'Málaga'], ['_id' => 30, 'name' => 'Murcia'], ['_id' => 31, 'name' => 'Navarra'], ['_id' => 32, 'name' => 'Ourense'], ['_id' => 33, 'name' => 'Asturias'], ['_id' => 34, 'name' => 'Palencia'], ['_id' => 35, 'name' => 'Las Palmas'], ['_id' => 36, 'name' => 'Pontevedra'], ['_id' => 37, 'name' => 'Salamanca'], ['_id' => 38, 'name' => 'Santa Cruz de Tenerife'], ['_id' => 39, 'name' => 'Cantabria'], ['_id' => 40, 'name' => 'Segovia'], ['_id' => 41, 'name' => 'Sevilla'], ['_id' => 42, 'name' => 'Soria'], ['_id' => 43, 'name' => 'Tarragona'], ['_id' => 44, 'name' => 'Teruel'], ['_id' => 45, 'name' => 'Toledo'], ['_id' => 46, 'name' => 'Valencia'], ['_id' => 47, 'name' => 'Valladolid'], ['_id' => 48, 'name' => 'Bizkaia'], ['_id' => 49, 'name' => 'Zamora'], ['_id' => 50, 'name' => 'Zaragoza'], ['_id' => 51, 'name' => 'Ceuta'], ['_id' => 52, 'name' => 'Melilla']]; foreach ($regions as $rData) { $region = new Region(['name' => $rData['name'], 'country_id' => $this->countryId]); if ($region->save() === false) { throw new SaveException($region); } $this->regionMapping[$rData['_id']] = $region->id; } }
/** * Finds the Region model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Region the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findRegion($id) { if (($model = Region::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = Region::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'zone_id' => $this->zone_id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function run() { echo $this->form->field($this->model, $this->model->getCountryPropertyName())->dropDownList(ArrayHelper::map(Country::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), ['id' => 'location_country_id', 'prompt' => Yii::t('common/geo/country', 'Select country')]); if ($this->localized === $this->model->getCountryPropertyName()) { return; } echo $this->form->field($this->model, $this->model->getRegionPropertyName())->widget(DepDrop::className(), ['options' => ['id' => 'location_region_id', 'placeholder' => Yii::t('common/geo/region', 'Select region')], 'data' => ArrayHelper::map(Region::find()->where(['country_id' => $this->model->country_id])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), 'pluginOptions' => ['url' => Url::to(['/geo/region/list']), 'depends' => ['location_country_id']]]); if ($this->localized === $this->model->getRegionPropertyName()) { return; } echo $this->form->field($this->model, $this->model->getCityPropertyName())->widget(DepDrop::className(), ['options' => ['id' => 'location_city_id', 'cityholder' => Yii::t('common/geo/city', 'Select city')], 'data' => ArrayHelper::map(City::find()->where(['region_id' => $this->model->region_id])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), 'pluginOptions' => ['url' => Url::to(['/geo/city/list']), 'depends' => ['location_region_id']]]); if ($this->localized === $this->model->getCityPropertyName()) { return; } echo $this->form->field($this->model, 'address')->textInput(); }
/** * @return \yii\db\ActiveQuery */ public function getRegion() { return $this->hasOne(Region::className(), ['id' => 'region_id']); }
/** * Returns the table name of the Region model. You can override this * method in order to provide a custom table name. * * @return string */ protected function getRegionTableName() { return Region::tableName(); }
/** * Renders the region part. */ protected function region() { $this->parts['{region}'] = $this->form->field($this->model, $this->model->getRegionPropertyName())->widget(DepDrop::className(), ['options' => ['id' => 'location_region_id', 'placeholder' => Yii::t('jlorente/location', 'Select region')], 'data' => ArrayHelper::map(Region::find()->where(['country_id' => $this->model->country_id])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), 'pluginOptions' => ['url' => Url::to(["/{$this->module->id}/region/list"]), 'depends' => ['location_country_id']]]); }
/** * * @return yii\db\ActiveQuery */ public function getRegion() { return $this->hasMany(Region::className(), ['country_id' => 'id']); }