/**
  * 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 Province(['name' => $value, 'country_id' => $parent_id, 'status' => Province::STATUS_ACTIVE]);
             return $model->save(FALSE) ? $model->id : 0;
         }
     }
 }
 /**
  * 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 = Province::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', 'recordStatus', $this->recordStatus])->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'abbreviation', $this->abbreviation]);
     return $dataProvider;
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvince()
 {
     return $this->hasOne(Province::className(), ['id' => 'province_id']);
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvinces()
 {
     return $this->hasMany(Province::className(), ['country_id' => 'id'])->andFilterWhere(['like', 'status', Province::STATUS_ACTIVE]);
 }
 /**
  * Provide data for Depdrop options
  * @param type $selected
  *
  * @return mixed
  */
 public function actionDepdropOptions($selected = 0)
 {
     echo \common\helpers\DepdropHelper::getOptionData(['modelClass' => Province::className(), 'parents' => ['country_id' => function ($value) {
         return $value > 0 ? $value : "";
     }], 'filter' => ['recordStatus' => Province::RECORDSTATUS_USED], 'selected' => $selected]);
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvinces()
 {
     return $this->hasMany(Province::className(), ['country_id' => 'id'])->andFilterWhere(['like', 'recordStatus', Province::RECORDSTATUS_USED]);
 }
示例#8
0
				<?php 
echo $model->name;
?>
			</h2>
        </div>

        <div class="panel-body">



			<?php 
$this->beginBlock('Province');
?>

			<?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['attribute' => 'status', 'value' => frontend\modules\region\models\Province::getStatusValueLabel($model->status)], 'number', 'name', 'abbreviation', ['format' => 'html', 'attribute' => 'country_id', 'value' => $model->country ? $model->country->linkTo : '<span class="label label-warning">?</span>']]]);
?>

			<hr/>

			<?php 
echo $model->operation->button('delete');
?>
			<?php 
echo $model->operation->button('restore');
?>

			<?php 
$this->endBlock();
?>