/** * Displays a single Categories model. * @param integer $id * @return mixed */ public function actionView($id) { if (\Yii::$app->user->isGuest) { return $this->goHome(); } $dataProvider = new ActiveDataProvider(['query' => CategoriesIndicators::find()->where(['id_categories' => $id])]); return $this->render('view', ['model' => $this->findModel($id), 'dataProvider' => $dataProvider]); }
/** * Creates a new InsightsDef model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($idCategory = 4, $id = 0) { $model = new InsightsDef(); $content = new InsightsContent(); $model->name = $id; $model->id_category = $idCategory; if ($model->load(Yii::$app->request->post())) { $priorityCounter = 0; foreach (Yii::$app->request->post()['InsightsDef'] as $key => $value) { if (!in_array($key, ['id', 'id_category', 'priority', 'hospitals', 'units', 'specialities', 'name']) && $value != '') { $priorityCounter++; } } $model->priority = $priorityCounter; $model->save(); $content->id_insights_def = $model->id; $content->content = Yii::$app->request->post()['InsightsContent']['content']; $content->lang = 'pl'; $content->save(); return $this->redirect(['create', 'idCategory' => $model->id_category, 'id' => $model->id]); } else { $categories = Categories::find()->select(['name', 'id'])->indexBy('id')->column(); $indicatorNames = CategoriesIndicators::find()->where('id_categories = ' . $idCategory)->all(); $insights = InsightsDef::find()->where('id_category = ' . $idCategory)->all(); $insightsCollection = [0 => '']; foreach ($insights as $insight) { $name = ''; foreach ($insight->toArray() as $key => $value) { if (!in_array($key, ['id', 'id_category', 'priority', 'hospitals', 'units', 'specialities']) && $value !== null) { $name .= $key . '(' . $value . ')'; } } $insightsCollection[$insight->id] = $name; } return $this->render('create', ['model' => $model, 'content' => $content, 'categories' => $categories, 'indicatorNames' => $indicatorNames, 'insights' => $insightsCollection]); } }