Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     $rules = parent::rules();
     /* 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;
     }];
     /* new subdistrict */
     $rules[] = ['subdistrict_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 = RgnPostcode::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, 'postcode' => $this->postcode, 'subdistrict_id' => $this->subdistrict_id, 'district_id' => $this->district_id, 'city_id' => $this->city_id, 'province_id' => $this->province_id, 'country_id' => $this->country_id]);
     $query->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnPostcodes()
 {
     return $this->hasMany(RgnPostcode::className(), ['country_id' => 'id'])->andFilterWhere(['like', 'recordStatus', RgnPostcode::RECORDSTATUS_USED]);
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnPostcodes()
 {
     return $this->hasMany(RgnPostcode::className(), ['district_id' => 'id'])->andFilterWhere(['like', 'status', RgnPostcode::STATUS_ACTIVE]);
 }
 /**
  * Finds the RgnPostcode model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return RgnPostcode the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = RgnPostcode::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RgnPostcode::find()->with('province', 'city', '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_postcode.id' => $this->id, 'rgn_postcode.postcode' => $this->postcode]);
     $query->andFilterWhere(['like', 'rgn_postcode.recordStatus', $this->recordStatus]);
     // filtering subdistrict
     if (is_integer($this->subdistrict_id)) {
         $query->andFilterWhere(['subdistrict_id' => $this->subdistrict_id]);
     } else {
         if ($this->subdistrict_id) {
             $query->joinWith(['subdistrict' => function ($q) {
                 $q->where('rgn_subdistrict.name LIKE "%' . $this->subdistrict_id . '%"');
             }]);
         }
     }
     // filtering district
     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 . '%"');
             }]);
         }
     }
     // filtering city
     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 . '%"');
             }]);
         }
     }
     // filtering province
     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 . '%"');
             }]);
         }
     }
     // filtering country
     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;
 }