public function actionTeams($id) { $model = $this->loadModel($id); $players = $model->players; if (isset($_POST['Teams']['info'])) { $error = false; $data = CJSON::decode($_POST['Teams']['info']); foreach ($data['players'] as $key => $player) { $_player = PlayerTournament::model()->findByPk($player['id']); $_player->chip_pulled = $player['chip_pulled']; if (!$_player->save()) { $error = true; } $team = new Team(); $team->tournament_id = $id; $team->player_id = $player['player_id']; $team->position = $player['chip_pulled']; if (!$team->save()) { $error = true; } } $teams = $model->get_teams(); //echo "<pre>";print_r($teams);echo "</pre>";exit; $max_teams = Team::model()->findAllByAttributes(array('tournament_id' => $model->id), array('order' => 'position DESC')); $c = new ChallongeAPI(Yii::app()->params['challonge_api']); foreach (range(1, $max_teams[0]->position) as $position) { $params = array("participant[name]" => $model->get_team_name($position), "participant[seed]" => $position); $participant = $c->createParticipant($model->challonge_id, $params)->participant; if ($participant) { Team::model()->updateAll(array('challonge_participant_id' => $participant->id), "tournament_id = {$model->id} and position = {$position}"); } } if (!$error) { Yii::app()->user->setFlash('success', 'Teams saved.'); $this->redirect(array('teams', 'id' => $id)); } $message = ""; foreach ($_player->getErrors() as $error) { $message .= $error . "<br />"; } Yii::app()->user->setFlash('error', $message); } $this->render('teams', array('model' => $model, 'players' => $players, 'registered_players' => $model->registered_players(), 'teams' => $model->get_teams())); }
header("Location: " . $_SERVER['HTTP_REFERER']); } //Edit Tournament if ($_POST['action'] == 'edit') { echo '<pre>'; var_dump($_POST); echo '</pre>'; } //Add Participant if (isset($_GET['addParticipant'])) { $participantName = $_POST['name']; $thisTournament = Tournament::find_by_tournamentid($_POST['tournamentID']); $thisUser = User::find_by_loginname($_POST['name']); $tournament_id = $thisTournament->challongeurl; $params = array("participant[name]" => $_POST['name']); $participant = $challonge->createParticipant($tournament_id, $params); $participants = unserialize($thisTournament->participants); //Get participant ID $participantID = count($participants) + 1; //Build participant array $thisParticipant['userID'] = intval($thisUser->userid); $thisParticipant['participantID'] = $participantID; $thisParticipant['participantName'] = $_POST['name']; $participants[$participantID] = $thisParticipant; $thisTournament->participants = serialize($participants); $thisTournament->save(); $participants = unserialize($thisTournament->participants); $_SESSION['participants'] = $participants; } //Add Team Participant if (isset($_GET['addTeamParticipant'])) {