public function actionmatchresults($id) { $model = $this->loadModel($id); $tournament_id = $model->challonge_id; if (isset($_POST['winner_id']) && isset($_POST['match_id'])) { $c = new ChallongeAPI(Yii::app()->params['challonge_api']); $match_id = $_POST['match_id']; $csv = $_POST['team_number'] == 1 ? "1-0" : "0-1"; $params = array("match[scores_csv]" => $csv, "match[winner_id]" => $_POST['winner_id']); $match = $c->updateMatch($tournament_id, $match_id, $params); if (count($c->errors)) { foreach ($c->errors as $error) { Yii::app()->user->setFlash('error', "Challonge ERROR: " . $error); } } else { $model->updateMatchesFromChallonge(); } $outs = $_POST['Data']['outs']; $high_darts = $_POST['Data']['high_dart']; // echo "<pre>"; // print_r($_POST); // print_r($outs); // echo "</pre>"; foreach ($outs as $game) { foreach ($game as $player_id => $out) { if ($out > 0) { $highout = new HighOut(); $highout->tournament_id = $id; $highout->player_id = $player_id; $highout->high_out = $out; $highout->save(); } } } foreach ($high_darts as $player_id => $high_dart) { if ($high_dart > 0) { $highdart = new HighDart(); $highdart->tournament_id = $id; $highdart->player_id = $player_id; $highdart->high_dart = $high_dart; $highdart->save(); } } } $this->redirect(array('matches', 'id' => $model->id)); }
if (isset($_GET['submitScore'])) { $tournament_id = $_POST['tournamentURL']; $match_id = $_POST['matchID']; switch ($_POST['winnerSelect']) { case 'A': $winner_id = $_POST['participantA']; break; case 'B': $winner_id = $_POST['participantB']; break; default: echo 'ERROR - No winner selected'; break; } $params = array("match[scores_csv]" => $_POST['participantAScore'] . "-" . $_POST['participantBScore'], "match[winner_id]" => $winner_id); $match = $challonge->updateMatch($tournament_id, $match_id, $params); header("Location: " . $_SERVER['HTTP_REFERER']); } //Finalize Tournament if (isset($_GET['finalizeScores'])) { //Finalize the tournamet on challonge to get the final scores $params = array(); $tournament = $challonge->finalizeTournament($_POST['tournamentIDFinalURL'], $params); $params = array("include_participants" => 1); $tournament = $challonge->getTournament($_POST['tournamentIDFinalURL'], $params); foreach ($tournament->participants->participant as $thisParticipant) { switch ((string) $thisParticipant->{'final-rank'}) { case '1': $assignedTickets = 4; break; case '2':