/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = KpiItem::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'group_id' => $this->group_id]);
     $query->andFilterWhere(['like', 'the_must', $this->the_must])->andFilterWhere(['like', 'the_best', $this->the_best]);
     return $dataProvider;
 }
 /**
  * Finds the KpiItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return KpiItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = KpiItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getKpi()
 {
     return $this->hasOne(KpiItem::className(), ['id' => 'kpi_id']);
 }
 /**
  * [createEvauateScoreModels description]
  * @param  [type] $hospital_id [description]
  * @param  [type] $year        [description]
  * @return [type]              [description]
  */
 public function createEvauateScoreModels($hospital_id, $year, $group_id = null)
 {
     $items = KpiItem::find()->byGroup($group_id)->orderBy('group_id')->all();
     $evauateScores = [];
     foreach ($items as $item) {
         $evauateScores[] = new EvauateScore(['kpi_id' => $item->id, 'theMust' => $item->the_must, 'theBest' => $item->the_best, 'year' => $year, 'level' => Yii::$app->user->identity->level, 'hospital_id' => $hospital_id, 'groupName' => $item->group->name]);
     }
     return $evauateScores;
 }