コード例 #1
0
 /**
  * Revert this match from the tournament
  * 
  * That means deleting the details, and removing the teams' progress in the tournament
  * 
  * Warning: you cannot unreport matches that have teams with matches AFTER this match was reported
  * 
  * aka you can only unreport if neither team has progress any further in the tournament or reported any other matches
  * 
  * That does not apply to group rounds however, only brackets - group rounds can be unreported at anytime before the brackets start
  * 
  * @return boolean
  */
 public function unreport()
 {
     //Derp - can't unreport if not reported yet
     if (is_null($this->id)) {
         return $this->set_error('Can\'t unreport a match that hasn\'t been reported yet!');
     }
     //Only possible from the tournament's current stage
     if (!BBHelper::bracket_matches_tournament_status($this->tournament(), $this->bracket)) {
         return $this->set_error('This match was played a previous stage of the touranment, and therefore can no longer be changed');
     }
     //If NOT from the group rounds, we must make sure that neither team has reported any wins after this match
     if ($this->bracket !== 0) {
         $team1 =& $this->team();
         $team2 =& $this->opponent();
         if (is_null($team1->last_match())) {
             return false;
         }
         if (is_null($team2->last_match())) {
             return false;
         }
         if ($this->team->last_match->id != $this->id) {
             return $this->set_error("You cannot unreport this match, because there are depedent matches that have been reported by team {$this->team->id} after this match, check \$match->team->last_match for details");
         }
         if ($this->opponent->last_match->id != $this->id) {
             return $this->set_error("You cannot unreport this match, because there are depedent matches that have been reported by team {$this->opponent->id} after this match, check \$match->team2->last_match for details");
         }
     }
     //GOGOGO!
     $result = $this->call(self::SERVICE_UNREPORT, array('tourney_team_id' => $this->team->id, 'o_tourney_team_id' => $this->opponent->id));
     //Failure!
     if ($result->result != BinaryBeast::RESULT_SUCCESS) {
         return false;
     }
     //Success! Simply set the id to null, we can leave the rest as-is
     $this->set_id(null);
     //Remove ids from each game
     foreach ($this->games as &$game) {
         $game->set_id(null);
     }
     //Wipe out all cached opponent / open match cache from the tournament
     $this->tournament->clear_match_cache();
     //Flag the teams for a reload (wins / lbwins etc may have changed), and reset opponent / match values etc, to force a fresh query next time they're accessed
     $this->team->flag_reload();
     $this->opponent->flag_reload();
     //
     $this->team->reset_opponents();
     $this->opponent->reset_opponents();
     return true;
 }