/** * Returns an object containing the format for each round within this tournament, in the following layout: * {winners => [0 => {best_of=>3, map_id=>1234, wins_needed=>2, map=>Shakuras}, 1 =>{...}...], losers =>... finals =>... bronze =>... groups=>...} * * This method takes advantage of BBModel's __get, which allows us to emulate public values that we can * intercept access attempts, so we can execute an API request to get the values first * * * Note: for new tournaments, you'll want to save() the tournament before attempting to setup the round format * * @return BBRoundObject|boolean False if it fails for any reason */ public function &rounds() { //Already instantiated if (!is_null($this->rounds)) { return $this->rounds; } //New tournaments must be saved before we can start saving child data if (is_null($this->id)) { return $this->bb->ref($this->set_error('Please execute save() before manipulating rounds or teams')); } //Ask the API for the rounds. By default, this service returns every an array with a value for each bracket $result = $this->call(self::SERVICE_LOAD_ROUNDS, array('tourney_id' => $this->tourney_id), self::CACHE_TTL_ROUNDS, self::CACHE_OBJECT_TYPE, $this->id); //Error - return false and save the result if ($result->result != BinaryBeast::RESULT_SUCCESS) { return $this->bb->ref($this->set_error($result)); } //Initialize the rounds object, use BBHelper to give us the available brackets for this tournament $this->rounds = (object) BBHelper::get_available_brackets($this, true, true); //Initialize each returned round, and store it into local properties foreach ($result->rounds as $bracket => &$rounds) { //key each round by the round label $bracket_label = BBHelper::get_bracket_label($bracket, true); //Only import rounds for relevant brackets if (!isset($this->rounds->{$bracket_label})) { continue; } //Save each new BBRound after initializing it foreach ($rounds as $round => &$format) { $new_round = $this->bb->round($format); $new_round->init($this, $bracket, $round); $this->rounds->{$bracket_label}[] = $new_round; } } //Success! return the result return $this->rounds; }