/**
  * Removes maps from the map pool, using map_ids
  *
  * @covers BBTournament::remove_map
  */
 public function test_remove_id()
 {
     $this->test_add_id();
     $this->AssertTrue($this->object->remove_map(125));
     $this->assertArraySize($this->object->map_pool, 0);
     $this->assertSave($this->object->save());
     $this->assertArraySize($this->object->map_pool, 0);
     $fresh = $this->bb->tournament($this->object->id);
     $this->assertArraySize($fresh->map_pool, 0);
 }
 /**
  * Test reporting wins, by fetching open_match objects from a group-rounds draw
  */
 public function test_report_from_groups()
 {
     $this->get_tournament_with_open_matches(true);
     $this->assertTrue(is_object($groups = $this->object->groups()));
     //Grab the first match in group A
     $this->assertInstanceOf('BBMatch', $match = $groups->a[0][0]->match);
     //Grab winner / loser objects, verify they're matching up with values in the draw
     $this->assertInstanceOf('BBTeam', $winner = $match->team());
     $this->assertInstanceOf('BBTeam', $loser = $match->team2());
     $this->assertEquals($groups->a[0][0]->team, $winner);
     $this->assertEquals($groups->a[0][0]->opponent, $loser);
     //Report the match
     $this->assertTrue($match->set_winner($winner));
     //GOGOGO!
     $this->assertSave($match->report());
     //The original match object should have updated itself
     $this->assertEquals($match->id, $groups->a[0][0]->match->id);
 }
Example #3
0
 /**
  * Determines if the given team (Can provide either team_id integer or BBTeam object)
  *  is part of this match
  * 
  * If the team is in this match, the BBTeam object is returned
  *
  * If it's NOT part of this team, false is returned
  *
  * @param BBTeam|int $team
  * @return BBTeam|boolean
  *      <b>false</b> If not part of the match
  *      <b>{@link BBTeam} object</b> If it IS part of the match
  */
 public function &team_in_match($team)
 {
     //Use BBTournament::team to standardize the input and return any obvious errors (like not belonging to the tournament)
     if (is_null($team =& $this->tournament->team($team))) {
         return $this->bb->ref(false);
     }
     //Have to return a reference, so check against team() and opponent, and return if either match
     if ($team == ($matched_team =& $this->team())) {
         return $matched_team;
     }
     if ($team == ($matched_team =& $this->opponent())) {
         return $matched_team;
     }
     //Failure!
     return $this->bb->ref(false);
 }
 /**
  * Make sure that when loading teams, we send the "json_notes" argument, so that each team
  *  automtatically has a value for notes_decoded
  * 
  * @return LocalTeam[]
  */
 public function &teams($ids = false, $args = array())
 {
     return parent::teams($ids, array_merge($args, array('json_notes' => true)));
 }
Example #5
0
 /**
  * Overloads the list-clearing method so we can
  *  specify clear tournament-object cache
  *
  * {@inheritdoc}
  */
 public function clear_list_cache()
 {
     if (!is_null($this->tournament)) {
         $this->tournament->clear_id_cache(BBTournament::SERVICE_LOAD_ROUNDS);
     }
 }
 /**
  * Tests to make sure __toString returns a string as expected
  * 
  * @covers BBModel::__toString
  */
 public function test_to_string()
 {
     $this->assertTrue(is_string($this->object->__toString()));
     echo $this->object;
 }
Example #7
0
 /**
  * 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);
 }
 /**
  * Returns the BBTeam object of the winner of this game
  * 
  * This method will also seutp the value for loser, used by 
  *      loser() to keep the code DRY
  * 
  * If false is returned, it indicates a draw
  * 
  * @return BBTeam
  *      false if game is a draw
  *      null if not yet defined
  */
 public function &winner()
 {
     //Already cached
     if (!is_null($this->winner) || $this->winner === false) {
         return $this->winner;
     }
     //No winner defined
     if (is_null($id = $this->data['tourney_team_id'])) {
         //If this is a new object, it means no winner was set
         if (is_null($this->id)) {
             $this->set_error('Winner/Loser not defined for this game');
             return $this->bb->ref(null);
         }
         //Existing game - null team id means that this game was a draw
         $this->winner = false;
         $this->loser = false;
         return $this->bb->ref(false);
     }
     //Try to load from the tournament, return directly since null is returned if the id is invalid anyway
     $this->winner =& $this->tournament->team($id);
     //Now that we have a winner, use match::toggle_team to determine the loser
     $this->loser =& $this->match->toggle_team($this->winner);
     //If null or false, I don't want it returned by reference - wrap it in ref()
     if (is_null($this->winner) || $this->winner === false) {
         return $this->bb->ref($this->winner);
     }
     return $this->winner;
 }
Example #9
0
 /**
  * Adds 8 confirmed teams to the tournament reference
  * @param BBTournament  $tournament
  * @param boolean       $save
  */
 protected function add_tournament_teams(BBTournament &$tournament, $save = true)
 {
     //Must start with an ID
     $this->assertSave($tournament->save());
     //Add 8 players
     $countries = array('USA', 'GBR', 'USA', 'NOR', 'JPN', 'SWE', 'NOR', 'GBR');
     for ($x = 0; $x < 8; $x++) {
         $team = $tournament->team();
         $team->confirm();
         $team->display_name = 'Player ' . ($x + 1);
         $team->country_code = $countries[$x];
     }
     if ($save) {
         $this->assertTrue($tournament->save_teams());
     }
 }