/** * Test deleting teams to make sure they are removed from the tournament correctly afterwards */ public function test_remove_teams() { $this->get_tournament_inactive(); //Add teams that will be saved before removal for ($x = 0; $x < 8; $x++) { $this->object->team->confirm(); } //Should now have 8 teams with ids $this->assertSave($this->object->save()); $this->assertArraySize($this->object->teams(), 8); foreach ($this->object->teams as $team) { $this->assertID($team->id); } //Add teams that won't have ids when removed for ($x = 0; $x < 8; $x++) { $this->object->team->ban(); } $this->assertArraySize($this->object->teams(), 16); $this->assertArraySize($this->object->confirmed_teams(), 8); $this->assertArraySize($this->object->banned_teams(), 8); //Deleted!!! foreach ($this->object->teams as $team) { $team->delete(); } $this->assertArraySize($this->object->teams(), 0); $this->assertArraySize($this->object->confirmed_teams(), 0); $this->assertArraySize($this->object->banned_teams(), 0); //Check externally $this->AssertTournamentValueExternally($this->object, 'teams', array()); }
/** * Calculate the number of teams that will be in each group, based on * the tournament's group_count, and the number of confirmed teams * * Warning: This method should only be used before groups have started, because * Afterwards it will no longer necessarily be accurate * * Also beware that it's based on the number of teams currently confirmed in the tournament, * so it will change if you add / remove any teams before starting * * If you get a value of 0 back, it means that you don't have enough teams to fill * the groups, you should either add more teams or lower the $tournament->group_count value * * @param BBTournament $tournament * * @return int */ public static function get_group_size(BBTournament &$tournament) { //Just grab a list of confirmed team ids, and count how many we get $confirmed_ids = $tournament->confirmed_teams(true); $teams = sizeof($confirmed_ids); //Derp if ($tournament->group_count == 0) { return 0; } //Simply divide teams by groups $size = $teams / $tournament->group_count; //Not enough teams, we need at LEAST 2 teams per group if ($size < 2) { return 0; } //Success! return the rounded (up) value return ceil($size); }