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 getRecentGamesGroupedByTourWithForecast($tournament, $user) { $trn = Tournaments::findOne($tournament); //first we need to get the ids of teams $id_teams = ArrayHelper::getColumn(TeamTournaments::find()->where(['id_tournament' => $tournament])->all(), 'id'); $teamsCount = count($id_teams); $games = self::find()->with('idTeamHome.idTeam', 'idTeamGuest.idTeam')->where(['or', ['in', 'id_team_home', $id_teams], ['in', 'id_team_guest', $id_teams]])->andWhere(['<', 'date_time_game', time()])->orderBy(['tour' => SORT_DESC])->addOrderBy(['date_time_game' => SORT_DESC])->limit($teamsCount)->indexBy('id_game')->asArray()->all(); $forecasts = Forecasts::find()->where(['in', 'id_game', ArrayHelper::getColumn($games, 'id_game')])->andWhere(['id_user' => $user])->indexBy('id_game')->asArray()->all(); $tours = array_unique(ArrayHelper::getColumn($games, 'tour')); $return = []; foreach ($tours as $tour) { foreach ($games as $k => $game) { if ($game['tour'] == $tour) { $return[$tour][$k] = ArrayHelper::remove($games, $k); if (isset($forecasts[$k])) { $return[$tour][$k]['fpoints'] = $forecasts[$k]['points']; $return[$tour][$k]['id_user_forecast'] = $forecasts[$k]['id_user']; $return[$tour][$k]['fscore_home'] = $forecasts[$k]['fscore_home']; $return[$tour][$k]['fscore_guest'] = $forecasts[$k]['fscore_guest']; $return[$tour][$k]['f_id'] = $forecasts[$k]['id']; $return[$tour][$k]['f_date'] = $forecasts[$k]['date']; } } } } $dataProvider = []; foreach ($return as $k => $one) { $dataProvider[$k] = new ArrayDataProvider(['allModels' => $one]); } return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getTeamTournaments() { return $this->hasMany(TeamTournaments::className(), ['id_team' => 'id_team']); }
public function getTeam() { return $this->hasOne(TeamTournaments::className(), ['id' => 'id_participant_team']); }
public function actionGames($id) { $games = new ArrayDataProvider(['allModels' => Result::getParticipantGames($id), 'pagination' => false]); $tournament = TeamTournaments::findOne($id); $team = TeamTournaments::findOne($id); return $this->render('gamesGuest', compact('games', 'tournament', 'team')); }
protected function findParticipantModel($id) { if (($model = TeamTournaments::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getForecastedStandings($id_tournament, $id_user) { //getting list of games for the tournament $games = Games::getGamesForTournament($id_tournament); $gameIDs = array_map(function ($item) { return $item->id_game; }, $games); //getting forecasts for the user for the tournament $forecasts = Forecasts::find()->where(['id_game' => $gameIDs, 'id_user' => $id_user])->indexBy('id_game')->asArray()->all(); //if there's a forecast for the game -> put forecast score as a game score + recalculating points foreach ($games as &$game) { if (isset($forecasts[$game->id_game])) { $game->score_home = $forecasts[$game->id_game]['fscore_home']; $game->score_guest = $forecasts[$game->id_game]['fscore_guest']; $game->getGamePoints(); } } $games = ArrayHelper::toArray($games); $teams = array_unique(array_merge(array_map(function ($value) { return $value['id_team_home']; }, $games), array_map(function ($value) { return $value['id_team_guest']; }, $games))); $teamObjects = TeamTournaments::find()->where(['id' => $teams])->joinWith('idTeam')->indexBy('id')->all(); $result = array_map(function ($item) use($games, $teamObjects) { $row['pts'] = 0; $row['participant'] = $item; $row['id'] = $item; $row['team_logo'] = $teamObjects[$item]->idTeam->team_logo; $row['team_name'] = $teamObjects[$item]->idTeam->team_name; $row['games_played'] = 0; foreach ($games as $game) { if ($game['id_team_home'] == $item) { $row['pts'] += $game['points_home']; if (isset($game['points_home'])) { $row['games_played'] += 1; } } if ($game['id_team_guest'] == $item) { $row['pts'] += $game['points_guest']; if (isset($game['points_guest'])) { $row['games_played'] += 1; } } } return $row; }, $teams); usort($result, function ($a, $b) { return $b['pts'] - $a['pts']; }); return $result; }
/** * @return \yii\db\ActiveQuery */ public function getIdTeamHome() { return $this->hasOne(TeamTournaments::className(), ['id' => 'id_team_home']); }
/** * Finds games with empty points but with not empty score * @return int */ public function actionGetNull() { $tournaments = Tournaments::getAutoprocessTournaments(); $games = []; foreach ($tournaments as $one) { $teamTournament = TeamTournaments::find()->where(['id_tournament' => $one->id_tournament])->all(); //getting Participant IDs for the tournament $teamIDs = ArrayHelper::getColumn($teamTournament, 'id'); $games = ArrayHelper::merge($games, Games::find()->where(['or', ['in', 'id_team_home', $teamIDs], ['in', 'id_team_guest', $teamIDs]])->andWhere(['and', ['or', ['not', ['score_home' => null]], ['not', ['score_guest' => null]]], ['or', ['points_home' => null], ['points_guest' => null]]])->all()); } if (!empty($games)) { $this->getErrorMessage($games); } else { Yii::info('No games with score but with no points', 'console'); } return 0; }
public function parse() { $teamTournament = TeamTournaments::find()->where(['id_tournament' => $this->tournament->id_tournament])->all(); $this->getGamesFromWeb($teamTournament); $this->getGamesFromDB($teamTournament); $this->matchWebDB(); $this->addNewGames(); }
if (time() > $tournament->wfDueTo) { $expired = true; } else { $expired = false; } $subtitle = $expired ? 'Прием прогнозов на призеров окончен ' . date('d.m.y', $tournament->wfDueTo) : 'Вы можете сделать прогноз на призеров турнира до ' . date('d.m.y', $tournament->wfDueTo) . ' и заработать дополнительные очки'; ?> <div class = 'col-xs-12 col-md-5 col-lg-4 col-lg-offset-1'> <p class = 'text-center' style="font-size:1.5em; color: #777">Прогноз на призеров турнира</p> <p class = 'text-center' style="color: #777"><?php echo $subtitle; ?> </p> <?php $teams = TeamTournaments::find()->select(['{{%teams}}.team_name', 'id'])->where(['id_tournament' => $tournament->id_tournament])->joinWith('idTeam')->indexBy('id')->column(); ?> <?php $options = ['prompt' => '---Выберите команду---']; if ($expired) { $options['disabled'] = 'disabled'; } ?> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($winners, 'first')->dropDownList($teams, $options); ?> <?php