/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RgnSubdistrict::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', 'status', $this->status])->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;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RgnSubdistrict::find()->with('district');
     $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(['rgn_subdistrict.id' => $this->id]);
     $query->andFilterWhere(['like', 'rgn_subdistrict.recordStatus', $this->recordStatus])->andFilterWhere(['like', 'rgn_subdistrict.number', $this->number])->andFilterWhere(['like', 'rgn_subdistrict.name', $this->name]);
     if (is_integer($this->district_id)) {
         $query->andFilterWhere(['district_id' => $this->district_id]);
     } else {
         if ($this->district_id) {
             $query->joinWith(['district' => function ($q) {
                 $q->where('rgn_district.name LIKE "%' . $this->district_id . '%"');
             }]);
         }
     }
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnSubdistricts()
 {
     return $this->hasMany(RgnSubdistrict::className(), ['district_id' => 'id'])->andFilterWhere(['like', 'status', RgnSubdistrict::STATUS_ACTIVE]);
 }
 /**
  * Provide data for Depdrop options
  * @param type $selected
  *
  * @return mixed
  */
 public function actionDepdropOptions($selected = 0)
 {
     echo \common\helpers\DepdropHelper::getOptionData(['modelClass' => RgnSubdistrict::className(), 'parents' => ['district_id' => function ($value) {
         return $value > 0 ? $value : "";
     }], 'filter' => ['recordStatus' => RgnSubdistrict::RECORDSTATUS_USED], 'selected' => $selected]);
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnSubdistricts()
 {
     return $this->hasMany(RgnSubdistrict::className(), ['district_id' => 'id'])->andFilterWhere(['like', 'recordStatus', RgnSubdistrict::RECORDSTATUS_USED]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSubdistrict()
 {
     return $this->hasOne(\frontend\models\RgnSubdistrict::className(), ['id' => 'subdistrict_id']);
 }