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; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Tournament(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Tournament'])) { $model->attributes = $_POST['Tournament']; if ($model->validate()) { // Set up the challonge tournament before we save ours. if this fails we need to stop $challonge_url = str_replace(' ', '_', strtolower($model->name)) . "_" . str_replace('/', '_', $model->date); $challone_name = $model->name . " " . $model->date; $c = new ChallongeAPI(Yii::app()->params['challonge_api']); $params = array("tournament[name]" => $challone_name, "tournament[tournament_type]" => $model->tournament_type, "tournament[url]" => $challonge_url, "tournament[sequential_pairings]" => 'true'); $tournament = $c->createTournament($params)->tournament; if (count($c->errors)) { foreach ($c->errors as $error) { Yii::app()->user->setFlash('error', "Challonge ERROR: " . $error); } } else { if (!$tournament) { Yii::app()->user->setFlash('error', "Was not able to create a tournament in the challonge software"); } else { $model->challonge_id = $tournament->id; $model->challonge_full_url = $tournament->full_challonge_url; $model->challonge_url = $tournament->url; $model->challonge_image = $tournament->live_image_url; if ($model->save()) { Yii::app()->user->setFlash('success', 'Tournament created'); $this->redirect(array('players', 'id' => $model->id)); } } } } } $this->render('create', array('model' => $model)); }
$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();
//Insert tournament into local database $thisTournament = new tournament(); $thisTournament->name = $_POST['tournamentName']; $thisTournament->eventid = $_SESSION['event']; if ($_POST['team'] == 'yes') { $thisTournament->team = 1; } else { $thisTournament->team = 0; } $thisTournament->game = $_POST['game']; $thisTournament->format = $_POST['format']; $thisTournament->participants = serialize(array()); $thisTournament->challongeurl = $tournamentURL; //Make Tournament on Challonge $params = array("tournament[name]" => $_POST['tournamentName'], "tournament[tournament_type]" => "single elimination", "tournament[url]" => $tournamentURL, "tournament[description]" => "LanOps tournament for " . $tournamentURL); $tournament = $challonge->createTournament($params); $thisTournament->save(); 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;