public function __construct(array $performance_data, $first_result = 1)
 {
     $this->performance_data = $performance_data;
     $this->first_result = (int) $first_result;
     parent::XhtmlTable();
     $this->SetCssClass("bowling");
     if (count($performance_data) > 0) {
         $performance = $performance_data[0];
         # Create the table header
         $this->SetCaption("Most wickets by a bowling and catching combination");
         $fields = array();
         $position = new XhtmlCell(true, "#");
         $position->SetCssClass("position");
         $fields[] = $position;
         $bowler = new XhtmlCell(true, "Bowler");
         $bowler->SetCssClass("player");
         $fields[] = $bowler;
         $catcher = new XhtmlCell(true, "Catcher");
         $catcher->SetCssClass("player");
         $fields[] = $catcher;
         $team = new XhtmlCell(true, "Team");
         $fields[] = $team;
         $matches = new XhtmlCell(true, 'Matches <span class="qualifier">(where wickets were taken)</span>');
         $matches->SetCssClass("numeric");
         $fields[] = $matches;
         $wickets = new XhtmlCell(true, "Wickets");
         $wickets->SetCssClass("numeric");
         $fields[] = $wickets;
         $header = new XhtmlRow($fields);
         $header->SetIsHeader(true);
         $this->AddRow($header);
     }
 }
 function OnPreRender()
 {
     /* @var $o_season Season */
     /* @var $o_team Team */
     $this->SetCaption($this->o_competition->GetName());
     $o_headings = new XhtmlRow(array('Name of team', 'Ground address', 'Contact details'));
     $o_headings->SetIsHeader(true);
     $this->AddRow($o_headings);
     foreach ($this->o_competition->GetLatestSeason()->GetTeams() as $o_team) {
         if ($o_team instanceof Team) {
             $o_row = new XhtmlRow();
             $o_row->AddCell(new XhtmlAnchor(Html::Encode($o_team->GetName()), $o_team->GetEditTeamUrl()));
             $o_row->AddCell(new PostalAddressControl($o_team->GetGround()->GetAddress()));
             $private = $o_team->GetPrivateContact();
             $public = $o_team->GetContact();
             $private_header = '<h2 style="margin:0; font-size:1.1em; color: #900;">Private</h2>';
             if ($private and $public) {
                 $contact = $public . $private_header . $private;
             } else {
                 $contact = $private ? $private_header . $private : $public;
             }
             $o_row->AddCell(nl2br(XhtmlMarkup::ApplySimpleTags(XhtmlMarkup::ApplyLinks($contact, true))));
             $this->AddRow($o_row);
         }
     }
     parent::OnPreRender();
 }
 public function OnPreRender()
 {
     if ($this->matches_with_run_data < 1) {
         $this->SetVisible(false);
         return;
     }
     # Add table of runs
     $this->SetCssClass('runTable');
     $this->SetCaption("Team runs");
     $total_header = new XhtmlCell(true, "Total");
     $total_header->SetCssClass("numeric");
     $run_header = new XhtmlRow(array(new XhtmlCell(true, "Statistic"), $total_header));
     $run_header->SetIsHeader(true);
     $this->AddRow($run_header);
     $matches_cell = new XhtmlCell(false, $this->matches_with_run_data);
     $matches_cell->SetCssClass('numeric');
     $matches_row = new XhtmlRow(array(new XhtmlCell(false, "matches with runs recorded"), $matches_cell));
     $this->AddRow($matches_row);
     if (!is_null($this->runs_scored)) {
         $scored_cell = new XhtmlCell(false, $this->runs_scored);
         $scored_cell->SetCssClass('numeric');
         $scored_row = new XhtmlRow(array(new XhtmlCell(false, "runs scored"), $scored_cell));
         $this->AddRow($scored_row);
     }
     if (!is_null($this->runs_conceded)) {
         $conceded_cell = new XhtmlCell(false, $this->runs_conceded);
         $conceded_cell->SetCssClass('numeric');
         $this->AddRow(new XhtmlRow(array(new XhtmlCell(false, "runs conceded"), $conceded_cell)));
     }
     if (!is_null($this->runs_scored) and !is_null($this->runs_conceded)) {
         $run_difference = $this->runs_scored - $this->runs_conceded;
         if ($run_difference > 0) {
             $run_difference = "+" . $run_difference;
         }
         $difference_cell = new XhtmlCell(false, $run_difference);
         $difference_cell->SetCssClass('numeric');
         $this->AddRow(new XhtmlRow(array(new XhtmlCell(false, "run difference"), $difference_cell)));
     }
     if (!is_null($this->highest_innings)) {
         $best_cell = new XhtmlCell(false, $this->highest_innings);
         $best_cell->SetCssClass('numeric');
         $scored_row = new XhtmlRow(array(new XhtmlCell(false, "highest innings"), $best_cell));
         $this->AddRow($scored_row);
     }
     if (!is_null($this->lowest_innings)) {
         $worst_cell = new XhtmlCell(false, $this->lowest_innings);
         $worst_cell->SetCssClass('numeric');
         $scored_row = new XhtmlRow(array(new XhtmlCell(false, "lowest innings"), $worst_cell));
         $this->AddRow($scored_row);
     }
     if (!is_null($this->average_innings)) {
         $average_cell = new XhtmlCell(false, round($this->average_innings, 0));
         $average_cell->SetCssClass('numeric');
         $average_row = new XhtmlRow(array(new XhtmlCell(false, "average innings"), $average_cell));
         $this->AddRow($average_row);
     }
     parent::OnPreRender();
 }
 public function __construct($caption, array $performance_data, $first_result = 1, $show_position = false)
 {
     $this->performance_data = $performance_data;
     $this->first_result = (int) $first_result;
     $this->show_position = (bool) $show_position;
     parent::XhtmlTable();
     if (count($performance_data) > 0) {
         $performance = $performance_data[0];
         # Create the table header
         $this->SetCaption($caption);
         $this->SetCssClass('player-performances');
         $fields = array();
         if ($show_position) {
             $position = new XhtmlCell(true, "#");
             $position->SetCssClass("position");
             $fields[] = $position;
         }
         $player = new XhtmlCell(true, "Player");
         $player->SetCssClass("player");
         $fields[] = $player;
         $match = new XhtmlCell(true, "Match");
         $fields[] = $match;
         $when = new XhtmlCell(true, "When");
         $fields[] = $when;
         if (array_key_exists("runs_scored", $performance)) {
             $runs = new XhtmlCell(true, "Batting");
             $runs->SetCssClass("numeric");
             $fields[] = $runs;
         }
         if (array_key_exists("wickets", $performance)) {
             $bowling = new XhtmlCell(true, "Bowling");
             $bowling->SetCssClass("numeric");
             $fields[] = $bowling;
         }
         if (array_key_exists("catches", $performance)) {
             $catches = new XhtmlCell(true, "Catches");
             $catches->SetCssClass("numeric");
             $fields[] = $catches;
         }
         if (array_key_exists("run_outs", $performance)) {
             $runouts = new XhtmlCell(true, "Run-outs");
             $runouts->SetCssClass("numeric");
             $fields[] = $runouts;
         }
         $header = new XhtmlRow($fields);
         $header->SetIsHeader(true);
         $this->AddRow($header);
     }
 }
 /**
  * Create a BowlingPerformanceTable
  * @param $bowling_data Bowling[]
  * @param $display_team bool
  * @param int $first_result
  * @param int $max_results
  * @return void
  */
 public function __construct($bowling_data, $display_team = true, $first_result = 1, $max_results = null)
 {
     $this->bowling_data = $bowling_data;
     $this->display_team = (bool) $display_team;
     $this->first_result = (int) $first_result;
     if (!is_null($max_results)) {
         $this->max_results = (int) $max_results;
     }
     parent::XhtmlTable();
     # Create the table header
     $this->SetCaption(is_null($max_results) ? "All bowling performances, best first" : "Best bowling performances");
     $this->SetCssClass('statsOverall bowling');
     $position = new XhtmlCell(true, "#");
     $position->SetCssClass("position");
     $player = new XhtmlCell(true, "Player");
     $player->SetCssClass("player");
     if ($display_team) {
         $team = new XhtmlCell(true, "Team");
         $team->SetCssClass("team");
     }
     $opposition = new XhtmlCell(true, "Opposition");
     $opposition->SetCssClass("team");
     $when = new XhtmlCell(true, "When");
     $when->SetCssClass("date");
     $wickets = new XhtmlCell(true, $display_team ? '<abbr title="Wickets">Wkts</abbr>' : "Wickets");
     $wickets->SetCssClass("numeric");
     $runs = new XhtmlCell(true, "Runs");
     $runs->SetCssClass("numeric");
     if ($display_team) {
         $best_bowling_header = new XhtmlRow(array($position, $player, $team, $opposition, $when, $wickets, $runs));
     } else {
         $best_bowling_header = new XhtmlRow(array($position, $player, $opposition, $when, $wickets, $runs));
     }
     $best_bowling_header->SetIsHeader(true);
     $this->AddRow($best_bowling_header);
 }
 /**
  * Create a BattingInningsTable
  * @param $batting_data Batting[]
  * @param $display_team bool
  * @param int $first_result
  * @param int $max_results
  * @return void
  */
 public function __construct($batting_data, $display_team = true, $first_result = 1, $max_results = null)
 {
     $this->batting_data = $batting_data;
     $this->display_team = (bool) $display_team;
     $this->first_result = (int) $first_result;
     if (!is_null($max_results)) {
         $this->max_results = (int) $max_results;
     }
     parent::XhtmlTable();
     # Create the table header
     $this->SetCaption("Highest individual scores");
     $this->SetCssClass('statsOverall');
     $position = new XhtmlCell(true, "#");
     $position->SetCssClass("position");
     $player = new XhtmlCell(true, "Player");
     $player->SetCssClass("player");
     if ($display_team) {
         $team = new XhtmlCell(true, "Team");
         $team->SetCssClass("team");
     }
     $opposition = new XhtmlCell(true, "Opposition");
     $opposition->SetCssClass("team");
     $when = new XhtmlCell(true, "When");
     $when->SetCssClass("date");
     $runs = new XhtmlCell(true, "Runs");
     $runs->SetCssClass("numeric");
     $balls = new XhtmlCell(true, "Balls");
     $balls->SetCssClass("numeric");
     if ($display_team) {
         $best_batting_header = new XhtmlRow(array($position, $player, $team, $opposition, $when, $runs, $balls));
     } else {
         $best_batting_header = new XhtmlRow(array($position, $player, $opposition, $when, $runs, $balls));
     }
     $best_batting_header->SetIsHeader(true);
     $this->AddRow($best_batting_header);
 }
 /**
  * Create a PlayerStatisticsTable
  * @param $caption
  * @param $column_heading
  * @param $data mixed[]
  * @param $display_team bool
  * @param int $first_result
  * @return void
  */
 public function __construct($caption, $column_heading, $data, $display_team = true, $first_result = 1)
 {
     $this->data = $data;
     $this->display_team = (bool) $display_team;
     $this->first_result = (int) $first_result;
     parent::XhtmlTable();
     if (count($data) > 0) {
         $performance = $data[0];
         # Create the table header
         $this->SetCaption($caption);
         $this->SetCssClass('statsOverall');
         $columns = array();
         $position = new XhtmlCell(true, "#");
         $position->SetCssClass("position");
         $columns[] = $position;
         $player = new XhtmlCell(true, "Player");
         $player->SetCssClass("player");
         $columns[] = $player;
         if ($display_team) {
             $team = new XhtmlCell(true, "Team");
             $team->SetCssClass("team");
             $columns[] = $team;
         }
         if (array_key_exists("total_matches", $performance)) {
             $matches = new XhtmlCell(true, "Matches");
             $matches->SetCssClass("numeric");
             $columns[] = $matches;
         }
         $aggregate = new XhtmlCell(true, $column_heading);
         $aggregate->SetCssClass("numeric");
         $columns[] = $aggregate;
         $header = new XhtmlRow($columns);
         $header->SetIsHeader(true);
         $this->AddRow($header);
     }
 }
 function OnPreRender()
 {
     /* @var $o_team Team */
     /* @var $o_match Match */
     $a_data_to_bind = array();
     $i_played = 1;
     $i_won = 2;
     $i_lost = 3;
     $i_tie = 4;
     $i_noresult = 5;
     $i_runs_for = 6;
     $i_runs_against = 7;
     $i_points = 8;
     # Build an array of teams, and initiate an array of data for each team
     foreach ($this->o_season->GetTeams() as $o_team) {
         if ($o_team instanceof Team and !is_object($this->o_season->TeamsWithdrawnFromLeague()->GetItemByProperty('GetId', $o_team->GetId()))) {
             $a_team_data = array();
             $a_team_data[0] = new XhtmlAnchor(htmlentities($o_team->GetName(), ENT_QUOTES, "UTF-8", false), $o_team->GetNavigateUrl());
             $a_team_data[$i_played] = 0;
             $a_team_data[$i_won] = 0;
             $a_team_data[$i_lost] = 0;
             $a_team_data[$i_tie] = 0;
             $a_team_data[$i_noresult] = 0;
             if ($this->o_season->GetShowTableRunsScored()) {
                 $a_team_data[$i_runs_for] = 0;
             }
             if ($this->o_season->GetShowTableRunsConceded()) {
                 $a_team_data[$i_runs_against] = 0;
             }
             $a_team_data[$i_points] = 0;
             $a_data_to_bind[$o_team->GetId()] =& $a_team_data;
             unset($a_team_data);
         }
     }
     # Look at matches to build data for each team
     foreach ($this->o_season->GetMatches() as $o_match) {
         # Discount matches in the future
         if ($o_match->GetStartTime() >= gmdate('U')) {
             break;
         }
         # Discount non-league matches
         if ($o_match->GetMatchType() != MatchType::LEAGUE) {
             continue;
         }
         # Discount postponed matches
         if ($o_match->Result()->GetResultType() == MatchResult::POSTPONED) {
             continue;
         }
         # Discount matches where a team has withdrawn from the league
         if (is_object($this->o_season->TeamsWithdrawnFromLeague()->GetItemByProperty('GetId', $o_match->GetHomeTeamId()))) {
             continue;
         }
         if (is_object($this->o_season->TeamsWithdrawnFromLeague()->GetItemByProperty('GetId', $o_match->GetAwayTeamId()))) {
             continue;
         }
         # Make a note of missing results, to excuse inaccuracies
         if ($o_match->Result()->GetResultType() == MatchResult::UNKNOWN) {
             $this->a_results_missing[] = '<a href="' . Html::Encode($o_match->GetNavigateUrl()) . '">' . Html::Encode($o_match->GetTitle()) . '</a> &#8211; ' . Html::Encode($o_match->GetStartTimeFormatted());
             continue;
         }
         # Home team
         $i_home = $o_match->GetHomeTeamId();
         if (array_key_exists($i_home, $a_data_to_bind)) {
             $a_data_to_bind[$i_home][$i_played]++;
             if ($o_match->Result()->GetIsHomeWin()) {
                 $a_data_to_bind[$i_home][$i_won]++;
             } else {
                 if ($o_match->Result()->GetIsAwayWin()) {
                     $a_data_to_bind[$i_home][$i_lost]++;
                 } else {
                     if ($o_match->Result()->GetIsEqualResult()) {
                         $a_data_to_bind[$i_home][$i_tie]++;
                     } else {
                         if ($o_match->Result()->GetIsNoResult()) {
                             $a_data_to_bind[$i_home][$i_noresult]++;
                         } else {
                             $a_data_to_bind[$i_home][$i_played]--;
                         }
                     }
                 }
             }
             // safeguard - shouldn't get here
             if ($this->o_season->GetShowTableRunsScored()) {
                 $a_data_to_bind[$i_home][$i_runs_for] = $a_data_to_bind[$i_home][$i_runs_for] + $o_match->Result()->GetHomeRuns();
             }
             if ($this->o_season->GetShowTableRunsConceded()) {
                 $a_data_to_bind[$i_home][$i_runs_against] = $a_data_to_bind[$i_home][$i_runs_against] + $o_match->Result()->GetAwayRuns();
             }
             $a_data_to_bind[$i_home][$i_points] = $a_data_to_bind[$i_home][$i_points] + $o_match->Result()->GetHomePoints();
         }
         # Away team
         $i_away = $o_match->GetAwayTeamId();
         if (array_key_exists($i_away, $a_data_to_bind)) {
             $a_data_to_bind[$i_away][$i_played]++;
             if ($o_match->Result()->GetIsHomeWin()) {
                 $a_data_to_bind[$i_away][$i_lost]++;
             } else {
                 if ($o_match->Result()->GetIsAwayWin()) {
                     $a_data_to_bind[$i_away][$i_won]++;
                 } else {
                     if ($o_match->Result()->GetIsEqualResult()) {
                         $a_data_to_bind[$i_away][$i_tie]++;
                     } else {
                         if ($o_match->Result()->GetIsNoResult()) {
                             $a_data_to_bind[$i_away][$i_noresult]++;
                         } else {
                             $a_data_to_bind[$i_away][$i_played]--;
                         }
                     }
                 }
             }
             // safeguard - shouldn't get here
             if ($this->o_season->GetShowTableRunsScored()) {
                 $a_data_to_bind[$i_away][$i_runs_for] = $a_data_to_bind[$i_away][$i_runs_for] + $o_match->Result()->GetAwayRuns();
             }
             if ($this->o_season->GetShowTableRunsConceded()) {
                 $a_data_to_bind[$i_away][$i_runs_against] = $a_data_to_bind[$i_away][$i_runs_against] + $o_match->Result()->GetHomeRuns();
             }
             $a_data_to_bind[$i_away][$i_points] = $a_data_to_bind[$i_away][$i_points] + $o_match->Result()->GetAwayPoints();
         }
     }
     # Apply points adjustments
     foreach ($this->o_season->PointsAdjustments()->GetItems() as $o_point) {
         /* @var $o_point PointsAdjustment */
         $a_data_to_bind[$o_point->GetTeam()->GetId()][$i_points] += $o_point->GetPoints();
     }
     # Sort the teams so that the highest points come first
     $a_control_array = array();
     foreach ($a_data_to_bind as $a_team_data) {
         $a_control_array[] = $a_team_data[$i_points];
     }
     $a_control_subarray = array();
     foreach ($a_data_to_bind as $a_team_data) {
         $a_control_subarray[] = $a_team_data[$i_played];
     }
     array_multisort($a_control_array, SORT_DESC, $a_control_subarray, SORT_DESC, $a_data_to_bind);
     # Display the data
     $this->BindArray($a_data_to_bind);
     # Add withdrawn teams at the end of the table
     foreach ($this->o_season->TeamsWithdrawnFromLeague() as $team) {
         /* @var $team Team */
         $withdrawn_row = new XhtmlRow(array(new XhtmlAnchor(htmlentities($team->GetName(), ENT_QUOTES, "UTF-8", false), $team->GetNavigateUrl()), 'Withdrew from league'));
         $withdrawn_row->SetCssClass('withdrawn');
         $this->AddRow($withdrawn_row);
     }
     parent::OnPreRender();
 }
 function CreateControls()
 {
     $this->AddCssClass('legacy-form');
     /* @var $team Team */
     /* @var $comp Competition */
     $season = $this->GetDataObject();
     /* @var $season Season */
     require_once 'xhtml/forms/form-part.class.php';
     require_once 'xhtml/forms/textbox.class.php';
     require_once 'xhtml/forms/radio-button.class.php';
     require_once 'xhtml/forms/checkbox.class.php';
     # Show 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) $season->GetId();
     # Add competition
     $comp = $season->GetCompetition();
     $competition = new TextBox($this->GetNamingPrefix() . 'competition', $comp->GetId());
     $competition->SetMode(TextBoxMode::Hidden());
     $this->AddControl($competition);
     # Make current short URL available, because then it can match the suggested one and be left alone
     $short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $season->GetShortUrl());
     $short_url->SetMode(TextBoxMode::Hidden());
     $this->AddControl($short_url);
     # add years
     $start_box = new TextBox('start', is_null($season->GetStartYear()) ? Date::Year(gmdate('U')) : $season->GetStartYear(), $this->IsValidSubmit());
     $start_box->AddAttribute('maxlength', 4);
     $start = new FormPart('Year season starts', $start_box);
     $this->AddControl($start);
     $summer = new RadioButton('summer', 'when', 'Summer season', 0);
     $winter = new RadioButton('winter', 'when', 'Winter season', 1);
     if ($season->GetEndYear() > $season->GetStartYear()) {
         $winter->SetChecked(true);
     } else {
         $summer->SetChecked(true);
     }
     $when = new XhtmlElement('div', $summer);
     $when->AddControl($winter);
     $when->SetCssClass('formControl');
     $when_legend = new XhtmlElement('legend', 'Time of year');
     $when_legend->SetCssClass('formLabel');
     $when_fs = new XhtmlElement('fieldset', $when_legend);
     $when_fs->SetCssClass('formPart');
     $when_fs->AddControl($when);
     $this->AddControl($when_fs);
     # add intro
     $intro_box = new TextBox('intro', $season->GetIntro(), $this->IsValidSubmit());
     $intro_box->SetMode(TextBoxMode::MultiLine());
     $intro = new FormPart('Introduction', $intro_box);
     $this->AddControl($intro);
     if (!$b_is_new_season) {
         # add types of matches
         if (!$this->IsPostback() or $this->b_saving_new and $this->IsValidSubmit()) {
             foreach ($season->MatchTypes()->GetItems() as $i_type) {
                 $this->match_types_editor->DataObjects()->Add(new IdValue($i_type, ucfirst(MatchType::Text($i_type))));
             }
         }
         $this->AddControl(new FormPart('Match types', $this->match_types_editor));
         # add results
         $result_container = new XhtmlElement('div');
         $result_box = new TextBox('results', $season->GetResults(), $this->IsValidSubmit());
         $result_box->SetMode(TextBoxMode::MultiLine());
         $result_container->AddControl($result_box);
         $result = new FormPart('Results', $result_container);
         $result->GetLabel()->AddAttribute('for', $result_box->GetXhtmlId());
         $this->AddControl($result);
         # Add rules table
         $rules = new XhtmlTable();
         $rules->SetCaption('Points for each result');
         $header = new XhtmlRow(array('Result', 'Points for home team', 'Points for away team'));
         $header->SetIsHeader(true);
         $rules->AddRow($header);
         foreach ($this->result_types as $result) {
             /* @var $result MatchResult */
             # Shouldn't ever need to assign points to a postponed match
             if ($result->GetResultType() == MatchResult::POSTPONED) {
                 continue;
             }
             # Populate result with points from season rule
             $season->PossibleResults()->ResetCounter();
             while ($season->PossibleResults()->MoveNext()) {
                 if ($season->PossibleResults()->GetItem()->GetResultType() == $result->GetResultType()) {
                     $result->SetHomePoints($season->PossibleResults()->GetItem()->GetHomePoints());
                     $result->SetAwayPoints($season->PossibleResults()->GetItem()->GetAwayPoints());
                     break;
                 }
             }
             # Create table row
             $home_box = new TextBox($this->GetNamingPrefix() . 'Result' . $result->GetResultType() . 'Home', $result->GetHomePoints(), $this->IsValidSubmit());
             $away_box = new TextBox($this->GetNamingPrefix() . 'Result' . $result->GetResultType() . 'Away', $result->GetAwayPoints(), $this->IsValidSubmit());
             $home_box->AddAttribute('class', 'pointsBox');
             $away_box->AddAttribute('class', 'pointsBox');
             $result_row = new XhtmlRow(array(MatchResult::Text($result->GetResultType()), $home_box, $away_box));
             $rules->AddRow($result_row);
         }
         $result_container->AddControl($rules);
         # Add points adjustments
         $this->adjustments_editor->SetTeams($season->GetTeams());
         if (!$this->IsPostback() or $this->b_saving_new and $this->IsValidSubmit()) {
             $this->adjustments_editor->DataObjects()->SetItems($season->PointsAdjustments()->GetItems());
         }
         $result_container->AddControl($this->adjustments_editor);
         # Show league table?
         $table = new CheckBox('showTable', 'Show results table', 1, $season->GetShowTable());
         $this->AddControl($table);
         $this->AddControl(new CheckBox('runsScored', 'Include runs scored', 1, $season->GetShowTableRunsScored()));
         $this->AddControl(new CheckBox('runsConceded', 'Include runs conceded', 1, $season->GetShowTableRunsConceded()));
         # add teams
         if (!$this->IsPostback() or $this->b_saving_new and $this->IsValidSubmit()) {
             $teams_in_season = array();
             foreach ($season->GetTeams() as $team) {
                 $teams_in_season[] = new TeamInSeason($team, $season, is_object($season->TeamsWithdrawnFromLeague()->GetItemByProperty('GetId', $team->GetId())));
             }
             $this->teams_editor->DataObjects()->SetItems($teams_in_season);
         }
         $this->AddControl(new FormPart('Teams', $this->teams_editor));
     }
 }
 /**
  * Adds a row to the table
  *
  * @param XhtmlRow $o_row
  * @param int $i_group_index
  */
 function AddRow(XhtmlRow $o_row, $i_group_index = 0)
 {
     if ($o_row->GetIsHeader()) {
         if (!is_object($this->o_headergroup)) {
             $this->o_headergroup = new XhtmlRowGroup(true);
         }
         $this->o_headergroup->AddControl($o_row);
     } else {
         if ($o_row->GetIsFooter()) {
             if (!is_object($this->o_footergroup)) {
                 $this->o_footergroup = new XhtmlRowGroup();
                 $this->o_footergroup->SetIsFooter(true);
             }
             $this->o_footergroup->AddControl($o_row);
         } else {
             if (isset($this->a_rowgroups[$i_group_index])) {
                 $this->a_rowgroups[$i_group_index]->AddControl($o_row);
                 $this->i_rowcount++;
             }
         }
     }
 }
 public function OnPageLoad()
 {
     if ($this->not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     if ($this->regenerating) {
         echo $this->regenerating_control;
         return;
     }
     # Container element for structured data
     echo '<div typeof="schema:Person" about="' . htmlentities($this->player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">';
     $querystring = '?player=' . $this->player->GetId();
     if ($_SERVER["QUERY_STRING"]) {
         $querystring = htmlspecialchars('?' . $_SERVER["QUERY_STRING"]);
     }
     require_once "stoolball/statistics/player-summary-control.class.php";
     echo new \Stoolball\Statistics\PlayerSummaryControl($this->player, $this->filter, $this->filter_matched_nothing, $querystring);
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         require_once 'xhtml/navigation/tabs.class.php';
         $tabs = array('Batting' => '', 'Bowling and fielding' => $this->player->GetPlayerUrl() . '/bowling');
         echo new Tabs($tabs);
         ?>
         <div class="box tab-box">
             <div class="dataFilter"></div>
             <div class="box-content">
         <?php 
     }
     # Filter control
     echo $this->filter_control;
     # Batting stats
     if ($this->player->TotalBattingInnings()) {
         //echo "<h2>Batting</h2>";
         # Overview table
         $batting_table = new XhtmlTable();
         $batting_table->SetCssClass("numeric");
         $batting_table->SetCaption("Batting");
         $batting_heading_row = new XhtmlRow(array('<abbr title="Innings" class="small">Inn</abbr><span class="large">Innings</span>', "Not out", "Runs", "50s", "100s", "Best", '<abbr title="Average" class="small">Avg</abbr><span class="large">Average</span>', '<abbr title="Strike rate" class="small">S/R</abbr><span class="large">Strike rate</span>'));
         $batting_heading_row->SetIsHeader(true);
         $batting_table->AddRow($batting_heading_row);
         $batting_table->AddRow(new XhtmlRow(array($this->player->TotalBattingInnings(), $this->player->NotOuts(), $this->player->TotalRuns(), $this->player->Fifties(), $this->player->Centuries(), $this->player->BestBatting(), is_null($this->player->BattingAverage()) ? "&#8211;" : $this->player->BattingAverage(), is_null($this->player->BattingStrikeRate()) ? "&#8211;" : $this->player->BattingStrikeRate())));
         echo $batting_table;
         if ($this->player->TotalBattingInnings()) {
             echo '<p class="statsViewAll"><a href="/play/statistics/individual-scores' . $querystring . '">Individual scores &#8211; view all and filter</a></p>';
         }
         ?>
         <span class="chart-js-template" id="score-spread-chart"></span>
         <span class="chart-js-template" id="batting-form-chart"></span>
         <span class="chart-js-template" id="dismissals-chart"></span>
         <?php 
     }
     $this->ShowSocial();
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         ?>
         </div>
         </div>
         <?php 
     }
     # End container for structured data
     echo "</div>";
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->player->Team()->GetLinkedDataUri());
         $has_admin_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
         if ($has_permission) {
             $this->AddSeparator();
             $panel = new UserEditPanel($this->GetSettings());
             $panel->AddLink("rename this player", $this->player->GetEditUrl());
             if ($has_admin_permission) {
                 $panel->AddLink("delete this player", $this->player->GetDeleteUrl());
             }
             echo $panel;
         }
     }
 }
 /**
  * Creates a bowling scorecard for one innings with as much data as is available
  * @param Match $match
  * @param bool $is_home_innings
  * @return void
  */
 private function CreateBowlingCard(Match $match, $is_home_innings)
 {
     $overs_data = $is_home_innings ? $match->Result()->AwayOvers() : $match->Result()->HomeOvers();
     $bowling_data = $is_home_innings ? $match->Result()->AwayBowling() : $match->Result()->HomeBowling();
     $bowling_team = $is_home_innings ? $match->GetAwayTeam() : $match->GetHomeTeam();
     # First, bowler's figures
     if ($bowling_data->GetCount()) {
         $bowling_table = new XhtmlTable();
         $bowling_table->SetCaption(htmlentities($bowling_team->GetName() . "'s bowlers", ENT_QUOTES, "UTF-8", false));
         $bowling_table->SetCssClass("bowling scorecard");
         $over_header = new XhtmlCell(true, '<abbr title="Overs" class="small">Ov</abbr><span class="large">Overs</span>');
         $over_header->SetCssClass("numeric");
         $maidens_header = new XhtmlCell(true, '<abbr title="Maiden overs" class="small">Md</abbr><abbr title="Maiden overs" class="large">Mdns</abbr>');
         $maidens_header->SetCssClass("numeric");
         $runs_header = new XhtmlCell(true, "Runs");
         $runs_header->SetCssClass("numeric");
         $wickets_header = new XhtmlCell(true, '<abbr title="Wickets" class="small">Wk</abbr><abbr title="Wickets" class="large">Wkts</abbr>');
         $wickets_header->SetCssClass("numeric");
         $economy_header = new XhtmlCell(true, '<abbr title="Economy" class="small">Econ</abbr><span class="large">Economy</span>');
         $economy_header->SetCssClass("numeric");
         $average_header = new XhtmlCell(true, '<abbr title="Average" class="small">Avg</abbr><span class="large">Average</span>');
         $average_header->SetCssClass("numeric");
         $strike_header = new XhtmlCell(true, '<abbr title="Strike rate" class="small">S/R</abbr><span class="large">Strike rate</span>');
         $strike_header->SetCssClass("numeric");
         $bowling_headings = new XhtmlRow(array("Bowler", $over_header, $maidens_header, $runs_header, $wickets_header, $economy_header, $average_header, $strike_header));
         $bowling_headings->SetIsHeader(true);
         $bowling_table->AddRow($bowling_headings);
         $bowling_data->ResetCounter();
         while ($bowling_data->MoveNext()) {
             $bowling = $bowling_data->GetItem();
             /* @var $bowling Bowling */
             $player = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . htmlentities($bowling->GetPlayer()->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($bowling->GetPlayer()->GetName(), ENT_QUOTES, "UTF-8", false) . '</a>');
             $player->AddCssClass("bowler");
             $player->AddAttribute("typeof", "schema:Person");
             $player->AddAttribute("about", $bowling->GetPlayer()->GetLinkedDataUri());
             $over_data = new XhtmlCell(false, htmlentities($bowling->GetOvers(), ENT_QUOTES, "UTF-8", false));
             $over_data->SetCssClass("numeric");
             $maidens_data = new XhtmlCell(false, htmlentities($bowling->GetMaidens(), ENT_QUOTES, "UTF-8", false));
             $maidens_data->SetCssClass("numeric");
             $runs_data = new XhtmlCell(false, htmlentities($bowling->GetRunsConceded(), ENT_QUOTES, "UTF-8", false));
             $runs_data->SetCssClass("numeric");
             $wickets_data = new XhtmlCell(false, htmlentities($bowling->GetWickets(), ENT_QUOTES, "UTF-8", false));
             $wickets_data->SetCssClass("numeric");
             $economy = StoolballStatistics::BowlingEconomy($bowling->GetOvers(), $bowling->GetRunsConceded());
             $economy_data = new XhtmlCell(false, is_null($economy) ? "&#8211;" : htmlentities($economy, ENT_QUOTES, "UTF-8", false));
             $economy_data->SetCssClass("numeric");
             $average = StoolballStatistics::BowlingAverage($bowling->GetRunsConceded(), $bowling->GetWickets());
             $average_data = new XhtmlCell(false, is_null($average) ? "&#8211;" : htmlentities($average, ENT_QUOTES, "UTF-8", false));
             $average_data->SetCssClass("numeric");
             $strike = StoolballStatistics::BowlingStrikeRate($bowling->GetOvers(), $bowling->GetWickets());
             $strike_data = new XhtmlCell(false, is_null($strike) ? "&#8211;" : htmlentities($strike, ENT_QUOTES, "UTF-8", false));
             $strike_data->SetCssClass("numeric");
             $bowling_row = new XhtmlRow(array($player, $over_data, $maidens_data, $runs_data, $wickets_data, $economy_data, $average_data, $strike_data));
             $bowling_row->GetFirstCell()->SetCssClass("bowler");
             $bowling_table->AddRow($bowling_row);
         }
         $this->AddControl($bowling_table);
     }
     # Now over-by-over
     if ($overs_data->GetCount()) {
         $overs_table = new XhtmlTable();
         $overs_table->SetCaption(htmlentities($bowling_team->GetName() . "'s bowling, over-by-over", ENT_QUOTES, "UTF-8", false));
         $overs_table->SetCssClass("scorecard bowling-scorecard bowling overs");
         $balls_header = new XhtmlCell(true, "Balls");
         $balls_header->SetCssClass("numeric");
         $wides_header = new XhtmlCell(true, "Wides");
         $wides_header->SetCssClass("numeric");
         $no_balls_header = new XhtmlCell(true, "No balls");
         $no_balls_header->SetCssClass("numeric");
         $runs_in_over_header = new XhtmlCell(true, "Runs");
         $runs_in_over_header->SetCssClass("numeric");
         $total_header = new XhtmlCell(true, "Total");
         $total_header->SetCssClass("numeric");
         $overs_headings = new XhtmlRow(array("Bowler", $balls_header, $wides_header, $no_balls_header, $runs_in_over_header, $total_header));
         $overs_headings->SetIsHeader(true);
         $overs_table->AddRow($overs_headings);
         $overs_data->ResetCounter();
         $total = 0;
         while ($overs_data->MoveNext()) {
             $bowling = $overs_data->GetItem();
             /* @var $bowling Over */
             $player = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . htmlentities($bowling->GetPlayer()->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($bowling->GetPlayer()->GetName(), ENT_QUOTES, "UTF-8", false) . '</a>');
             $player->AddCssClass("bowler");
             $player->AddAttribute("typeof", "schema:Person");
             $player->AddAttribute("about", $bowling->GetPlayer()->GetLinkedDataUri());
             $balls_data = new XhtmlCell(false, htmlentities($bowling->GetBalls(), ENT_QUOTES, "UTF-8", false));
             $balls_data->SetCssClass("numeric");
             $wides_data = new XhtmlCell(false, htmlentities($bowling->GetWides(), ENT_QUOTES, "UTF-8", false));
             $wides_data->SetCssClass("numeric");
             $no_balls_data = new XhtmlCell(false, htmlentities($bowling->GetNoBalls(), ENT_QUOTES, "UTF-8", false));
             $no_balls_data->SetCssClass("numeric");
             $runs_in_over_data = new XhtmlCell(false, htmlentities($bowling->GetRunsInOver(), ENT_QUOTES, "UTF-8", false));
             $runs_in_over_data->SetCssClass("numeric");
             $total += $bowling->GetRunsInOver();
             $total_data = new XhtmlCell(false, htmlentities($total, ENT_QUOTES, "UTF-8", false));
             $total_data->SetCssClass("numeric");
             $bowling_row = new XhtmlRow(array($player, $balls_data, $wides_data, $no_balls_data, $runs_in_over_data, $total_data));
             $bowling_row->GetFirstCell()->SetCssClass("bowler");
             $overs_table->AddRow($bowling_row);
         }
         $this->AddControl($overs_table);
     }
 }
 private function CreateWicketsRow(Match $match, $wickets_taken)
 {
     $wickets_header = new XhtmlCell(true, "Wickets");
     $wickets_header->SetColumnSpan(4);
     $wickets = new XhtmlSelect("batWickets", null, $this->IsValidSubmit());
     $wickets->SetBlankFirst(true);
     $max_wickets = $match->GetMaximumPlayersPerTeam() - 2;
     $season_dates = Season::SeasonDates($match->GetStartTime());
     # working with GMT
     if (Date::Year($season_dates[0]) != Date::Year($season_dates[1])) {
         # outdoor needs maximum-2, but indoor needs maximum-1 cos last batter can play on.
         # if there's any chance it's indoor use maximum-1
         $max_wickets = $match->GetMaximumPlayersPerTeam() - 1;
     }
     for ($i = 0; $i <= $max_wickets; $i++) {
         $wickets->AddControl(new XhtmlOption($i));
     }
     $wickets->AddControl(new XhtmlOption('all out', -1));
     if ($this->IsValidSubmit() and !is_null($wickets_taken)) {
         $wickets->SelectOption($wickets_taken);
     }
     $balls_column = new XhtmlCell(false, null);
     $wickets_row = new XhtmlRow(array($wickets_header, $wickets, $balls_column));
     $wickets_row->SetCssClass("totals");
     return $wickets_row;
 }
 /**
  * Adds populated controls as a new table row
  *
  * @param XhtmlElement[] $a_controls
  * @param bool $b_enabled
  * @return XhtmlRow
  */
 protected function AddRowToTable($a_controls, $b_enabled = true)
 {
     # Add action button to controls for table
     $button = new XhtmlElement('input');
     if (!$b_enabled) {
         $button->AddAttribute('disabled', 'disabled');
     }
     $last_cell_data = new Placeholder($button);
     $s_id = '';
     if (!is_null($this->current_data_object)) {
         # Get methods for data objects
         $s_id_method = $this->s_id_method;
         $s_date_modified_method = $this->s_date_modified_method;
         # Update button
         $button->AddAttribute('value', 'Delete');
         $button->SetXhtmlId($this->GetNamingPrefix() . 'DeleteRelated' . $this->i_current_row_identifier);
         # Hidden - id of related item
         $s_id = $this->current_data_object->{$s_id_method}();
         $s_id = $s_id ? $s_id : $this->i_current_row_identifier;
         $id_box = new TextBox($this->GetNamingPrefix() . 'RelatedId' . $this->i_current_row_identifier, $s_id);
         $id_box->SetMode(TextBoxMode::Hidden());
         $last_cell_data->AddControl($id_box);
         # Hidden - when was relationship to item updated?
         $b_track_modified_date = ($s_date_modified_method and method_exists($this->current_data_object, $s_date_modified_method));
         if ($b_track_modified_date) {
             $updated_box = new TextBox($this->GetNamingPrefix() . 'RelatedUpdated' . $this->i_current_row_identifier, $this->current_data_object->{$s_date_modified_method}());
             $updated_box->SetMode(TextBoxMode::Hidden());
             $last_cell_data->AddControl($updated_box);
         }
         # Hidden - check whether item updated
         $check_box = new TextBox($this->GetNamingPrefix() . 'Check' . $this->i_current_row_identifier, $this->GetDataObjectHash($this->current_data_object));
         $check_box->SetMode(TextBoxMode::Hidden());
         $last_cell_data->AddControl($check_box);
     } else {
         $button->AddAttribute('value', 'Add');
         $button->SetXhtmlId($this->GetNamingPrefix() . 'AddRelated');
     }
     $button->AddAttribute('type', 'submit');
     $button->SetEmpty(true);
     $button->AddAttribute('name', $button->GetXhtmlId());
     $this->RegisterInternalButton($button->GetXhtmlId());
     # Create table row and add to table
     $a_controls[] = $last_cell_data;
     $row = new XhtmlRow($a_controls);
     if (!$b_enabled) {
         $row->SetCssClass('unavailable');
     }
     $this->table->AddRow($row);
     return $row;
 }
 public function OnPageLoad()
 {
     if ($this->not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     if ($this->regenerating) {
         echo $this->regenerating_control;
         return;
     }
     # Container element for structured data
     echo '<div typeof="schema:Person" about="' . htmlentities($this->player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">';
     $querystring = '?player=' . $this->player->GetId();
     if ($_SERVER["QUERY_STRING"]) {
         $querystring = htmlspecialchars('?' . $_SERVER["QUERY_STRING"]);
     }
     require_once "stoolball/statistics/player-summary-control.class.php";
     echo new \Stoolball\Statistics\PlayerSummaryControl($this->player, $this->filter, $this->filter_matched_nothing, $querystring);
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         require_once 'xhtml/navigation/tabs.class.php';
         $tabs = array('Batting' => $this->player->GetPlayerUrl(), 'Bowling and fielding' => '');
         echo new Tabs($tabs);
         ?>
         <div class="box tab-box">
             <div class="dataFilter"></div>
             <div class="box-content">
         <?php 
     }
     # Filter control
     echo $this->filter_control;
     if ($this->player->Bowling()->GetCount()) {
         //			echo "<h2>Bowling</h2>";
         # Overview table
         $bowling_table = new XhtmlTable();
         $bowling_table->SetCssClass("numeric");
         $bowling_table->SetCaption("Bowling");
         $bowling_heading_row = new XhtmlRow(array('<abbr title="Innings" class="small">Inn</abbr><span class="large">Innings</span>', '<abbr title="Overs" class="small">Ov</abbr><span class="large">Overs</span>', '<abbr title="Maiden overs" class="small">Md</abbr><abbr title="Maiden overs" class="large">Mdns</abbr>', "Runs", '<abbr title="Wickets" class="small">Wk</abbr><abbr title="Wickets" class="large">Wkts</abbr>', "Best", '<abbr title="Economy" class="small">Econ</abbr><span class="large">Economy</span>', '<abbr title="Average" class="small">Avg</abbr><span class="large">Average</span>', '<abbr title="Strike rate" class="small">S/R</abbr><span class="large">Strike rate</span>', '<abbr title="5 wickets" class="small">5 wk</abbr><abbr title="5 wickets" class="large">5 wkts</abbr>'));
         $bowling_heading_row->SetIsHeader(true);
         $bowling_table->AddRow($bowling_heading_row);
         $bowling_table->AddRow(new XhtmlRow(array($this->player->BowlingInnings(), $this->player->Overs(), $this->player->MaidenOvers(), $this->player->RunsAgainst(), $this->player->WicketsTaken(), is_null($this->player->BestBowling()) ? "&#8211;" : $this->player->BestBowling(), is_null($this->player->BowlingEconomy()) ? "&#8211;" : $this->player->BowlingEconomy(), is_null($this->player->BowlingAverage()) ? "&#8211;" : $this->player->BowlingAverage(), is_null($this->player->BowlingStrikeRate()) ? "&#8211;" : $this->player->BowlingStrikeRate(), $this->player->FiveWicketHauls())));
         echo $bowling_table;
         echo '<p class="statsViewAll"><a href="/play/statistics/bowling-performances' . $querystring . '">Bowling performances &#8211; view all and filter</a></p>';
     }
     ?>
     <span class="chart-js-template" id="economy-chart"></span>
     <span class="chart-js-template" id="bowling-average-chart"></span>
     <span class="chart-js-template" id="wickets-chart"></span>
     <?php 
     # Fielding
     $catches = $this->player->GetCatches();
     $run_outs = $this->player->GetRunOuts();
     if ($catches or $run_outs) {
         $fielding_table = new XhtmlTable();
         $fielding_table->SetCssClass("numeric");
         $fielding_table->SetCaption("Fielding");
         $fielding_heading_row = new XhtmlRow(array('Catches', "Run-outs"));
         $fielding_heading_row->SetIsHeader(true);
         $fielding_table->AddRow($fielding_heading_row);
         $fielding_table->AddRow(new XhtmlRow(array($catches, $run_outs)));
         echo $fielding_table;
     }
     $this->ShowSocial();
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         ?>
         </div>
         </div>
         <?php 
     }
     # End container for structured data
     echo "</div>";
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->player->Team()->GetLinkedDataUri());
         $has_admin_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
         if ($has_permission) {
             $this->AddSeparator();
             $panel = new UserEditPanel($this->GetSettings());
             $panel->AddLink("rename this player", $this->player->GetEditUrl());
             if ($has_admin_permission) {
                 $panel->AddLink("delete this player", $this->player->GetDeleteUrl());
             }
             echo $panel;
         }
     }
 }