/** * Stores the result code from the latest API Request, so developers can * always access the latest result in $bb->result, or $bb->result(), or $bb->result_friendly etc * * @param object $result A reference to the API's response * @param string $svc Service name called * @param array $args Arguments used * @return void */ private function set_result(&$result, $svc, $args) { //Stash the new values, and try to translate the result code to be more readable $this->last_result = isset($result->result) ? $result->result : false; $this->last_friendly_result = BBHelper::translate_result($this->last_result); //Parse into an object for storage / dumping $result_history = (object) array('result' => $this->last_result, 'friendly' => $this->last_friendly_result, 'svc' => $svc, 'args' => $args); //Store it in the result history array too $this->result_history[] = $result_history; //Dump failed calls if ($this->last_result != 200) { $title = 'API Failure (' . $this->last_friendly_result . ')'; BBDev::print_error($this, $this->last_result, $title, debug_backtrace()); } }
* @author Brandon Simmons <*****@*****.**> * * * @package BinaryBeast * @subpackage Examples */ require_once '../__brackets.php'; ?> <h1>Tournament Brackets (<?php echo $tournament->id; ?> )</h1> <?php //Embed it BBHelper::embed_tournament($tournament); ?> <h1>Matches that need to be reported</h1> <?php //Now list all of the open matches $matches = $tournament->open_matches(); foreach ($matches as $match) { echo $match->team->display_name . ' vs ' . $match->team2->display_name . ' in round ' . $match->round . '<br />'; } ?> <?php //Display option of deleting the example tournament require '../delete/delete.php';
/** * Revert this match from the tournament * * That means deleting the details, and removing the teams' progress in the tournament * * Warning: you cannot unreport matches that have teams with matches AFTER this match was reported * * aka you can only unreport if neither team has progress any further in the tournament or reported any other matches * * That does not apply to group rounds however, only brackets - group rounds can be unreported at anytime before the brackets start * * @return boolean */ public function unreport() { //Derp - can't unreport if not reported yet if (is_null($this->id)) { return $this->set_error('Can\'t unreport a match that hasn\'t been reported yet!'); } //Only possible from the tournament's current stage if (!BBHelper::bracket_matches_tournament_status($this->tournament(), $this->bracket)) { return $this->set_error('This match was played a previous stage of the touranment, and therefore can no longer be changed'); } //If NOT from the group rounds, we must make sure that neither team has reported any wins after this match if ($this->bracket !== 0) { $team1 =& $this->team(); $team2 =& $this->opponent(); if (is_null($team1->last_match())) { return false; } if (is_null($team2->last_match())) { return false; } if ($this->team->last_match->id != $this->id) { return $this->set_error("You cannot unreport this match, because there are depedent matches that have been reported by team {$this->team->id} after this match, check \$match->team->last_match for details"); } if ($this->opponent->last_match->id != $this->id) { return $this->set_error("You cannot unreport this match, because there are depedent matches that have been reported by team {$this->opponent->id} after this match, check \$match->team2->last_match for details"); } } //GOGOGO! $result = $this->call(self::SERVICE_UNREPORT, array('tourney_team_id' => $this->team->id, 'o_tourney_team_id' => $this->opponent->id)); //Failure! if ($result->result != BinaryBeast::RESULT_SUCCESS) { return false; } //Success! Simply set the id to null, we can leave the rest as-is $this->set_id(null); //Remove ids from each game foreach ($this->games as &$game) { $game->set_id(null); } //Wipe out all cached opponent / open match cache from the tournament $this->tournament->clear_match_cache(); //Flag the teams for a reload (wins / lbwins etc may have changed), and reset opponent / match values etc, to force a fresh query next time they're accessed $this->team->flag_reload(); $this->opponent->flag_reload(); // $this->team->reset_opponents(); $this->opponent->reset_opponents(); return true; }
/** * Overloaded so that we can validate the value of best_of, * and re-calculate the wins_needed when it changes * * @ignore * {@inheritdoc} */ public function __set($name, $value) { //Make sure that when setting best_of, that it's a valid value if ($name == 'best_of') { $value = BBHelper::get_best_of($value); //Store directly into $data - if we reset, it'll be overwritten automatically $this->data['wins_needed'] = BBHelper::get_wins_needed($value); } //setting map_id - change map instead if ($name == 'map_id') { $name = 'map'; } //Let the default method handle the rest parent::__set($name, $value); }
/** * Used by confirm, unconfirm, and ban to change the status of this eam * @param int $status * @param string $svc * @return boolean */ private function set_status($status, $svc) { //Orphaned team if ($this->orphan_error()) { return false; } //No change if ($this->data['status'] == $status) { return true; } //Tournament already started if (BBHelper::tournament_is_active($this->tournament)) { return $this->set_error('Cannot change team status after tournament has already started!'); } //Not a real team yet, just change the status to 1 if (is_null($this->id)) { $this->set_new_data('status', $status); return true; } //Let the API handle the rest $result = $this->call($svc, array('tourney_team_id' => $this->id)); if ($result->result != BinaryBeast::RESULT_SUCCESS) { return $this->set_error('Unable to set team ' . $this->id . ' status to ' . BBHelper::translate_team_status($status)); } //Success! $this->set_current_data('status', $svc); return true; }
/** * Fetch the data object that determines the group round matchups / fixtures and results directly * * @return BBGroupsObject|boolean * Returns false if tournament has no groups to draw */ public function &groups() { //Already set if (!is_null($this->brackets)) { return $this->brackets; } //Failure if (!BBHelper::tournament_has_group_rounds($this)) { $this->set_error('This tournament does not have any groups to load!'); return $this->bb->ref(false); } //GOGOGO! $result = $this->call(self::SERVICE_LOAD_GROUPS, array('tourney_id' => $this->id), self::CACHE_TTL_DRAW, self::CACHE_OBJECT_TYPE, $this->id); //Failure! if ($result->result != BinaryBeast::RESULT_SUCCESS) { $this->set_error('Error returned from the API when calling the bracket drawing service, please refer to $bb->result_history for details'); return $this->bb->ref(false); } /* * Success! * * Now pass each returned match through process_draw_match, * which will attempt to convert the values into Model objects, * save the result in brackets, keyed by the group label */ $this->groups = new stdClass(); foreach ($result->fixtures as $group => $rounds) { $group = strtolower($group); $this->groups->{$group} = array(); foreach ($rounds as $round => $matches) { $this->groups->{$group}[$round] = array(); foreach ($matches as $match) { $this->groups->{$group}[$round][] = $this->process_drawn_match($match); } } } //Success! now return the result return $this->groups; }