/**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $matches = Match::find()->with('team', 'competition')->orderBy(['date_time' => SORT_DESC])->asArray()->all();
     $trainingMatches = TrainingMatch::find()->with('greenPlayers', 'purplePlayers')->orderBy(['date_time' => SORT_DESC])->asArray()->all();
     $trainingMatchStandings = TrainingMatchStandings::find()->one()->sorted();
     $playersStatisticSummary = PlayerStatisticSummary::find()->with(['player' => function ($query) {
         $query->with('playerLastResultsAggregated');
     }])->orderBy(['count_points' => SORT_DESC, 'count_games' => SORT_ASC])->limit(5)->asArray()->all();
     $playersRatingLebedev = PlayerRatingLebedevSummary::find()->with(['player' => function ($query) {
         $query->with('playerLastResultsAggregated');
     }])->orderBy(['rating_lebedev_avg' => SORT_DESC])->limit(5)->asArray()->all();
     return $this->render('index', ['matches' => $matches, 'trainingMatches' => $trainingMatches, 'trainingMatchStandings' => $trainingMatchStandings, 'playersStatisticSummary' => $playersStatisticSummary, 'playersRatingLebedev' => $playersRatingLebedev]);
 }
 public function actionFinish($id)
 {
     $trainingMatch = TrainingMatch::find()->where(['id' => $id])->one();
     $request = Yii::$app->request;
     if ($request->isPost) {
         $post = $request->post();
         $trainingMatch->green_goals = $post['green_goals'];
         $trainingMatch->purple_goals = $post['purple_goals'];
         $trainingMatch->is_finished = true;
         if ($trainingMatch->save()) {
             $this->sendScoreMessage($id);
         }
     }
 }
 public function actionRefuse($id)
 {
     $trainingMatch = TrainingMatch::find()->where(['id' => $id])->one();
     if (!Yii::$app->user->isGuest) {
         $userId = Yii::$app->user->identity->id;
         $request = Yii::$app->request;
         if ($request->isPost) {
             $post = $request->post();
             $player = Player::find()->where(['id' => $userId])->one();
             $trainingMatch->unlink('purplePlayers', $player);
             $trainingMatch->unlink('greenPlayers', $player);
             $trainingMatch->link('refusedPlayers', $player);
             $trainingMatch->save();
         }
     }
     return $this->goBack();
 }