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')); }
/** * @param $tournament * @var $trn Tournaments * @return string|\yii\web\Response */ public function actionAlias($tournament) { //getting the list of teams for the tournament $teams = TeamTournaments::getTournamentParticipantsTeams($tournament); $trn = Tournaments::findOne($tournament); if (TeamTournaments::loadMultiple($teams, Yii::$app->request->post())) { foreach ($teams as $team) { $team->save(false); } return $this->redirect(['tournaments/update', 'id' => $trn->id_tournament]); } return $this->render('aliasAssign', compact('teams', 'trn')); }