Example #1
0
 static function check($param = [])
 {
     $country_id = ArrayHelper::getValue($param, 'country_id');
     $postcode = ArrayHelper::getValue($param, 'postcode');
     if ($country_id > 0 && $postcode > 0) {
         $model = static::findNumber($postcode, $country_id);
         if (is_null($model)) {
             $postcode = new Postcode($param);
             return $postcode->save(FALSE) ? $postcode : NULL;
         }
         return $model->improveData($param);
     }
 }
 /**
  * @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 = Postcode::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', 'recordStatus', $this->recordStatus]);
     return $dataProvider;
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPostcodes()
 {
     return $this->hasMany(Postcode::className(), ['city_id' => 'id'])->andFilterWhere(['like', 'status', Postcode::STATUS_ACTIVE]);
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPostcodes()
 {
     return $this->hasMany(Postcode::className(), ['city_id' => 'id'])->andFilterWhere(['like', 'recordStatus', Postcode::RECORDSTATUS_USED]);
 }
 /**
  * Finds the Postcode model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Postcode the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Postcode::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }