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