function createGFCTournament($mynodeidparent) { // /******************************************************************************** // //CREATE A TOURNAMENT and Update Drupal Tournaments Node with Challonge tourney ID // // Include the Challonge API Class include '/opt/bitnami/apps/drupal/htdocs/includes/challonge.class.php'; $c = new ChallongeAPI('XqrMnBPs15MvmX0izddB4zyIHKswRCoaIAyq4cTt'); // get the GFC data needed to create tourney in Challonge //$mynodeidparent = 18; //test id for debugging $node = node_load($mynodeidparent); $wrapper = entity_metadata_wrapper('node', $node); // retreive param values needed from GFC data // get tourney name $tourney_name = $wrapper->field_tournament_name->value(); // get type of play $term = taxonomy_term_load($wrapper->field_tournament_type->raw()); $wrapper2 = entity_metadata_wrapper('taxonomy_term', $term); $tourney_type = $term->name; // get description $tourney_descriptions = $wrapper->field_tournament_description->value(); //get url value $tourney_url = (string) uniqid(); //str_replace ( ' ', '', $tourney_name ); // TODO: invent good url scheme // set paramater values for challonge from GFC values $params = array("tournament[name]" => $tourney_name, "tournament[tournament_type]" => $tourney_type, "tournament[url]" => $tourney_url, "tournament[description]" => $tourney_descriptions); // call to challonge to create tournament $tournament = $c->makeCall("tournaments", $params, "post"); $tournament = $c->createTournament($params); //Save new URL value to GFC $wrapper->field_tournament_challonge_url->set($tourney_url); // save value $wrapper->save(); // ************************* // update GFC with returned tournament ID // ************************* //****************NOTE: Need to reload by URL value from CHALLONGE due to bug $tournament_id = $tourney_url; $params = array("include_matches " => 0); $tournament = $c->makeCall("tournaments/{$tournament_id}", $params, "get"); $tournament = $c->getTournament($tournament_id, $params); // retreive new tournament id and set to variable $challonge_id = (int) $tournament->id; // id set value $wrapper->field_tournament_challonge_id->set($challonge_id); //set url value // save value $wrapper->save(); return $c->result; }
//header('Content-type: application/xml'); // Include the class on your page somewhere require $_SERVER['DOCUMENT_ROOT'] . '/includes/modules/tournamentManagement/challonge.class.php'; // Create a new instance of the API wrapper. Pass your API key into the constructor // You can view/generate your API key on the 'Password / API Key' tab of your account settings page. $c = new ChallongeAPI('vbAqvSEkokYx74ZIIMP7wUgVZLOzq7VzgF2CBetW'); /* For whatever reason (example: developing locally) if you get a SSL validation error from CURL, you can set the verify_ssl attribute of the class to false (defualts to true). It is highly recommended that you **NOT** do this on a production server. */ $c->verify_ssl = true; $tournament_id = 'testtournamentlanops'; $params = array("include_matches " => 0); $tournament = $c->makeCall("tournaments/{$tournament_id}", $params, "get"); $tournament = $c->getTournament($tournament_id, $params); echo '<pre>'; print_r($c->result); echo '</pre>'; // MATCHES EXAMPLES // ************************ // Get all matches for a tournament // http://challonge.com/api/tournaments/:tournament/matches $matches = $c->makeCall("tournaments/{$tournament_id}/matches", $params); $matches = $c->getMatches($tournament_id, $params); echo '<pre>'; print_r($c->result); echo '</pre>'; $participants = $c->makeCall("tournaments/{$tournament_id}/participants"); $participants = $c->getParticipants($tournament_id); echo '<pre>';
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': $assignedTickets = 3; break; case '3': $assignedTickets = 2; break; default: $assignedTickets = 1; break; }