/**
  * Evaluates the value of the user.
  * The return result of this method will be assigned to the current attribute(s).
  * @param Event $event
  * @return mixed the value of the user.
  */
 protected function getValue($event)
 {
     $attribute = $this->cityAttribute;
     $value = $this->owner->{$attribute};
     $parentAttribute = $this->provinceAttribute;
     $parent_id = $this->owner->{$parentAttribute};
     $parent_valid = $parent_id > 0;
     if (is_numeric($value)) {
         return $value;
     } else {
         if (empty($value) or $parent_valid == FALSE) {
             return NULL;
         } else {
             $model = new City(['name' => $value, 'province_id' => $parent_id, 'recordStatus' => City::RECORDSTATUS_USED]);
             return $model->save(FALSE) ? $model->id : 0;
         }
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     $rules = parent::rules();
     $rules[] = [['country_id'], 'required'];
     /* special rule when typing new country */
     $rules[] = ['country_id', 'string', 'max' => 255, 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute}) == FALSE;
     }];
     /* special rule when typing new province */
     $rules[] = ['province_id', 'string', 'max' => 255, 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute}) == FALSE;
     }];
     return $rules;
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = City::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'province_id' => $this->province_id]);
     $query->andFilterWhere(['like', 'recordStatus', $this->recordStatus])->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'abbreviation', $this->abbreviation]);
     return $dataProvider;
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCity()
 {
     return $this->hasOne(City::className(), ['id' => 'city_id']);
 }
 /**
  * Provide data for Depdrop options
  * @param type $selected
  *
  * @return mixed
  */
 public function actionDepdropOptions($selected = 0)
 {
     echo \common\helpers\DepdropHelper::getOptionData(['modelClass' => City::className(), 'parents' => ['province_id' => function ($value) {
         return $value > 0 ? $value : "";
     }], 'filter' => ['recordStatus' => City::RECORDSTATUS_USED], 'selected' => $selected]);
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCities()
 {
     return $this->hasMany(City::className(), ['province_id' => 'id'])->andFilterWhere(['like', 'status', City::STATUS_ACTIVE]);
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCities()
 {
     return $this->hasMany(City::className(), ['province_id' => 'id'])->andFilterWhere(['like', 'recordStatus', City::RECORDSTATUS_USED]);
 }