/** * Displays the moreresults page * * @return mixed */ public function actionMoreresults() { $tilesUsers = TilesUsers::find()->where(['created_by' => Yii::$app->getUser()->id])->all(); $tilesCategories = TilesCategories::find()->all(); $categoriesNames = []; $categoriesLevels = []; foreach ($tilesCategories as $tilesCategory) { $points[$tilesCategory->name] = 0; $outOf[$tilesCategory->name] = 0; $levels[$tilesCategory->name] = 0; $categoriesNames[] = $tilesCategory->name; } foreach ($tilesUsers as $tilesUser) { $category = Tiles::findOne($tilesUser->tile)->category0; $level = Levels::findOne($tilesUser->level); $points[$category->name] += $level->score; $outOf[$category->name] += 1; $levels[$category->name] += $level->level; } foreach ($tilesCategories as $tilesCategory) { $levels[$tilesCategory->name] = round($levels[$tilesCategory->name] / $outOf[$tilesCategory->name]); $categoriesLevels[] = $levels[$tilesCategory->name]; $colors[$tilesCategory->name] = Levels::find()->where(['level' => $levels[$tilesCategory->name]])->one()->color; } return $this->render('moreresults', ['tilesCategories' => $tilesCategories, 'points' => $points, 'outOf' => $outOf, 'levels' => $levels, 'colors' => $colors, 'categoriesNames' => $categoriesNames, 'categoriesLevels' => $categoriesLevels]); }
/** * Finds the Tiles model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tiles the loaded model * @throws HttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tiles::findOne($id)) !== null) { return $model; } else { throw new HttpException(404, 'The requested page does not exist.'); } }