Beispiel #1
0
 /**
  * Given a team ('A'/'B'), determines new team rating.
  *
  * @param string $team
  * @return float
  */
 protected function getNewTeamRating($team)
 {
     $inputRatingFunction = 'getTeam' . $team . 'Rating';
     if ($this->matchResult->getHigherTeam() == MatchResult::TEAMS_EQUAL) {
         // team's ranking points equal before game
         if ($this->matchResult->getResult() == MatchResult::DRAW) {
             // no change
             return $this->ratingsInput->{$inputRatingFunction}();
         }
         if ($this->matchResult->getResult() == $team) {
             // this team wins and gets points increase
             return $this->ratingsInput->{$inputRatingFunction}() + $this->exchange->getExchangeAmount();
         }
         // team lost
         return $this->ratingsInput->{$inputRatingFunction}() - $this->exchange->getExchangeAmount();
     }
     if ($this->matchResult->getHigherTeam() == $team) {
         // team in question is higher ranked before game
         if ($this->matchResult->getResult() == $team) {
             // team won
             return $this->ratingsInput->{$inputRatingFunction}() + $this->exchange->getExchangeAmount();
         }
         // team lost or drew, as they're higher ranked they lose points
         return $this->ratingsInput->{$inputRatingFunction}() - $this->exchange->getExchangeAmount();
     }
     // if we get here we're dealing with lower-ranked team before game
     if ($this->matchResult->getResult() == $team || $this->matchResult->getResult() == MatchResult::DRAW) {
         // lower ranked team gains points from win or draw
         return $this->ratingsInput->{$inputRatingFunction}() + $this->exchange->getExchangeAmount();
     }
     // lower ranked team lost
     return $this->ratingsInput->{$inputRatingFunction}() - $this->exchange->getExchangeAmount();
 }
Beispiel #2
0
 /**
  * Calculates rating points exchange between teams and returns it.
  *
  * @return float the points exchange
  * @throws InvalidMatchResultException if cannot determine match result
  */
 public function calculate()
 {
     $base = $this->ratingsGap / Calculate::MAX_RATINGS_GAP;
     if ($this->matchResult->isUnderdogWin() || $this->matchResult->equalsWin()) {
         $this->exchangeAmount = 1 + $base;
         $this->applyWeightings();
         return $this->exchangeAmount;
     }
     if ($this->matchResult->isHigherTeamWin()) {
         $this->exchangeAmount = 1 - $base;
         $this->applyWeightings();
         return $this->exchangeAmount;
     }
     if ($this->matchResult->getResult() == MatchResult::DRAW) {
         $this->exchangeAmount = $base;
         $this->applyWeightings();
         return $this->exchangeAmount;
     }
     throw new InvalidMatchResultException('Cannot calculate exchange: Invalid MatchResult Type');
 }
 /**
  * Gets a text description of the match result
  */
 public function GetResultDescription()
 {
     if ($this->result->GetResultType() == MatchResult::UNKNOWN) {
         return '';
     }
     $s_text = MatchResult::Text($this->result->GetResultType());
     if (is_object($this->o_home_team)) {
         $s_text = str_ireplace('Home', $this->o_home_team->GetName(), $s_text);
     }
     if (is_object($this->GetAwayTeam())) {
         $s_text = str_ireplace('Away', $this->GetAwayTeam()->GetName(), $s_text);
     }
     return $s_text;
 }
