/**
  * Tests removing a child with $preserve disabled, and checking to make sure
  *  that any references are set to null
  * 
  * @covers BBTournament::remove_child
  * @covers BBModel::remove_child
  * @group bbmodel
  */
 public function test_remove_child_unpreserved()
 {
     $this->get_tournament_inactive();
     $team =& $this->object->team();
     $this->assertTrue(in_array($team, $this->object->teams()));
     $this->assertTrue($this->object->remove_child($team, null, false));
     //
     $this->assertNull($team);
 }
 /**
  * Test team()'s ability to return the object of an existing team
  */
 public function test_team_id()
 {
     $this->get_tournament_ready();
     $team = $this->object->teams[0];
     $this->assertEquals($team, $this->object->team($team->id));
 }
Beispiel #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);
 }
Beispiel #4
0
 /**
  * Returns the BBTeam object of this team's current opponent
  * 
  * Returns false if this teams has been eliminated
  * 
  * returns null if this team is currently waiting on an opponent
  * 
  * IMPORTANT NOTE: If this tournament is configured to use group_rounds,
  *      there may be several opponents currently waiting to play agains this team,
  *		If that's the case, then the this method will simply return the first one found
  * 
  * @return BBTeam
  *      null indicates that this team currently has no opponent, if the tournament is active it means he's waiting for another match to finish
  *      false indicates that this team has been eliminated, you can use elimianted_by to see by whome
  */
 public function &opponent()
 {
     //Orphaned team
     if ($this->orphan_error()) {
         return $this->bb->ref(null);
     }
     //Value already set
     if (!is_null($this->opponent) || $this->opponent === false) {
         return $this->opponent;
     }
     //Tournament is not active, can't possibly have an opponent - derp
     if (!BBHelper::tournament_is_active($this->tournament)) {
         return $this->bb->ref($this->set_error('Tournament is not even active yet, impossible to determine a team\'s current opponent!'));
     }
     //Ask the API - cache it as tournament cache
     $result = $this->call(self::SERVICE_GET_OPPONENT, array('tourney_team_id' => $this->id), self::CACHE_TTL_OPPONENTS, self::CACHE_OBJECT_TYPE, $this->id);
     //Default to false, unless we determine otherwise
     $this->eliminated_by =& $this->bb->ref(false);
     //Found him!
     if ($result->result == 200) {
         $this->opponent =& $this->tournament->team($result->o_tourney_team_id);
     } else {
         if ($result->result == 735) {
             $this->opponent = false;
             $this->eliminated_by =& $this->tournament->team($result->victor->tourney_team_id);
             $this->set_error('Team has been eliminated! see $team->eliminated_by to see who defeated this team');
         } else {
             if ($result->result == 734) {
                 $this->set_error('Team ' . $this->id . ' is currently waiting on an opponent');
             }
         }
     }
     return $this->opponent;
 }
 /**
  * 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;
 }
 /**
  * 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());
     }
 }