/** * Test team_in_match to make sure it returns a team, or false when appropriate */ public function test_team_in_match() { $invalid_team = $this->get_invalid_team(); $valid_team =& $this->object->team(); //Invalid - by BBTeam, and by id integer $this->assertFalse($this->object->team_in_match($invalid_team)); $this->assertFalse($this->object->team_in_match($invalid_team->id)); //Valid team - passing in the model and id $this->assertEquals($valid_team, $this->object->team_in_match($valid_team)); $this->assertEquals($valid_team, $this->object->team_in_match($valid_team->id)); }
/** * If a match is reported, this method can be called to clear any * cached opponent results this team may have saved * * @return void */ public function reset_opponents() { //If the current match was reported, save it as the last_match $this->last_match =& $this->bb->ref(null); if (!is_null($this->match)) { if ($this->match->team_in_match($this)) { if (!$this->match->is_new()) { $this->last_match = $this->match; } } } //Assign to a new reference, so that we're not changing the original team value in Tournament::$teams $this->opponent =& $this->bb->ref(null); $this->match =& $this->bb->ref(null); $this->eliminated_by =& $this->bb->ref(null); //Clear all cache for this team's ID $this->clear_id_cache(); }
/** * Defines which team won this game * * Must be a team from within the match * * You can provide either the team's integer id, or the BBTeam object * * Set winner to null to indiciate a draw * * @param BBTeam|int $winner * The winning team - can be a BBTeam instance of a tourney_team_id integer<br/ > * returns false if provided team is invalid * @param int $match_winner_score * The score of the team who won the match * @param int $match_loser_score * The score of the team who lost the match * * @return boolean * <b>False</b> if the provided team is invalid, or the winner can no longer be changed */ public function set_winner($winner, $match_winner_score = null, $match_loser_score = null) { if ($this->orphan_error()) { return false; } //Set winner as "null", indicating a draw if (is_null($winner) || $winner == false) { return $this->set_draw($match_winner_score, $match_loser_score); } //Use the match's team_in_match to give us the BBTeam, and to verify that it's actually in the match if (($winner =& $this->match->team_in_match($winner)) == false) { return $this->set_error('Invalid team selected for this game\'s winner'); } //Update the winner property $this->winner =& $winner; //Use BBMatch::toggle_team to figure out who the loser is $this->loser =& $this->match->toggle_team($this->winner); //Update the team id values $this->set_new_data('tourney_team_id', $this->winner->id); $this->set_new_data('o_tourney_team_id', $this->loser->id); //Set scores $this->set_scores($match_winner_score, $match_loser_score); //Success! return true; }