Beispiel #4
0
 public function match($uri)
 {
     if (!preg_match($this->location_rx, $uri, $matches)) {
         return MatchResult::fail();
     }
     $vars = $this->defaults;
     foreach ($this->vmap as $index => $vname) {
         if (isset($matches[$index + 1])) {
             $vars[$vname] = $matches[$index + 1];
         } elseif ($vname == 'suffix') {
             $vars['suffix'] = '';
         }
     }
     $vars['uri'] = $uri;
     $result = preg_replace_callback('~\\$([a-z0-9_]+)~', function ($m) use(&$vars) {
         $value = $vars[$m[1]];
         unset($vars[$m[1]]);
         return $value;
     }, $this->result);
     unset($vars['uri'], $vars['suffix']);
     $path = trim(preg_replace('~/{2,}~', '/', $result), '/');
     return MatchResult::success(new RoutePoint($path, $vars));
 }
 /**
  * @return void
  * @desc Create DataValidator objects to validate the edit control
  */
 function CreateValidators()
 {
     # Validate fewer options for a new season than when editing, beacause a new season gets settings copied from last year to save time
     $b_is_new_season = !(bool) $this->GetDataObject()->GetId();
     if (!$this->IsInternalPostback()) {
         require_once 'data/validation/required-field-validator.class.php';
         require_once 'data/validation/length-validator.class.php';
         require_once 'data/validation/numeric-validator.class.php';
         $this->a_validators[] = new NumericValidator('competition', 'The competition identifier should be a number');
         $this->a_validators[] = new RequiredFieldValidator('start', 'Please add the year the season starts', ValidatorMode::AllFields());
         $this->a_validators[] = new NumericValidator('start', 'The start year must be a number');
         $this->a_validators[] = new LengthValidator('start', 'The start year should be in YYYY format', 4, 4);
         $this->a_validators[] = new LengthValidator('intro', 'Please make the introduction shorter', 0, 10000);
         if (!$b_is_new_season) {
             $this->a_validators[] = new LengthValidator('results', 'Please make the results shorter', 0, 10000);
             foreach ($this->result_types as $o_result) {
                 /* @var $o_result MatchResult */
                 $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Result' . $o_result->GetResultType() . 'Home', 'The home points for ' . MatchResult::Text($o_result->GetResultType()) . ' must be a number. For example, \'2\', not \'two\'.');
                 $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Result' . $o_result->GetResultType() . 'Away', 'The away points for ' . MatchResult::Text($o_result->GetResultType()) . ' must be a number. For example, \'2\', not \'two\'.');
             }
         }
     }
     $a_aggregated_validators = array();
     if (!$b_is_new_season) {
         $a_aggregated_validators = $this->adjustments_editor->GetValidators();
         $a_aggregated_validators = array_merge($a_aggregated_validators, $this->match_types_editor->GetValidators());
         $a_aggregated_validators = array_merge($a_aggregated_validators, $this->teams_editor->GetValidators());
     }
     $this->a_validators = array_merge($this->a_validators, $a_aggregated_validators);
 }
 static function __static()
 {
     self::$EMPTY = new self(0, array());
 }
 /**
  * Sets up controls for page 4 of the wizard
  * @param Match $match
  * @return void
  */
 private function CreateHighlightsControls(Match $match)
 {
     $b_got_teams = !(is_null($match->GetHomeTeam()) || is_null($match->GetAwayTeam()));
     // Move CSS class to div element
     $match_outer_1 = new XhtmlElement('div');
     $match_outer_1->SetCssClass('matchResultEdit panel');
     $match_outer_2 = new XhtmlElement('div');
     $match_box = new XhtmlElement('div');
     $this->AddControl($match_outer_1);
     $match_outer_1->AddControl($match_outer_2);
     $match_outer_2->AddControl($match_box);
     $o_title_inner_1 = new XhtmlElement('span', "Match highlights");
     $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
     $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
     $o_heading = new XhtmlElement('h2', $o_title_inner_3);
     $match_box->AddControl($o_heading);
     # Who's playing?
     $o_home_name = new TextBox($this->GetNamingPrefix() . 'Home');
     $o_away_name = new TextBox($this->GetNamingPrefix() . 'Away');
     $o_home_name->SetMode(TextBoxMode::Hidden());
     $o_away_name->SetMode(TextBoxMode::Hidden());
     if (!is_null($match->GetHomeTeam())) {
         $o_home_name->SetText($match->GetHomeTeam()->GetId() . MatchHighlightsEditControl::DATA_SEPARATOR . $match->GetHomeTeam()->GetName());
     }
     if (!is_null($match->GetAwayTeam())) {
         $o_away_name->SetText($match->GetAwayTeam()->GetId() . MatchHighlightsEditControl::DATA_SEPARATOR . $match->GetAwayTeam()->GetName());
     }
     $this->AddControl($o_home_name);
     $this->AddControl($o_away_name);
     # When? (for validator message only)
     $when = new TextBox($this->GetNamingPrefix() . 'Date', $match->GetStartTime());
     $when->SetMode(TextBoxMode::Hidden());
     $this->AddControl($when);
     # Who won?
     $o_winner = new XhtmlSelect($this->GetNamingPrefix() . 'Result');
     $o_winner->AddControl(new XhtmlOption("Don't know", ''));
     $result_types = array(MatchResult::HOME_WIN, MatchResult::AWAY_WIN, MatchResult::TIE, MatchResult::ABANDONED);
     foreach ($result_types as $result_type) {
         if ($b_got_teams) {
             $o_winner->AddControl(new XhtmlOption($this->NameTeams(MatchResult::Text($result_type), $match->GetHomeTeam(), $match->GetAwayTeam()), $result_type));
         } else {
             $o_winner->AddControl(new XhtmlOption(MatchResult::Text($result_type), $result_type));
         }
     }
     if ($this->IsValidSubmit()) {
         if ($match->Result()->GetResultType() == MatchResult::UNKNOWN and !is_null($match->Result()->GetHomeRuns()) and !is_null($match->Result()->GetAwayRuns())) {
             # If match result is not known but we can guess from the entered scores, select it
             if ($match->Result()->GetHomeRuns() > $match->Result()->GetAwayRuns()) {
                 $o_winner->SelectOption(MatchResult::HOME_WIN);
             } else {
                 if ($match->Result()->GetHomeRuns() < $match->Result()->GetAwayRuns()) {
                     $o_winner->SelectOption(MatchResult::AWAY_WIN);
                 } else {
                     if ($match->Result()->GetHomeRuns() == $match->Result()->GetAwayRuns()) {
                         $o_winner->SelectOption(MatchResult::TIE);
                     }
                 }
             }
         } else {
             $o_winner->SelectOption($match->Result()->GetResultType());
         }
     }
     $o_win_part = new FormPart('Who won?', $o_winner);
     $match_box->AddControl($o_win_part);
     # Get current player of match
     $player = $match->Result()->GetPlayerOfTheMatch();
     $home_player = $match->Result()->GetPlayerOfTheMatchHome();
     $away_player = $match->Result()->GetPlayerOfTheMatchAway();
     $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE;
     if ($player instanceof Player) {
         $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL;
     } else {
         if ($home_player instanceof Player or $away_player instanceof Player) {
             $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY;
         }
     }
     # Choose from different types of player of the match
     require_once 'xhtml/forms/radio-button.class.php';
     $pom_container = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Player of the match', 'formLabel'));
     $pom_container->SetCssClass('formPart');
     $pom_options = new XhtmlElement('div', null, 'formControl radioButtonList');
     $pom_options->SetXhtmlId($this->GetNamingPrefix() . "PlayerOptions");
     $pom_container->AddControl($pom_options);
     $match_box->AddControl($pom_container);
     $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $this->GetNamingPrefix() . 'POM', "none chosen", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $this->IsValidSubmit()));
     $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $this->GetNamingPrefix() . 'POM', "yes, one chosen", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $this->IsValidSubmit()));
     $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $this->GetNamingPrefix() . 'POM', "yes, one from each team", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $this->IsValidSubmit()));
     # Controls for entering a single player of the match
     $player_name = new TextBox($this->GetNamingPrefix() . 'Player', $player instanceof Player ? $player->GetName() : '', $this->IsValidSubmit());
     $player_name->SetMaxLength(100);
     $player_name->AddCssClass("player");
     $player_name->AddCssClass("team" . $match->GetHomeTeamId());
     $player_name->AddCssClass("team" . $match->GetAwayTeamId());
     $player_name->AddAttribute("autocomplete", "off");
     $player_box = new XhtmlElement("div", $player_name);
     $player_team = new XhtmlSelect($this->GetNamingPrefix() . "PlayerTeam", " playing for", $this->IsValidSubmit());
     $player_team->SetCssClass("playerTeam");
     # for JS
     $player_team->AddControl(new XhtmlOption("Don't know", ""));
     $player_team->AddControl(new XhtmlOption($match->GetHomeTeam()->GetName(), $match->GetHomeTeamId()));
     $player_team->AddControl(new XhtmlOption($match->GetAwayTeam()->GetName(), $match->GetAwayTeamId()));
     if ($player instanceof Player) {
         $player_team->SelectOption($player->Team()->GetId());
     }
     $player_box->AddControl($player_team);
     $player_part = new FormPart("Player's name", $player_box);
     $player_part->SetXhtmlId($this->GetNamingPrefix() . "OnePlayer");
     $player_part->GetLabel()->AddAttribute("for", $player_name->GetXhtmlId());
     $match_box->AddControl($player_part);
     # Controls for entering home and away players of the match
     $home_box = new TextBox($this->GetNamingPrefix() . 'PlayerHome', $home_player instanceof Player ? $home_player->GetName() : '', $this->IsValidSubmit());
     $home_box->SetMaxLength(100);
     $home_box->AddCssClass("player");
     $home_box->AddCssClass("team" . $match->GetHomeTeamId());
     $home_box->AddAttribute("autocomplete", "off");
     $home_part = new FormPart($this->NameTeams('Home player', $match->GetHomeTeam(), $match->GetAwayTeam()), $home_box);
     $home_part->SetCssClass("formPart multiPlayer");
     $match_box->AddControl($home_part);
     $away_box = new TextBox($this->GetNamingPrefix() . 'PlayerAway', $away_player instanceof Player ? $away_player->GetName() : '', $this->IsValidSubmit());
     $away_box->SetMaxLength(100);
     $away_box->AddCssClass("player");
     $away_box->AddCssClass("team" . $match->GetAwayTeamId());
     $away_box->AddAttribute("autocomplete", "off");
     $away_part = new FormPart($this->NameTeams('Away player', $match->GetHomeTeam(), $match->GetAwayTeam()), $away_box);
     $away_part->SetCssClass("formPart multiPlayer");
     $match_box->AddControl($away_part);
     # Any comments?
     $comments = new TextBox($this->GetNamingPrefix() . 'Comments', '', $this->IsValidSubmit());
     $comments->SetMode(TextBoxMode::MultiLine());
     $comments->AddAttribute('class', 'matchReport');
     $comments_label = new XhtmlElement('label');
     $comments_label->AddAttribute('for', $comments->GetXhtmlId());
     $comments_label->AddCssClass('matchReport');
     $comments_label->AddControl('Add a match report:');
     $match_box->AddControl($comments_label);
     $match_box->AddControl($comments);
     if ($match->GetLastAudit() != null) {
         require_once "data/audit-control.class.php";
         $match_box->AddControl(new AuditControl($match->GetLastAudit(), "match"));
     }
     $this->SetButtonText('Save match');
 }
 protected function CreateControls()
 {
     $o_match = $this->GetDataObject();
     /* @var $o_match Match */
     $b_got_teams = !(is_null($o_match->GetHomeTeam()) || is_null($o_match->GetAwayTeam()));
     $b_future = ($o_match->GetId() and $o_match->GetStartTime() > gmdate('U'));
     // Move CSS class to div element
     $o_match_outer_1 = new XhtmlElement('div');
     if ($this->GetCssClass()) {
         $o_match_outer_1->SetCssClass('matchResultEdit ' . $this->GetCssClass());
     } else {
         $o_match_outer_1->SetCssClass('matchResultEdit');
     }
     $this->SetCssClass('');
     $o_match_outer_2 = new XhtmlElement('div');
     $o_match_box = new XhtmlElement('div');
     $this->AddControl($o_match_outer_1);
     $o_match_outer_1->AddControl($o_match_outer_2);
     $o_match_outer_2->AddControl($o_match_box);
     if ($this->GetShowHeading()) {
         $s_heading = str_replace('{0}', $o_match->GetTitle(), $this->GetHeading());
         $s_heading = str_replace('{1}', Date::BritishDate($o_match->GetStartTime(), false), $s_heading);
         $o_title_inner_1 = new XhtmlElement('span', htmlentities($s_heading, ENT_QUOTES, "UTF-8", false));
         $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
         $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
         $o_heading = new XhtmlElement($this->b_in_section ? 'h3' : 'h2', $o_title_inner_3);
         $o_match_box->AddControl($o_heading);
     }
     # Who's playing?
     $o_home_name = new TextBox($this->GetNamingPrefix() . 'Home');
     $o_away_name = new TextBox($this->GetNamingPrefix() . 'Away');
     $o_home_name->SetMode(TextBoxMode::Hidden());
     $o_away_name->SetMode(TextBoxMode::Hidden());
     if (!is_null($o_match->GetHomeTeam())) {
         $o_home_name->SetText($o_match->GetHomeTeam()->GetId() . ";" . $o_match->GetHomeTeam()->GetName());
     }
     if (!is_null($o_match->GetAwayTeam())) {
         $o_away_name->SetText($o_match->GetAwayTeam()->GetId() . ";" . $o_match->GetAwayTeam()->GetName());
     }
     $this->AddControl($o_home_name);
     $this->AddControl($o_away_name);
     # When? (for validator message only)
     $when = new TextBox($this->GetNamingPrefix() . 'Date', $o_match->GetStartTime());
     $when->SetMode(TextBoxMode::Hidden());
     $this->AddControl($when);
     # Who batted first?
     if (!$b_future) {
         $o_bat_first = new XhtmlSelect($this->GetNamingPrefix() . 'BatFirst');
         $o_bat_first->AddControl(new XhtmlOption("Don't know", ''));
         if ($b_got_teams) {
             $o_bat_first->AddControl(new XhtmlOption($o_match->GetHomeTeam()->GetName(), 'home'));
             $o_bat_first->AddControl(new XhtmlOption($o_match->GetAwayTeam()->GetName(), 'away'));
         } else {
             $o_bat_first->AddControl(new XhtmlOption('Home team', 'home'));
             $o_bat_first->AddControl(new XhtmlOption('Away team', 'away'));
         }
         if (!is_null($o_match->Result()->GetHomeBattedFirst())) {
             if ($o_match->Result()->GetHomeBattedFirst()) {
                 $o_bat_first->SelectOption('home');
             } else {
                 $o_bat_first->SelectOption('away');
             }
         }
         $o_bat_part = new FormPart('Who batted first?', $o_bat_first);
         $o_match_box->AddControl($o_bat_part);
     }
     # Who won?
     $o_winner = new XhtmlSelect($this->GetNamingPrefix() . 'Result');
     $o_winner->AddControl(new XhtmlOption($b_future ? 'The match will go ahead' : "Don't know", ''));
     $result_types = array(MatchResult::HOME_WIN, MatchResult::AWAY_WIN, MatchResult::HOME_WIN_BY_FORFEIT, MatchResult::AWAY_WIN_BY_FORFEIT, MatchResult::TIE, MatchResult::POSTPONED, MatchResult::CANCELLED, MatchResult::ABANDONED);
     if ($o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         # You don't postpone a match in a tournament for another day
         unset($result_types[array_search(MatchResult::POSTPONED, $result_types, true)]);
     }
     foreach ($result_types as $result_type) {
         if (!$b_future or MatchResult::PossibleInAdvance($result_type)) {
             if ($b_got_teams) {
                 $o_winner->AddControl(new XhtmlOption($this->NameTeams(MatchResult::Text($result_type), $o_match->GetHomeTeam(), $o_match->GetAwayTeam()), $result_type));
             } else {
                 $o_winner->AddControl(new XhtmlOption(MatchResult::Text($result_type), $result_type));
             }
         }
     }
     $o_winner->SelectOption($o_match->Result()->GetResultType());
     $o_win_part = new FormPart($b_future ? 'Will it happen?' : 'Who won?', $o_winner);
     $o_match_box->AddControl($o_win_part);
     # If the match has already happened
     if (!$b_future) {
         # What did each team score?
         $this->CreateTeamScoreControls($o_match_box, 'Home', $o_match, $o_match->GetHomeTeam(), $o_match->Result()->GetHomeRuns(), $o_match->Result()->GetHomeWickets());
         $this->CreateTeamScoreControls($o_match_box, 'Away', $o_match, $o_match->GetAwayTeam(), $o_match->Result()->GetAwayRuns(), $o_match->Result()->GetAwayWickets());
         # Any comments?
         $comments = new TextBox($this->GetNamingPrefix() . 'Comments', '', $this->IsValidSubmit());
         $comments->SetMode(TextBoxMode::MultiLine());
         $comments->AddAttribute('class', 'matchReport');
         $comments_label = new XhtmlElement('label');
         $comments_label->AddAttribute('for', $comments->GetXhtmlId());
         $comments_label->AddCssClass('matchReport');
         $comments_label->AddControl('Add a match report:');
         $o_match_box->AddControl($comments_label);
         $o_match_box->AddControl($comments);
     }
     # Show audit data
     if ($o_match->GetLastAudit() != null) {
         require_once "data/audit-control.class.php";
         $o_match_box->AddControl(new AuditControl($o_match->GetLastAudit(), "match"));
     }
 }
 function CreateControls()
 {
     $match = $this->GetDataObject();
     /* @var $match Match */
     $this->b_user_is_match_owner = ($match->GetAddedBy() instanceof User and AuthenticationManager::GetUser()->GetId() == $match->GetAddedBy()->GetId());
     $this->AddCssClass('legacy-form');
     if ($this->b_user_is_match_admin) {
         # Add match title editing
         $b_new = !$match->GetId();
         $title = new TextBox('title', $b_new ? '' : $match->GetTitle());
         $title->SetMaxLength(100);
         $this->AddControl(new FormPart('Match title', $title));
         $o_generate = new CheckBox('defaultTitle', 'Use default title', 1);
         if ($b_new) {
             $o_generate->SetChecked(true);
         } else {
             $o_generate->SetChecked(!$match->GetUseCustomTitle());
         }
         $this->AddControl($o_generate);
         # Add match type
         if ($match->GetMatchType() != MatchType::TOURNAMENT_MATCH) {
             $o_type_list = new XhtmlSelect('type');
             $o_type_list->AddControl(new XhtmlOption(MatchType::Text(MatchType::LEAGUE), MatchType::LEAGUE));
             $o_type_list->AddControl(new XhtmlOption(MatchType::Text(MatchType::PRACTICE), MatchType::PRACTICE));
             $o_type_list->AddControl(new XhtmlOption(MatchType::Text(MatchType::FRIENDLY), MatchType::FRIENDLY));
             $o_type_list->AddControl(new XhtmlOption(MatchType::Text(MatchType::CUP), MatchType::CUP));
             $o_type_list->SelectOption($match->GetMatchType());
             $this->AddControl(new FormPart('Type of match', $o_type_list));
         }
     }
     if ($this->b_user_is_match_owner or $this->b_user_is_match_admin) {
         $this->EnsureAggregatedEditors();
         $this->fixture_editor->SetDataObject($match);
         $this->AddControl($this->fixture_editor);
     }
     if ($this->b_user_is_match_admin) {
         # add season
         if (!$this->IsPostback()) {
             $this->season_editor->DataObjects()->SetItems($match->Seasons()->GetItems());
         }
         $this->AddControl($this->season_editor);
         # Hidden data on teams, for use by match-fixture-edit-control.js to re-sort teams when the season is changed
         # Format is 1,2,3,4,5;2,3,4,5,6
         # where ; separates each team, and for each team the first number identifies the team and subsequent numbers identify the season
         /* @var $o_team Team */
         /* @var $o_comp Competition */
         $s_team_season = '';
         # Build a list of all seasons, so that the "Not known yet" option can be added to all seasons
         $all_seasons = array();
         foreach ($this->fixture_editor->GetTeams() as $group) {
             foreach ($group as $o_team) {
                 if (!$o_team instanceof Team) {
                     continue;
                 }
                 # Add team id
                 if ($s_team_season) {
                     $s_team_season .= ';';
                 }
                 $s_team_season .= $o_team->GetId();
                 # add team seasons
                 foreach ($o_team->Seasons() as $team_in_season) {
                     $s_team_season .= ',' . $team_in_season->GetSeasonId();
                     $all_seasons[] = $team_in_season->GetSeasonId();
                 }
             }
         }
         # Add the "Don't know yet" option with all seasons
         $all_seasons = array_unique($all_seasons);
         $s_team_season = "0," . implode(",", $all_seasons) . ";{$s_team_season}";
         # Put it in a hidden field accessible to JavaScript.
         $o_ts = new TextBox($this->GetNamingPrefix() . 'TeamSeason', $s_team_season);
         $o_ts->SetMode(TextBoxMode::Hidden());
         $this->AddControl($o_ts);
     }
     $got_home_team = !is_null($match->GetHomeTeam());
     $got_away_team = !is_null($match->GetAwayTeam());
     $b_got_teams = ($got_home_team and $got_away_team);
     $b_future = ($match->GetId() and $match->GetStartTime() > gmdate('U'));
     // Move CSS class to div element
     $match_outer_1 = new XhtmlElement('div');
     $match_outer_1->SetCssClass('matchResultEdit panel');
     $match_outer_2 = new XhtmlElement('div');
     $match_box = new XhtmlElement('div');
     $this->AddControl($match_outer_1);
     $match_outer_1->AddControl($match_outer_2);
     $match_outer_2->AddControl($match_box);
     $o_title_inner_1 = new XhtmlElement('span', "Result of this match");
     $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
     $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
     $o_heading = new XhtmlElement('h2', $o_title_inner_3);
     $match_box->AddControl($o_heading);
     # Who batted first?
     if (!$b_future) {
         $match_box->AddControl('<h3>If the match went ahead:</h3>');
         $toss = $this->SelectOneOfTwoTeams($this->GetNamingPrefix() . 'Toss', $match, $match->Result()->GetTossWonBy() === TeamRole::Home(), $match->Result()->GetTossWonBy() === TeamRole::Away());
         $toss_part = new FormPart('Who won the toss?', $toss);
         $match_box->AddControl($toss_part);
         $bat_first = $this->SelectOneOfTwoTeams($this->GetNamingPrefix() . 'BatFirst', $match, $match->Result()->GetHomeBattedFirst() === true, $match->Result()->GetHomeBattedFirst() === false);
         $bat_part = new FormPart('Who batted first?', $bat_first);
         $match_box->AddControl($bat_part);
     }
     # Who won?
     $o_winner = new XhtmlSelect($this->GetNamingPrefix() . 'Result');
     if ($b_future) {
         $o_winner->AddControl(new XhtmlOption('The match will go ahead', ''));
     } else {
         # This option means "no change", therefore it has to have the current value for the match result even though that's
         # a different value from match to match. If it's not there the submitted match doesn't have result info, so when admin
         # saves fixture it regenerates its title as "Team A v Team B", which doesn't match the existing title so gets saved to db.
         # Can't be exactly the current value though, because otherwise a cancelled match has two options with the same value,
         # so re-selecting the option doesn't work. Instead change it to a negative number, which can be converted back when submitted.
         $o_winner->AddControl(new XhtmlOption('Not applicable &#8211; match went ahead', $match->Result()->GetResultType() * -1));
     }
     $result_types = array(MatchResult::HOME_WIN_BY_FORFEIT, MatchResult::AWAY_WIN_BY_FORFEIT, MatchResult::POSTPONED, MatchResult::CANCELLED, MatchResult::ABANDONED);
     foreach ($result_types as $result_type) {
         if (!$b_future or MatchResult::PossibleInAdvance($result_type)) {
             if ($b_got_teams) {
                 $o_winner->AddControl(new XhtmlOption($this->NameTeams(MatchResult::Text($result_type), $match->GetHomeTeam(), $match->GetAwayTeam()), $result_type));
             } else {
                 $o_winner->AddControl(new XhtmlOption(MatchResult::Text($result_type), $result_type));
             }
         }
     }
     $o_winner->SelectOption($match->Result()->GetResultType());
     if (!$b_future) {
         $match_box->AddControl('<h3 class="ifNotPlayed">Or, if the match was not played:</h3>');
     }
     $o_win_part = new FormPart($b_future ? 'Will it happen?' : 'Why not?', $o_winner);
     $match_box->AddControl($o_win_part);
     # Show audit data
     if ($match->GetLastAudit() != null) {
         require_once "data/audit-control.class.php";
         $match_box->AddControl(new AuditControl($match->GetLastAudit(), "match"));
     }
     # Remember short URL
     $o_short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $match->GetShortUrl());
     if ($this->b_user_is_match_admin) {
         $o_url_part = new FormPart('Short URL', $o_short_url);
         $this->AddControl($o_url_part);
         $this->AddControl(new CheckBox($this->GetNamingPrefix() . 'RegenerateUrl', 'Regenerate short URL', 1, !$match->GetUseCustomShortUrl(), $this->IsValidSubmit()));
     } else {
         $o_short_url->SetMode(TextBoxMode::Hidden());
         $this->AddControl($o_short_url);
     }
     if ($b_future and !$this->b_user_is_match_admin and !$this->b_user_is_match_owner) {
         $this->SetButtonText("Save result");
     }
 }
 /**
  * Manages MatchGame 
  * @param unknown $id
  */
 public function actionManage($id)
 {
     $MATCH_TYPE = 3;
     $ACTIVE = 1;
     $STATUS_EVALUANDO = 5;
     $model = $this->loadModel($id);
     if (isset($_POST['MatchResult'])) {
         $matchResultArray = array();
         $matchResultArray = $_POST['MatchResult'];
         foreach ($matchResultArray as $matchResult) {
             if (isset($matchResult['MATCH_ID']) && $matchResult['MATCH_ID'] > 0 && isset($matchResult['RESULT_ID']) && $matchResult['RESULT_ID'] > 0) {
                 $dbMatchResult = MatchResult::model()->findByPk(array('RESULT_ID' => $matchResult['RESULT_ID'], 'MATCH_ID' => $matchResult['MATCH_ID']));
             } else {
                 throw new CHttpException(400, 'The requested page does not exist.');
                 // confirm http estatus code = 400 Bad Request
             }
             if ($dbMatchResult === null) {
                 $dbMatchResult = new MatchResult();
             }
             $dbMatchResult->attributes = $matchResult;
             $dbMatchResult->save();
         }
         $model->STATUS = $STATUS_EVALUANDO;
         $model->save();
         $this->redirect(array('tournament/manageResults', 'id' => $dbMatchResult->mATCH->TOURNAMENT_ID, 'roundId' => $dbMatchResult->mATCH->GROUP));
     }
     $currentResults = $model->matchResults;
     $catResult = new CatResult();
     $catResult->TYPE_RESULT = $MATCH_TYPE;
     $catResult->ACTIVE = $ACTIVE;
     $catResults = array();
     $catResults = $catResult->search()->getData();
     $matchResults = array();
     foreach ($catResults as $_catResult) {
         $matchResult = MatchResult::model()->findByPk(array('RESULT_ID' => $_catResult->ID, 'MATCH_ID' => $id));
         if ($matchResult === null) {
             $matchResult = new MatchResult();
             $matchResult->MATCH_ID = $id;
             $matchResult->RESULT_ID = $_catResult->ID;
         }
         $matchResults[] = $matchResult;
     }
     $this->render('manage', array('model' => $model, 'matchResults' => $matchResults));
 }
 /**
  * Populates the collection of business objects from raw data
  *
  * @return bool
  * @param MySqlRawData $o_result
  */
 protected function BuildItems(MySqlRawData $o_result)
 {
     /* @var $o_season Season */
     $this->Clear();
     # use CollectionBuilder to handle duplicates
     $o_season_builder = new CollectionBuilder();
     $o_team_builder = new CollectionBuilder();
     $o_rule_builder = new CollectionBuilder();
     $o_points_builder = new CollectionBuilder();
     $o_type_builder = new CollectionBuilder();
     $o_season = null;
     while ($o_row = $o_result->fetch()) {
         # check whether this is a new season
         if (!$o_season_builder->IsDone($o_row->season_id)) {
             # store any exisiting season and reset
             if ($o_season != null) {
                 $this->Add($o_season);
                 $o_team_builder->Reset();
                 $o_rule_builder->Reset();
                 $o_points_builder->Reset();
                 $o_type_builder->Reset();
             }
             # create the new season
             $o_season = new Season($this->GetSettings());
             $this->BuildSeason($o_season, $o_row);
         }
         # Teams the first cause of multiple rows
         if (isset($o_row->team_id)) {
             if (!$o_team_builder->IsDone($o_row->team_id)) {
                 if (isset($o_team)) {
                     unset($o_team);
                 }
                 $o_team = new Team($this->GetSettings());
                 $o_team->SetId($o_row->team_id);
                 $o_team->SetName($o_row->team_name);
                 $ground = new Ground($this->GetSettings());
                 $ground->SetId($o_row->team_ground_id);
                 $o_team->SetGround($ground);
                 if (isset($o_row->team_short_url)) {
                     $o_team->SetShortUrl($o_row->team_short_url);
                 }
                 $o_season->AddTeam($o_team);
                 if (isset($o_row->withdrawn_league) and (bool) $o_row->withdrawn_league) {
                     $o_season->TeamsWithdrawnFromLeague()->Add($o_team);
                 }
             }
             # Points adjustments - should come with team and in order of team
             if (isset($o_row->point_id) and !$o_points_builder->IsDone($o_row->point_id)) {
                 $o_point = new PointsAdjustment($o_row->point_id, $o_row->points, $o_team, $o_row->reason, $o_row->points_date);
                 $o_season->PointsAdjustments()->Add($o_point);
             }
         }
         # Season rules
         if (isset($o_row->season_rule_id) and !$o_rule_builder->IsDone($o_row->season_rule_id)) {
             $o_mr = new MatchResult($o_row->match_result_id);
             $o_mr->SetHomePoints($o_row->home_points);
             $o_mr->SetAwayPoints($o_row->away_points);
             $o_season->PossibleResults()->Add($o_mr);
             unset($o_mr);
         }
         # Match types
         if (isset($o_row->season_match_type) and !$o_type_builder->IsDone($o_row->season_match_type)) {
             $o_season->MatchTypes()->Add((int) $o_row->season_match_type);
         }
     }
     # store final season
     if ($o_season != null) {
         $this->Add($o_season);
     }
     return true;
 }
 public function __construct()
 {
     parent::__construct(false);
 }