/**
  * extending base rules to match form scenario
  */
 public function rules()
 {
     $rules = parent::rules();
     /* new province */
     $rules[] = ['country_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 = RgnProvince::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, 'country_id' => $this->country_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 = RgnProvince::find()->with('country');
     $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_province.id' => $this->id]);
     $query->andFilterWhere(['like', 'rgn_province.recordStatus', $this->recordStatus])->andFilterWhere(['like', 'rgn_province.number', $this->number])->andFilterWhere(['like', 'rgn_province.name', $this->name])->andFilterWhere(['like', 'rgn_province.abbreviation', $this->abbreviation]);
     if (is_integer($this->country_id)) {
         $query->andFilterWhere(['country_id' => $this->country_id]);
     } else {
         if ($this->country_id) {
             $query->joinWith(['country' => function ($q) {
                 $q->where('rgn_country.name LIKE "%' . $this->country_id . '%"');
             }]);
         }
     }
     return $dataProvider;
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnProvinces()
 {
     return $this->hasMany(RgnProvince::className(), ['country_id' => 'id'])->andFilterWhere(['like', 'recordStatus', RgnProvince::RECORDSTATUS_USED]);
 }
 /**
  * Provide data for Depdrop options
  * @param type $selected
  *
  * @return mixed
  */
 public function actionDepdropOptions($selected = 0)
 {
     echo \common\helpers\DepdropHelper::getOptionData(['modelClass' => RgnProvince::className(), 'parents' => ['country_id' => function ($value) {
         return $value > 0 ? $value : "";
     }], 'filter' => ['recordStatus' => RgnProvince::RECORDSTATUS_USED], 'selected' => $selected]);
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvince()
 {
     return $this->hasOne(RgnProvince::className(), ['id' => 'province_id']);
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnProvinces()
 {
     return $this->hasMany(RgnProvince::className(), ['country_id' => 'id'])->andFilterWhere(['like', 'status', RgnProvince::STATUS_ACTIVE]);
 }
示例#8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvince()
 {
     return $this->hasOne(\frontend\models\RgnProvince::className(), ['id' => 'province_id']);
 }