/** * Attempt to extract data sent from a BinaryBeast callback * * <br /> * This method will try to extract the data from $_POST and $_GET, and then * process the data further based on the event_id * * <br /><br /> * For example if a tourney_info array is provided, you'll get a full {@link BBTournament} instance * * * @return BBCallbackHandlerObject|boolean * <b>FALSE</b> returned if unable to find any relevent data in $_POST and $_GET * * <br /><br /> * Refer to the properties documented in {@link BBCallbackObject} for values that you can expect * * <br /><br /> * In additon to the standard values in {@link BBCallbackObject}, each event may return data that this method will convert into <b>model objects</b><br/ > * For example, if the callback sends a tourney_info array, you can expect <var>$tournament</var> to be a {@link BBTournament} model object * * <br /><br /> * Events that expect these values are documented in each event_id constant in this class */ public function handle_callback() { //Prepare the object we'll be returning $data = new stdClass(); //Figure out if we should use $_POST or $_GET, then save a refernece to $request $request = null; if (isset($_POST['callback_id'])) { $request =& $_POST; } else { if (isset($_GET['callback_id'])) { $request =& $_GET; } else { return $this->bb->set_error('Unable to locate a "callback_id" value in either $_POST or $_GET'); } } //All standard callback values must be present $keys = array('callback_id', 'event_id', 'event_description', 'event_utc_date'); foreach ($keys as $key) { if (!isset($request[$key])) { return $this->bb->set_error('Unable to locate a "' . $key . '" value, unable to process this as a valid callback', 'BBCallback'); } $data->{$key} = $request[$key]; } //Try to extract a tournament if (isset($request['tourney_info'])) { $data->tournament = $this->bb->tournament($request); } else { if (strpos($request['trigger_id'], 'x') === 0) { $data->tournament = $this->bb->tournament($request['trigger_id']); } else { if (isset($request['tourney_id'])) { $data->tournament = $this->bb->tournament($request['tourney_id']); } } } //Try to extract a match if (isset($request['match_info'])) { if (isset($request['games'])) { $data->match = $this->bb->match($request); } } else { if (isset($request['tourney_match_id'])) { $data->match = $this->bb->match($request['tourney_match_id']); } } //Try to extract a team if (isset($request['team_info'])) { $data->team = $this->bb->team($request); } else { if (isset($request['tourney_team_id'])) { $data->team = $this->bb->team($request['tourney_team_id']); } } //Success! return $data; }
/** * Test to make sure that BBModels do not allow * loading data from a specific ID, if it already had an ID and you are * specifying a new one */ public function test_load_different_id() { $tournament = $this->object->tournament(); $tournament->title = 'load() test'; $this->assertSave($tournament->save()); $tournament2 = $this->object->tournament(); $tournament2->title = 'load() test'; $this->assertSave($tournament2->save()); $this->assertFalse($tournament->load($tournament2->id)); $this->assertFalse($tournament2->load($tournament->id)); $tournament->delete(); $tournament2->delete(); }
* @package BinaryBeast * @subpackage Examples * * @version 1.0.0 * @date 2013-04-13 * @since 2013-04-13 * @author Brandon Simmons <*****@*****.**> */ $path = str_replace('\\', '/', dirname(__FILE__)) . '/../../BinaryBeast.php'; require_once $path; $bb = new BinaryBeast(); $bb->disable_ssl_verification(); /* * First - create a tournament with brackets */ $tournament = $bb->tournament(); $tournament->title = 'API Demo - Brackets'; $tournament->description = 'Simple API PHP Library demonstration - elimination only'; $tournament->elimination = BinaryBeast::ELIMINATION_DOUBLE; // for ($x = 0; $x < 16; $x++) { $team = $tournament->team(); $team->confirm(); $team->display_name = 'Demo Player ' . ($x + 1); } // if (!$tournament->save()) { var_dump(array('Error saving tournament', 'errors' => $bb->error_history, 'results' => $bb->result_history)); die; } if (!$tournament->start()) {
* * @version 1.0.1 * @date 2013-04-13 * @author Brandon Simmons <*****@*****.**> */ //May be set from another example if (!isset($bb)) { require '../../../BinaryBeast.php'; $bb = new BinaryBeast(); $bb->disable_ssl_verification(); } /** * Process the request */ if (isset($_POST['id'])) { $tournament = $bb->tournament($_POST['id']); if (!$tournament->delete()) { var_dump(array('Error deleting tournament', 'errors' => $bb->error_history)); die; } else { die('<h1 style="color:red">Tournament (' . $_POST['id'] . ') deleted successfully!</h1>'); } } /** * Create a tournament to delete (unless provided by another example) */ if (!isset($tournament)) { require_once '../__brackets.php'; ?> <h1>Tournament Brackets (<?php echo $tournament->id;
/** * Returns a brand new unsaved tournament * @return BBTournament */ protected function get_tournament_new() { $this->tournament = $this->bb->tournament(); self::$tournaments[] =& $this->tournament; return $this->tournament; }