public function prepareInsights($id, $indicators) { $hospitalIndicators = Divisions::find()->where(['id' => $id])->one(); $whereArray = ['and']; foreach ($indicators as $key => $value) { array_push($whereArray, ['or', "{$key} = {$value}", "{$key} IS NULL"]); } if ($insights = InsightsDef::find()->where($whereArray)->orderBy('priority')->all()) { foreach ($insights as $insight) { foreach ($insight->content as $insightLine) { array_push($this->insightsArray, Insights::_evaluateIndicators($insightLine->content, $hospitalIndicators)); } } } else { $this->insightsArray = []; } }
public function getInsight() { return $this->hasOne(InsightsDef::className(), ['id' => 'id_insights_def']); }
/** * Deletes an existing IndicatorNames model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { if (\Yii::$app->user->isGuest) { return $this->goHome(); } $model = $this->findModel($id); Yii::$app->db->createCommand()->dropColumn(InsightsDef::tableName(), $model->indicator)->execute(); $model->delete(); return $this->redirect(['index']); }
private static function _getInsights($indicators) { $returnArray = ['exact' => ['content' => '', 'id' => 0, 'defId' => 0], 'general' => []]; $whereArray = ['and']; $whereArrayExact = ['and']; foreach ($indicators as $key => $value) { if (in_array($key, ['hospitals', 'units', 'specialities'])) { $negation = 0; if ($value[0] == '!') { array_shift($value); $negation = 1; } if (count($value) == 1) { if ($negation) { array_push($whereArray, "{$key} != {$value['0']}"); array_push($whereArrayExact, "{$key} != {$value['0']}"); } else { array_push($whereArray, "{$key} = {$value['0']}"); array_push($whereArrayExact, "{$key} = {$value['0']}"); } } else { if ($negation) { array_push($whereArray, "{$key} NOT IN (" . implode(',', $value) . ")"); array_push($whereArrayExact, "{$key} NOT IN (" . implode(',', $value) . ")"); } else { array_push($whereArray, "{$key} IN (" . implode(',', $value) . ")"); array_push($whereArrayExact, "{$key} IN (" . implode(',', $value) . ")"); } } } else { if ($value !== '' && $value !== null) { array_push($whereArray, ['or', "{$key} = {$value}", "{$key} IS NULL"]); array_push($whereArrayExact, "{$key} = {$value}"); } else { array_push($whereArray, "{$key} IS NULL"); array_push($whereArrayExact, "{$key} IS NULL"); } } } if ($insightExact = InsightsDef::find()->where($whereArrayExact)->one()) { foreach ($insightExact->content as $insightLine) { // array_push ($returnArray['exact'], $insightLine->content); $returnArray['exact']['content'] = $insightLine->content; $returnArray['exact']['id'] = $insightLine->id; $returnArray['exact']['defId'] = $insightExact->id; } } if ($insights = InsightsDef::find()->where($whereArray)->orderBy('priority')->all()) { foreach ($insights as $insight) { if (!is_object($insightExact) || $insight->id != $insightExact->id) { foreach ($insight->content as $insightLine) { array_push($returnArray['general'], $insightLine->content); } } } } return $returnArray; }
use yii\helpers\Html; use yii\widgets\ActiveForm; use app\models\InsightsDef; /* @var $this yii\web\View */ /* @var $model app\models\InsightsContent */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="insights-content-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->dropDownList(InsightsDef::find()->select(['name', 'name'])->indexBy('name')->column()); ?> <?php echo $form->field($model, 'content')->textarea(['rows' => 6]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Utwórz' : 'Aktualizuj', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/** * Finds the InsightsDef model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return InsightsDef the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = InsightsDef::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }