/** * Updates an existing Categories model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { if (\Yii::$app->user->isGuest) { return $this->goHome(); } $model = $this->findModel($id); $indicatorsAvailable = IndicatorNames::find()->select(['name', 'id'])->indexBy('id')->column(); $indicatorsPresent = $model->getIndicators()->select(['name', 'id'])->indexBy('id')->column(); foreach ($indicatorsPresent as $value) { if (($key = array_search($value, $indicatorsAvailable)) !== false) { unset($indicatorsAvailable[$key]); } } if ($model->load(Yii::$app->request->post()) && $model->save()) { CategoriesIndicators::deleteAll('id_categories = ' . $id); foreach (Yii::$app->request->post()['Categories']['indicators'] as $id_indicator) { $catInd = new CategoriesIndicators(); $catInd->id_indicator_names = $id_indicator; $catInd->id_categories = $model->id; $catInd->save(); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'indicatorsAvailable' => $indicatorsAvailable, 'indicatorsPresent' => $indicatorsPresent]); } }
public function calculateIndicators($id, $idSpec) { $hospitalIndicators = Divisions::find()->where(['id' => $id])->one(); $indicatorDefinitions = IndicatorNames::find()->all(); foreach ($indicatorDefinitions as $indicator) { $numeratorName = $indicator->basicNumerator->name; if ($indicator->denominator != 0) { $denominatorName = $indicator->basicDenominator->name; } if ($indicator->denominator != 0 && $hospitalIndicators->{$denominatorName} != 0) { $indicatorValue = ($hospitalIndicators->{$numeratorName} - $hospitalIndicators->{$denominatorName}) / $hospitalIndicators->{$denominatorName}; } elseif ($indicator->denominator_dec != 0) { $indicatorValue = ($hospitalIndicators->{$numeratorName} - $indicator->denominator_dec) / $indicator->denominator_dec; } else { $indicatorValue = $hospitalIndicators->{$numeratorName}; } $this->indicatorsArray[$indicator->indicator] = Indicators::_getRank($indicator->indicator, $indicatorValue, $id, $idSpec); } }
/** * @inheritdoc */ public function getIndicators() { return $this->hasOne(IndicatorNames::className(), ['indicator' => 'indicator']); }
/** * Finds the IndicatorNames model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return IndicatorNames the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = IndicatorNames::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getIndicator() { return $this->hasOne(IndicatorNames::className(), ['id' => 'id_indicator_names']); }
/** * @inheritdoc */ public function rules() { return [[['id_category'], 'required'], [['id_category', 'priority'], 'integer'], [['hospitals', 'units', 'specialities'], 'match', 'pattern' => '/^!{0,1}[0-9-]+$/'], [IndicatorNames::find()->select('indicator')->column(), 'integer'], ['name', 'integer']]; }
use yii\helpers\Html; use yii\widgets\DetailView; use app\models\IndicatorNames; /* @var $this yii\web\View */ /* @var $model app\models\InsightsDef */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => 'Definicje wniosków', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="insights-def-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a('Aktualizuj', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Usuń', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Czy na pewno usunąć wpis?', 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => array_merge(['name', 'category.name', 'priority'], IndicatorNames::find()->select(['indicator'])->column())]); ?> </div>
use yii\helpers\Html; use yii\widgets\ActiveForm; use app\models\IndicatorNames; /* @var $this yii\web\View */ /* @var $model app\models\IndicatorMath */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="indicator-math-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'indicator')->dropDownList(IndicatorNames::find()->select(['name', 'indicator'])->indexBy('indicator')->column()); ?> <?php echo $form->field($model, 'id_hospital')->textInput(); ?> <?php echo $form->field($model, 'id_division')->textInput(); ?> <?php echo $form->field($model, 'id_specjalizacja')->textInput(); ?> <?php
public function getIndicators() { return $this->hasMany(IndicatorNames::className(), ['id' => 'id_indicator_names'])->viaTable('categories_indicators', ['id_categories' => 'id']); }