/**
  * Updates an existing tournaments model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     Yii::$app->user->returnUrl = Yii::$app->request->url;
     $model = $this->findModel($id);
     //getting standings with participants
     $participants = new ArrayDataProvider(['allModels' => Result::getStandings($id), 'pagination' => false]);
     //all teams(potential participants) for the current tournament
     $teams = Teams::getTeamCandidates($model->country0, TeamTournaments::getTournamentParticipantsID($id));
     $forecasters = new ArrayDataProvider(['allModels' => $model->getForecastersListNew()]);
     //getting the next tour number
     $nextTour = Tournaments::getNextTour($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->goBack();
     } else {
         return $this->render('update', compact('nextTour', 'model', 'teams', 'participants', 'forecasters'));
     }
 }
 public function actionAutoreminder()
 {
     $tournaments = Tournaments::find()->where(['not', ['is_active' => Tournaments::FINISHED]])->all();
     foreach ($tournaments as &$tournament) {
         if ($tournament->is_active == Tournaments::NOT_STARTED && $tournament->startsOn - time() < 60 * 60 * 24 * 5) {
             $tournament->is_active = Tournaments::GOING;
             $tournament->save(false);
         }
         $nextTour = Tournaments::getNextTour($tournament->id_tournament);
         if ($nextTour != NULL) {
             $firstGameStarts = ArrayHelper::getValue(Result::find()->select(['min(dtime) as dtime'])->where(['id_tournament' => $tournament->id_tournament, 'tour' => $nextTour])->all()[0], 'dtime');
             if ($firstGameStarts > time() + 60 * 60 * 24 * 4 && $firstGameStarts < time() + 60 * 60 * 24 * 5 || $firstGameStarts > time() + 60 * 60 * 24 * 2 && $firstGameStarts < time() + 60 * 60 * 24 * 3) {
                 $sendReminders = Reminders::sendAutoReminder($nextTour, $tournament->id_tournament);
                 Yii::info("Task Autoreminder for {$tournament->tournament_name} {$nextTour} tour has been executed", 'console');
             }
         }
     }
     return 0;
 }