/**
  * Evaluates the value of the user.
  * The return result of this method will be assigned to the current attribute(s).
  * @param Event $event
  * @return mixed the value of the user.
  */
 protected function getValue($event)
 {
     $attribute = $this->provinceAttribute;
     $value = $this->owner->{$attribute};
     $parentAttribute = $this->countryAttribute;
     $parent_id = $this->owner->{$parentAttribute};
     $parent_valid = $parent_id > 0;
     if (is_numeric($value)) {
         return $value;
     } else {
         if (empty($value) or $parent_valid == FALSE) {
             return NULL;
         } else {
             $model = new RgnProvince(['name' => $value, 'country_id' => $parent_id, 'recordStatus' => RgnProvince::RECORDSTATUS_USED]);
             return $model->save(FALSE) ? $model->id : 0;
         }
     }
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['recordStatus', 'default', 'value' => static::RECORDSTATUS_USED], [['postcode', 'country_id'], 'required'], [['subdistrict_id', 'district_id', 'city_id', 'province_id'], 'safe'], [['recordStatus'], 'string'], [['postcode'], 'integer'], ['recordStatus', 'in', 'range' => [self::RECORDSTATUS_USED, self::RECORDSTATUS_DELETED]], ['country_id', 'exist', 'targetClass' => RgnCountry::className(), 'targetAttribute' => 'id', 'when' => function (RgnPostcode $model, $attribute) {
         $num = is_numeric($model->{$attribute});
         //$model->addError($attribute, "num: [{$num}]; val: [{$model->$attribute}];");
         return $num;
     }, 'message' => "Country doesn't exist."], ['province_id', 'exist', 'targetClass' => RgnProvince::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "Province doesn't exist."], ['city_id', 'exist', 'targetClass' => RgnCity::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "City doesn't exist."], ['district_id', 'exist', 'targetClass' => RgnDistrict::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "District doesn't exist."], ['subdistrict_id', 'exist', 'targetClass' => RgnSubdistrict::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "Subdistrict doesn't exist."]];
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvince()
 {
     return $this->hasOne(\common\models\RgnProvince::className(), ['id' => 'province_id']);
 }
示例#4
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['recordStatus', 'default', 'value' => static::RECORDSTATUS_USED], [['name', 'province_id'], 'required'], [['recordStatus'], 'string'], [['number'], 'string', 'max' => 32], [['name'], 'string', 'max' => 255], [['abbreviation'], 'string', 'max' => 64], ['recordStatus', 'in', 'range' => [self::RECORDSTATUS_USED, self::RECORDSTATUS_DELETED]], ['province_id', 'exist', 'targetClass' => RgnProvince::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "Province doesn't exist."]];
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnProvinces()
 {
     return $this->hasMany(\common\models\RgnProvince::className(), ['country_id' => 'id']);
 }
示例#6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->operation = new RgnProvinceOperation(['model' => $this]);
 }