Ejemplo n.º 1
0
 /**
  * This method is used to report the results of unplayed matches
  * 
  * returns false if this match has already been played
  * 
  * Note: For new matches, you must use set_winner() to define which 
  *      team won the match
  * 
  * You also have the option of using $match->game($game_number) to save details about
  *      each individual game within this match
  * 
  * @param boolean $strict       disabled by default - if you force strict, it will
  *      only report if it validate_winner_games tells us that the match winner was given enough wins to satisfy
  *      this round's best_of setting
  * 
  * @return int		returns the id if successfully, false otherwise
  */
 public function report($strict = false)
 {
     //Already reported
     if (!is_null($this->id)) {
         return $this->set_error('This match has already been reported, please use save() if you wish to change the details');
     }
     //No winner defined
     if (!$this->winner_set) {
         return $this->set_error('Please define a winner before reporting ($team->set_winner($winning_team)) You can refer to $match->team and $match->opponent for participant details');
     }
     /**
      * Do a quick last check to make sure that this match is still in the touranment's list of open_matches,
      *  if it's not, it could be caused by a number of things - like being reported elsewhere, or the tournament advancing
      *  to the next stage etc
      */
     $tournament =& $this->tournament();
     if (!in_array($this, $tournament->open_matches())) {
         return $this->set_error('This match is no longer listed as an open match for this tournament, perhaps it was reported elsewhere, or the tournament has begun the next stage');
     }
     //We can't report the match if the round has unsaved changes, because the API may not process it correctly, as it may
     //have a different value for this round's best_of
     $format =& $this->round_format();
     if (!is_null($format)) {
         //Stop now - round has to be saved first
         if ($format->changed) {
             return $this->set_error('The round for this match has unsaved changes, please save them first (either with $round->save(), $tournament->save_rounds(), or $tournament->save()');
         }
         //Strict - validate the winner has enough game wins first
         if ($strict) {
             if (!$this->validate_winner_games($strict)) {
                 return $this->set_error('Winning team does not have enough game wins! This round requires at least ' . $format->best_of . ' game wins');
             }
         }
     }
     //Let BBModel handle this
     if (!($result = parent::save(false, array('tourney_id' => $this->tournament->id)))) {
         return false;
     }
     //Report all of the game details
     if (!$this->save_games()) {
         return $this->set_error('Error saving game details');
     }
     //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 the save() result
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Overloaded so that we can validate the value of best_of,
  *		and re-calculate the wins_needed when it changes
  * 
  * @ignore
  * {@inheritdoc}
  */
 public function __set($name, $value)
 {
     //Make sure that when setting best_of, that it's a valid value
     if ($name == 'best_of') {
         $value = BBHelper::get_best_of($value);
         //Store directly into $data - if we reset, it'll be overwritten automatically
         $this->data['wins_needed'] = BBHelper::get_wins_needed($value);
     }
     //setting map_id - change map instead
     if ($name == 'map_id') {
         $name = 'map';
     }
     //Let the default method handle the rest
     parent::__set($name, $value);
 }
Ejemplo n.º 3
0
 /**
  * Overload BBModel's reset() so we can also 
  *  reset any cached opponent / match data
  * 
  * This is important, since when reportin wins, reload() is called, which calls
  *      reset() - so we need to make sure that we honor the reaload() and re-query for
  *      opponent / eliminated_by etc
  */
 public function reset()
 {
     parent::reset();
     $this->reset_opponents();
 }
Ejemplo n.º 4
0
 /**
  * Called when something changes, so that we can decide
  *  notify parent classes of unsaved changes when appropriate
  * 
  * @ignore
  * @param bool $flag_parent
  * true by default, set to false to skip notifying the parent class of changes
  *
  * @return void
  */
 protected function flag_changed($flag_parent = true)
 {
     if ($this->orphan_error()) {
         return false;
     }
     //Determine the $changed flag
     $this->calculate_changed();
     //If we have a parent defined, let them know we either now or no longer have unsaved changes
     if (!is_null($this->parent) && $flag_parent) {
         if ($this->changed) {
             $this->parent->flag_child_changed($this);
         } else {
             $this->parent->unflag_child_changed($this);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Save the game details
  *
  * {@inheritdoc}
  */
 public function save($return_result = false, $child_args = null)
 {
     //If the match hasn't been saved yet, stop now
     if (is_null($this->match->id)) {
         return $this->set_error("You must save the entire match before saving games (\$match->save() or \$match->report())");
     }
     //Ask for the result directly, so we can import new map / race values etc
     $result = parent::save(true, array('tourney_match_id' => $this->match->id));
     if (!$result) {
         return false;
     }
     if (!is_null($result->map_id)) {
         $this->set_current_data('map_id', $result->map_id);
     }
     if (!is_null($result->race_id)) {
         $this->set_current_data('race_id', $result->race_id);
     }
     if (!is_null($result->o_race_id)) {
         $this->set_current_data('o_race_id', $result->o_race_id);
     }
     //Success!
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Revert all changes<br />
  * Overrides {@link BBModel::reset()} so we can define the $teams array for removing unsaved teams
  * {@inheritdoc}
  */
 public function reset()
 {
     //BBModel's default action first
     parent::reset();
     //Now let BBModel remove any unsaved teams from $this->teams
     $this->remove_new_children($this->teams);
 }