/**
  * @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;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RgnCity::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', 'status', $this->status])->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'abbreviation', $this->abbreviation]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RgnCity::find()->with('province');
     $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_city.id' => $this->id]);
     $query->andFilterWhere(['like', 'rgn_city.recordStatus', $this->recordStatus])->andFilterWhere(['like', 'rgn_city.number', $this->number])->andFilterWhere(['like', 'rgn_city.name', $this->name])->andFilterWhere(['like', 'rgn_city.abbreviation', $this->abbreviation]);
     if (is_integer($this->province_id)) {
         $query->andFilterWhere(['province_id' => $this->province_id]);
     } else {
         if ($this->province_id) {
             $query->joinWith(['province' => function ($q) {
                 $q->where('rgn_province.name LIKE "%' . $this->province_id . '%"');
             }]);
         }
     }
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCity()
 {
     return $this->hasOne(RgnCity::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' => RgnCity::className(), 'parents' => ['province_id' => function ($value) {
         return $value > 0 ? $value : "";
     }], 'filter' => ['status' => RgnCity::STATUS_ACTIVE], 'selected' => $selected]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnCities()
 {
     return $this->hasMany(RgnCity::className(), ['province_id' => 'id'])->andFilterWhere(['like', 'status', RgnCity::STATUS_ACTIVE]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnCities()
 {
     return $this->hasMany(RgnCity::className(), ['province_id' => 'id'])->andFilterWhere(['like', 'recordStatus', RgnCity::RECORDSTATUS_USED]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCity()
 {
     return $this->hasOne(\frontend\models\RgnCity::className(), ['id' => 'city_id']);
 }