public function actionIndex($tournament) { Yii::$app->user->returnUrl = Yii::$app->request->url; $curr_tournament = Tournaments::findOne($tournament); if (Yii::$app->request->post('tours')) { $tours = Yii::$app->request->post('tours'); } else { $tours = range(1, $curr_tournament->num_tours, 1); } $tourGames = Games::getGamesGroupedByTour($tournament, $tours); for ($i = 1; $i <= $curr_tournament->num_tours; $i++) { $tour_list[$i] = "{$i} тур"; } //preparing model for creating a game $newGame = new Games(); $participants = TeamTournaments::getTournamentParticipantsTeams($tournament); //model for uploading games from Excel $file = new GamesUploadForm(); if (Yii::$app->request->post('Games')) { $updatedGames = Yii::$app->request->post('Games'); foreach ($updatedGames as $k => $game) { $models[$k] = $this->findModel($k); } if (Games::loadMultiple($models, Yii::$app->request->post())) { $error = ''; foreach ($models as $model) { if (!$model->save()) { $error = $error . 'Ошибка сохранения игры ' . $model->competitors . "<br>"; } } if ($error === '') { Yii::$app->session->setFlash('status', 'Записи сохранены успешно'); } else { Yii::$app->session->setFlash('error', $error); } return $this->goBack(); } } return $this->render('index2', compact('tourGames', 'curr_tournament', 'tour_list', 'newGame', 'participants', 'file')); }
private static function sendReminder($tour, $tournament, $users) { $subject = "Напоминание: сделайте прогноз на матчи {$tour} тура турнира " . Tournaments::findOne($tournament)->tournament_name; $firstGameStarts = date('d-m-Y в H:i', ArrayHelper::getValue(Result::find()->select(['min(dtime) as dtime'])->where(['id_tournament' => $tournament, 'tour' => $tour])->all()[0], 'dtime')); $tours = Games::getNumberOfGamesPerTour($tournament); foreach ($users as $user) { if (Forecasts::getUserForecastTour($user->id, $tournament, $tours)[$tour] == 0) { $description = "Вы не сделали прогноз на матчи {$tour} тура турнира " . Tournaments::findOne($tournament)->tournament_name . ". Поторопитесь, первая игра тура начинается <strong>{$firstGameStarts}</strong>"; } else { $description = "Вы сделали прогноз не на все матчи: {$tour} тура турнира " . Tournaments::findOne($tournament)->tournament_name . ". Поторопитесь, первая игра тура начинается {$firstGameStarts}"; } $content = new ArrayDataProvider(['allModels' => Forecasts::getTourUserForecastStatus($tour, $tournament, $user->id), 'sort' => false, 'pagination' => false]); $messages[] = Yii::$app->mailer->compose('reminder', ['content' => $content, 'description' => $description, 'user' => $user])->setFrom([Yii::$app->params['adminEmail'] => 'Sportforecast'])->setTo($user->email)->setSubject($subject); //adding a record to the DB $reminder = self::getReminder($user->id, $tournament, $tour); $reminder->save(); } if (!empty($messages)) { Yii::$app->mailer->sendMultiple($messages); } return true; }
private static function generateTourNews($tournament, $tour) { $trn = Tournaments::findOne($tournament); $games = new ArrayDataProvider(['allModels' => self::getTourResults($tournament, $tour), 'pagination' => false, 'sort' => false]); $forecasters = new ArrayDataProvider(['allModels' => Forecasts::getTopFiveForecastersWithPoints($tournament, $tour)]); return Yii::$app->controller->renderPartial('@app/mail/_tourResultNews', ['trn' => $trn, 'games' => $games, 'forecasters' => $forecasters, 'tour' => $tour]); }
/** * Finds the tournaments model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return tournaments the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tournaments::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
* Time: 12:43 PM */ use app\components\grid\extendedGridView; use yii\helpers\Html; use yii\bootstrap\Collapse; use app\models\teams\Teams; use yii\bootstrap\ActiveForm; ?> <div class="row"> <div class = "col-xs-12"> <h3 class = 'text-center'>Ближайшие матчи</h3> <?php foreach ($games as $tournament) { ?> <?php $tournamentModel = \app\models\tournaments\Tournaments::findOne(['id_tournament' => $tournament['id_tournament']]); ?> <?php $content = ''; ?> <?php if (time() < $tournamentModel->wfDueTo) { ?> <?php $content .= "Вы можете " . Html::a('сделать прогноз на призеров турнира ', ['tournaments/details', 'id' => $tournament['id_tournament']]) . "и заработать дополнительные очки"; ?> <?php } ?> <?php $content .= "<p class = 'text-right'>" . Html::a("<i class = 'fa fa-list-alt'></i> Все игры", ['tournaments/details', 'id' => $tournament['id_tournament']]) . "</p>";
public function actionParticipate($id) { $tournament = Tournaments::findOne($id); if (UsersTournaments::find()->where(['id_tournament' => $id])->andWhere(['id_user' => Yii::$app->user->id])->exists()) { Yii::$app->session->setFlash('success', "Вы уже участвуете в турнире {$tournament->tournament_name}"); return $this->goBack(); } $model = new UsersTournaments(); $model->id_tournament = $id; $model->id_user = Yii::$app->user->id; $model->save(); Yii::$app->session->setFlash('success', "Вы теперь участвуете в турнире {$tournament->tournament_name}"); return $this->goBack(); }
public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); //getting the tournament number $tournament = ArrayHelper::getValue(Result::find()->where(['id_game' => $this->id_game])->one(), 'id_tournament'); //updating the forecast points for the game if (!$insert) { Forecasts::setForecastPoints($this->id_game, $this->score_home, $this->score_guest, $tournament); } //if tour finished, need to send notifications (if not already sent) and put tournament as finished if it was last tour /** * @var $tournamentModel \app\models\tournaments\Tournaments */ if (self::isTourFinished($tournament, $this->tour)) { $tournamentModel = Tournaments::findOne($tournament); if ($tournamentModel->num_tours == $this->tour) { $tournamentModel->is_active = Tournaments::FINISHED; $tournamentModel->save(false); } if (!TourResultNotifications::ifExists($this->tour, $tournament)) { self::sendTourResults($this->tour, $tournament); $notification = new TourResultNotifications(); $notification->tour = $this->tour; $notification->tournament = $tournament; $notification->save(); } } }