/** * Start the tournament!! * * Begin the next phase of the tournament<br /><br /> * * if <var>$type_id</var> is set to {@link BinaryBeast::TOURNEY_TYPE_CUP} ( (int) 1 ),<br /> * group rounds will be started the first time you call it, elimination brackets the second time<br /> * * <br /><br /> * <b>Warning: </b> You can't start with unsaved changes, call {@link save()} if you've changed anything first * * <br /><br /> * ***Seeding Methods:***<br /> * * - 'random' (group rounds): {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-groups Example} .{target:_blank} * - 'random' (brackets): {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-random Example} .{target:_blank} * - 'manual' (brackets): {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-manual Example} .{target:_blank} * - 'sports' (brackets): {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-seeded Example} .{target:_blank} * - 'balanced' (brackets): {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-seeded Example} .{target:_blank} * * <br /><br /> * There are examples available on {@link http://wiki.binarybeast.com/index.php?title=Seeding BinaryBeast.com} outlining the differences between each method * * * @param string $seeding * <br /><b>Default: </b> 'random' * * <br /> * <b>Acceptable Values:</b><br /> * <ul> * <li>'random' ({@link BinaryBeast::SEEDING_RANDOM})</li> * <li>'manual' ({@link BinaryBeast::SEEDING_MANUAL})</li> * <li>'sports' ({@link BinaryBeast::SEEDING_SPORTS})</li> * <li>'balanced' ({@link BinaryBeast::SEEDING_BALANCED})</li> * </ul> * * @param BBTeam[]|int[] $order * <br /><b>Optional</b><br /> * Only used for seeding methods <b>other than 'random'</b> * * <br /><br /> * The <b>format</b> expected can be found in the following examples: * <ul> * <li>'manual': {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-manual Example}</li> * <li>'sports': {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-seeded Example}</li> * <li>'balanced': {@link http://binarybeast.com/content/api/docs/php/class-BBTournament.html#start-brackets-seeded Example}</li> * </ul> * * @return boolean */ public function start($seeding = 'random', $order = null) { //Use BBHelper to run verify that this tournament is ready to start if (is_string($error = BBHelper::tournament_can_start($this))) { return $this->set_error($error); } //Make sure the seeding type is valid, use BBHelper - returned value of null indicates invalid seeding type if (is_null($seeding = BBHelper::validate_seeding_type($this, $seeding))) { return $this->set_error("{$seeding} is not a valid seeding method value! Valid values: 'random', 'manual', 'balanced', 'sports' for brackets, 'random' and 'manual' for groups"); } //Initialize the real $teams value we send to the API - $order is just temporary $teams = array(); /** * If we need an order or teams / seeds, we need to make sure that * all confirmed teams are provided, and nothing more */ if ($seeding != 'random') { /** * Will be supported in the future, however for now we don't allow * seeding groups with this class */ if (BBHelper::get_next_tournament_stage($this) == 'Active-Groups') { return $this->set_error('Unfortunately for the time being, seeding groups has been disabled. It will be supported in the future. However for now, only "random" is supported for group rounds'); } /** * First grab a list of teams that need to be included * * Any teams not specifically provided in $order will be random * added to the end */ $confirmed_teams = $this->confirmed_teams(true, true); //Start looping through each team provided, adding it to $teams only if it's in $confirmed_teams foreach ($order as &$team) { //If this is an actual BBTeam object, all we want is its id if ($team instanceof BBTeam) { $team = $team->id; } //Now make sure that this team is supposed to be here if (!in_array($team, $confirmed_teams) && intval($team) !== 0) { return $this->set_error("Team {$team} is a valid tourney_team_id of any team in this tournament, please include only valid team ids, or 0's to indicate a FreeWin"); } /** * Valid team! Now we need to do two things: * 1) Remove the team from confirmed_teams (so we can randomize + add any remaining teams after we're finished) * 2) Add its tourney_team_id to $teams, which is the actual value sent to BinaryBeast */ $teams[] = $team; unset($confirmed_teams[array_search($team, $confirmed_teams)]); } /** * Randomly append remaining teams */ if (sizeof($confirmed_teams) > 0) { shuffle($teams); array_push($teams, $confirmed_teams); } } else { $order = null; } //GOGOGO! $result = $this->call(self::SERVICE_START, array('tourney_id' => $this->id, 'seeding' => $seeding, 'teams' => $teams)); //oh noes! if ($result->result !== BinaryBeast::RESULT_SUCCESS) { return false; } /** * Started successfully! * Now we update our status value, and reload the teams array * * Conveniently the API actually sends back the new status, so we'll use that to update our local values */ $this->set_current_data('status', $result->status); //Reload all data that would likely change from a major update like this (open matches, teams) $this->handle_major_update(); //Success! return true; }