/**
  * 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->districtAttribute;
     $value = $this->owner->{$attribute};
     $parentAttribute = $this->cityAttribute;
     $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 District(['name' => $value, 'city_id' => $parent_id, 'status' => District::STATUS_ACTIVE]);
             return $model->save(FALSE) ? $model->id : 0;
         }
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = District::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, 'city_id' => $this->city_id]);
     $query->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     $rules = parent::rules();
     $rules[] = [['province_id', 'country_id'], 'required'];
     /* new country */
     $rules[] = ['country_id', 'string', 'max' => 255, 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute}) == FALSE;
     }];
     /* new province */
     $rules[] = ['province_id', 'string', 'max' => 255, 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute}) == FALSE;
     }];
     /* new city */
     $rules[] = ['city_id', 'string', 'max' => 255, 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute}) == FALSE;
     }];
     return $rules;
 }
Esempio n. 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDistrict()
 {
     return $this->hasOne(District::className(), ['id' => 'district_id']);
 }
Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDistricts()
 {
     return $this->hasMany(District::className(), ['city_id' => 'id'])->andFilterWhere(['like', 'status', District::STATUS_ACTIVE]);
 }
Esempio n. 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDistricts()
 {
     return $this->hasMany(District::className(), ['city_id' => 'id'])->andFilterWhere(['like', 'recordStatus', District::RECORDSTATUS_USED]);
 }
 /**
  * Provide data for Depdrop options
  * @param type $selected
  *
  * @return mixed
  */
 public function actionDepdropOptions($selected = 0)
 {
     echo \common\helpers\DepdropHelper::getOptionData(['modelClass' => District::className(), 'parents' => ['city_id' => function ($value) {
         return $value > 0 ? $value : "";
     }], 'filter' => ['recordStatus' => District::RECORDSTATUS_USED], 'selected' => $selected]);
 }