/**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = Tiles::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'x' => $this->x, 'y' => $this->y, 'category' => $this->category, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
 /**
  * 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]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTiles()
 {
     return $this->hasMany(Tiles::className(), ['category' => 'id']);
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTile0()
 {
     return $this->hasOne(Tiles::className(), ['id' => 'tile']);
 }
 /**
  * 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.');
     }
 }