/** * 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->subdistrictAttribute; $value = $this->owner->{$attribute}; $parentAttribute = $this->districtAttribute; $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 Subdistrict(['name' => $value, 'district_id' => $parent_id, 'status' => Subdistrict::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 = Subdistrict::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, 'district_id' => $this->district_id]); $query->andFilterWhere(['like', 'recordStatus', $this->recordStatus])->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @inheritdoc */ public function rules() { $rules = parent::rules(); $rules[] = [['city_id', '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; }]; /* new district */ $rules[] = ['district_id', 'string', 'max' => 255, 'when' => function ($model, $attribute) { return is_numeric($model->{$attribute}) == FALSE; }]; return $rules; }
/** * @return \yii\db\ActiveQuery */ public function getSubdistrict() { return $this->hasOne(Subdistrict::className(), ['id' => 'subdistrict_id']); }
/** * Provide data for Depdrop options * @param type $selected * * @return mixed */ public function actionDepdropOptions($selected = 0) { echo \common\helpers\DepdropHelper::getOptionData(['modelClass' => Subdistrict::className(), 'parents' => ['district_id' => function ($value) { return $value > 0 ? $value : ""; }], 'filter' => ['recordStatus' => Subdistrict::RECORDSTATUS_USED], 'selected' => $selected]); }
/** * @return \yii\db\ActiveQuery */ public function getSubdistricts() { return $this->hasMany(Subdistrict::className(), ['district_id' => 'id'])->andFilterWhere(['like', 'recordStatus', Subdistrict::RECORDSTATUS_USED]); }
/** * @return \yii\db\ActiveQuery */ public function getSubdistricts() { return $this->hasMany(Subdistrict::className(), ['district_id' => 'id'])->andFilterWhere(['like', 'status', Subdistrict::STATUS_ACTIVE]); }