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;
}
Ejemplo n.º 2
0
//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);
$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 = str_replace(' ', '', $tourney_name);
// TODO: invent good url scheme
// DEBUG CODE ONLY
// print $tourney_name;
// print $tourney_type;
// print $tourney_descriptions;
// print $tourney_url;
// END DEBUG CODE
// 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);
// *************************
// update GFC with returned tournament ID
// *************************
// get challonge id from xml result
// load result in dom
$return = new SimpleXMLElement($c->result);
// retreive new tournament id and set to variable
$challonge_id = $return->tournament->id;
// load GFC drupal tournament and update field
// set value
$wrapper->field_tournament_challonge_url->set($challonge_id);
// save value
$wrapper->save();