Exemplo n.º 1
0
 /**
  * Test to insure that a team is removed from cached results
  *  after being deleted / updated
  */
 public function test_cache()
 {
     $this->assertID($id = $this->object->save());
     $tournament = $this->object->tournament();
     $this->assertArrayContains($tournament->teams(), $this->object);
     $this->assertArrayContains($tournament->confirmed_teams(), $this->object);
     //Update
     $this->object->display_name = $name = uniqid();
     $this->object->save();
     //Test BBTeam::load()
     $this->AssertTeamValueExternally($this->object, 'display_name', $name);
     //Fetch a fresh tournament and check
     $fresh_tournament = $this->bb->tournament($tournament->id);
     $fresh = $fresh_tournament->team($id);
     $this->assertEquals($name, $fresh->display_name);
     //Delete!
     $this->object->delete();
     //Test BBTeam::load()
     $fresh = $this->bb->team($id);
     $this->assertFalse($fresh->load());
     //Test BinaryBeast::teams()
     $fresh_tournament = $this->bb->tournament($tournament->id);
     $this->assertArrayNotContains($tournament->teams(true), $id);
     $this->assertArrayNotContains($fresh_tournament->teams(true), $id);
 }
Exemplo n.º 2
0
 /**
  * Overload the data import, so that we can
  *  evaluate the value of $notes to try to find the $user_id
  */
 public function import_values($data)
 {
     //Default action first, actually import the data so we can work with it
     parent::import_values($data);
     //The api sent back the value notes_decoded - standardize it as an object if it has a value
     if (!is_null($this->notes_decoded)) {
         $this->notes_decoded = (object) $this->notes_decoded;
         //Success!
         if (isset($this->notes_decoded->user_id)) {
             $this->user_id = $this->notes_decoded->user_id;
         }
     }
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * Create a new match, or validate an existing one<br /><br />
  *
  * <br /><br />
  * Can be used 2 ways:<br /><br />
  *  <b>1)</b> Returns the open BBMatch object where the $team1 and $team2 meet,<br />
  *      it will try to return an unreported BBMatch from the open_matches array
  *
  * <br />
  *  <b>2)</b> Verifies that the provided BBMatch object is valid / part of this tournament
  *      In which case, we return the valid most up-to-date object instance possible, even if the only thing that matches
  *      from your BBMatch, is the id
  * 
  * 
  * @param int|BBTeam|BBMatch        $team1
  * <b>Possible values:</b>
  * - The <b>integer</b> ID the either team in the match
  * - The {@link BBTeam} object of either team in the match
  * - A {@link BBMatch} object - to verify that it exists and to fetch the latest and created instance, stored in our open matches array
  *  
  * @param int|BBTeam                $team2
  * <b>Possible values:</b>
  * - The <b>integer</b> ID the either team in the match (can't be the same as <var>$team1</var>)
  * - The {@link BBTeam} object of either team in the match (can't be the same as <var>$team1</var>)
  * 
  * @return BBMatch|null
  */
 public function &match($team1 = null, $team2 = null)
 {
     //If given BBMatch, verify or return null
     if ($team1 instanceof BBMatch) {
         //if unreported - check it against our open_matches list
         if ($team1->is_new()) {
             return $this->get_child($team1, $this->open_matches());
         } else {
             //Cast as a BBMatch
             $match = $this->bb->match($team1->id);
             $match->init($this);
             if ($match->tourney_id != $this->id) {
                 return $this->bb->ref(null);
             }
             //success!
             return $match;
         }
     }
     //If team1 is a number, and team 2 is null, treat team1 as a tourney_match_id
     if (is_numeric($team1) && is_null($team2)) {
         $match = $this->bb->match($team1);
         $match->init($this);
         return $match->load();
     }
     //Let open_match() take over
     return $this->open_match($team1, $team2);
 }