function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Match id", "Title", "Start time", "Latitude", "Longitude", "Website", "Description");
     require_once 'stoolball/match-manager.class.php';
     require_once "search/match-search-adapter.class.php";
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager->FilterByDateStart(gmdate("U"));
     $match_manager->ReadByMatchId();
     while ($match_manager->MoveNext()) {
         $match = $match_manager->GetItem();
         $adapter = new MatchSearchAdapter($match);
         /* @var $match Match */
         # Add this match to the data array
         $data[] = array($match->GetId(), $match->GetTitle(), $match->GetStartTime(), $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLatitude() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLongitude() : "", "https://" . $this->GetSettings()->GetDomain() . $match->GetNavigateUrl(), $adapter->GetSearchDescription());
     }
     unset($match_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
 function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Club/ facility name", "Address 1", "Address 2", "Address 3", "Address 4", "Address 5", "City", "Postcode", "Country", "Tel", "Email", "Website", "Activities", "Opening times");
     require_once 'stoolball/team-manager.class.php';
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByTeamType(array(Team::REGULAR));
     $team_manager->ReadById();
     while ($team_manager->MoveNext()) {
         /* @var $team Team */
         $team = $team_manager->GetItem();
         # NHS choices can only import records with a postcode
         if (!$team->GetGround()->GetAddress()->GetPostcode()) {
             continue;
         }
         $address = array();
         if ($team->GetGround()->GetAddress()->GetSaon()) {
             $address[] = $team->GetGround()->GetAddress()->GetSaon();
         }
         if ($team->GetGround()->GetAddress()->GetPaon()) {
             $address[] = $team->GetGround()->GetAddress()->GetPaon();
         }
         if ($team->GetGround()->GetAddress()->GetStreetDescriptor()) {
             $address[] = $team->GetGround()->GetAddress()->GetStreetDescriptor();
         }
         if ($team->GetGround()->GetAddress()->GetLocality()) {
             $address[] = $team->GetGround()->GetAddress()->GetLocality();
         }
         if ($team->GetGround()->GetAddress()->GetAdministrativeArea()) {
             $address[] = $team->GetGround()->GetAddress()->GetAdministrativeArea();
         }
         $data[] = array($team->GetName() . " Stoolball Club", isset($address[0]) ? $address[0] : "", isset($address[1]) ? $address[1] : "", isset($address[2]) ? $address[2] : "", isset($address[3]) ? $address[3] : "", isset($address[4]) ? $address[4] : "", $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), "stoolball", preg_replace('/\\[[^]]+\\]/', "", $team->GetPlayingTimes()));
     }
     unset($team_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
 /**
  * @return void
  * @desc Create DataValidator objects to validate the edit control
  */
 public function CreateValidators()
 {
     # Validate existing rows only if 'add' or 'delete' not clicked,
     # because those buttons should only affect the row those buttons relate to.
     $i_rows_posted = count($this->a_rows_posted);
     if (!$this->controlling_editor->IsInternalPostback() and $i_rows_posted) {
         $i_last_item = $this->a_rows_posted[$i_rows_posted - 1];
         foreach ($this->a_rows_posted as $i) {
             if ($i == $i_last_item and $this->Adding()) {
                 continue;
             }
             # ignore last one if it's the new row
             $this->CreateValidatorsForItem($i);
         }
     }
     # Validate the new row, unless 'delete' was clicked on another row in this control,
     # because then only the deleted row should be affected, or unless any internal
     # button in another control was clicked.
     if (!$this->DeleteClicked() and !$this->IsUnrelatedInternalPostback()) {
         $this->CreateValidatorsForItem();
     }
     # If saving, and this control doesn't have its minimum number of items, force a validation error
     $i_total_items = $this->DataObjects()->GetCount();
     if ($i_total_items < $this->i_min_items and !$this->controlling_editor->IsInternalPostback()) {
         $force_invalid = new RequiredFieldValidator('ForceInvalid', 'Please add at least one item in \'' . strtolower($this->table->GetCaption()) . '\'');
         $force_invalid->SetValidIfNotFound(false);
         $this->AddValidator($force_invalid);
     }
 }
 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();
 }
 function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Team id", "Team name", "Player type", "Home ground name", "Street name", "Locality", "Town", "Administrative area", "Postcode", "Country", "Latitude", "Longitude", "Contact phone", "Contact email", "Website", "Description");
     require_once 'stoolball/team-manager.class.php';
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByTeamType(array(Team::REGULAR));
     $team_manager->ReadById();
     while ($team_manager->MoveNext()) {
         $team = $team_manager->GetItem();
         /* @var $team Team */
         # Spogo can only import records with contact details
         if (!$team->GetContactPhone() and !$team->GetContactEmail()) {
             continue;
         }
         # Combine free text fields into a description field
         $description = $team->GetIntro();
         if ($description) {
             $description .= "\n\n";
         }
         if ($team->GetPlayingTimes()) {
             $description .= $team->GetPlayingTimes() . "\n\n";
         }
         if ($team->GetCost()) {
             $description .= $team->GetCost();
         }
         # Add this team to the data array
         $data[] = array($team->GetId(), $team->GetName() . " Stoolball Club", PlayerType::Text($team->GetPlayerType()), $team->GetGround()->GetAddress()->GetPaon(), $team->GetGround()->GetAddress()->GetStreetDescriptor(), $team->GetGround()->GetAddress()->GetLocality(), $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetAdministrativeArea(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $team->GetGround()->GetAddress()->GetLatitude(), $team->GetGround()->GetAddress()->GetLongitude(), $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), trim(html_entity_decode(strip_tags($description), ENT_QUOTES)));
     }
     unset($team_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
 public function OnPreRender()
 {
     $i = $this->first_result;
     $last_value = "";
     foreach ($this->performance_data as $performance) {
         $current_value = $performance["wickets"];
         if ($current_value != $last_value) {
             $pos = $i;
             $last_value = $current_value;
         } else {
             $pos = "=";
         }
         $i++;
         $fields = array();
         $position = new XhtmlCell(false, $pos);
         $position->SetCssClass("position");
         $fields[] = $position;
         $bowler = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . $performance["bowler_url"] . '">' . $performance["bowler_name"] . "</a>");
         $bowler->SetCssClass("player");
         $bowler->AddAttribute("typeof", "schema:Person");
         $bowler->AddAttribute("about", "http://www.stoolball.org.uk/id/player" . $performance["bowler_url"]);
         $fields[] = $bowler;
         $catcher = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . $performance["catcher_url"] . '">' . $performance["catcher_name"] . "</a>");
         $catcher->SetCssClass("player");
         $catcher->AddAttribute("typeof", "schema:Person");
         $catcher->AddAttribute("about", "http://www.stoolball.org.uk/id/player" . $performance["catcher_url"]);
         $fields[] = $catcher;
         $team = new XhtmlCell(false, $performance["team_name"]);
         $team->SetCssClass("team");
         $fields[] = $team;
         $matches = new XhtmlCell(false, $performance["total_matches"]);
         $matches->SetCssClass("numeric");
         $fields[] = $matches;
         $wickets = new XhtmlCell(false, $performance["wickets"]);
         $wickets->SetCssClass("numeric");
         $fields[] = $wickets;
         $row = new XhtmlRow($fields);
         $this->AddRow($row);
     }
     parent::OnPreRender();
 }
 public function OnPreRender()
 {
     $i = $this->first_result;
     $last_value = "";
     foreach ($this->performance_data as $performance) {
         $current_value = "";
         if (array_key_exists("runs_scored", $performance)) {
             $current_batting_value = $performance["runs_scored"];
             $not_out = ($performance["how_out"] == Batting::NOT_OUT or $performance["how_out"] == Batting::RETIRED or $performance["how_out"] == Batting::RETIRED_HURT);
             if ($not_out) {
                 $current_batting_value .= "*";
             }
             $current_value .= $current_batting_value;
         }
         if (array_key_exists("wickets", $performance)) {
             $current_bowling_value = $performance["wickets"] . "/" . $performance["runs_conceded"];
             $current_value .= $current_bowling_value;
         }
         if (array_key_exists("catches", $performance)) {
             $current_value .= $performance["catches"];
         }
         if (array_key_exists("run_outs", $performance)) {
             $current_value .= $performance["run_outs"];
         }
         if ($current_value != $last_value) {
             $pos = $i;
             $last_value = $current_value;
         } else {
             $pos = "=";
         }
         $i++;
         $fields = array();
         if ($this->show_position) {
             $position = new XhtmlCell(false, $pos);
             $position->SetCssClass("position");
             $fields[] = $position;
         }
         $player = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . $performance["player_url"] . '">' . $performance["player_name"] . "</a>");
         $player->SetCssClass("player");
         $player->AddAttribute("typeof", "schema:Person");
         $player->AddAttribute("about", "http://www.stoolball.org.uk/id/player" . $performance["player_url"]);
         $fields[] = $player;
         $match = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . $performance["match_url"] . '">' . $performance["match_title"] . "</a>");
         $match->AddAttribute("typeof", "schema:SportsEvent");
         $match->AddAttribute("about", "https://www.stoolball.org.uk/id/match" . $performance["match_url"]);
         $match->SetCssClass("match");
         $fields[] = $match;
         $date = new XhtmlCell(false, Date::BritishDate($performance["match_time"], false, true, true));
         $date->SetCssClass("date");
         $fields[] = $date;
         if (array_key_exists("runs_scored", $performance)) {
             $runs = new XhtmlCell(false, $current_batting_value == "" ? "&#8211;" : $current_batting_value);
             $runs->SetCssClass("numeric");
             if (!$not_out) {
                 $runs->AddCssClass("out");
             }
             $fields[] = $runs;
         }
         if (array_key_exists("wickets", $performance)) {
             $bowling = new XhtmlCell(false, $current_bowling_value == "/" ? "&#8211;" : $current_bowling_value);
             $bowling->SetCssClass("numeric");
             $fields[] = $bowling;
         }
         if (array_key_exists("catches", $performance)) {
             $catches = new XhtmlCell(false, $performance["catches"] == "0" ? "&#8211;" : $performance["catches"]);
             $catches->SetCssClass("numeric");
             $fields[] = $catches;
         }
         if (array_key_exists("run_outs", $performance)) {
             $runouts = new XhtmlCell(false, $performance["run_outs"] == "0" ? "&#8211;" : $performance["run_outs"]);
             $runouts->SetCssClass("numeric");
             $fields[] = $runouts;
         }
         $row = new XhtmlRow($fields);
         $this->AddRow($row);
     }
     parent::OnPreRender();
 }
 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;
         }
     }
 }
 /**
  * Generates the XHTML for the control
  *
  * @return string
  */
 public function __toString()
 {
     $s_xhtml = parent::__toString();
     if ($this->o_season->PointsAdjustments()->GetCount()) {
         $s_xhtml .= '<p>The results table includes the following points adjustments:</p><ul>';
         $this->o_season->PointsAdjustments()->SortByProperty('GetDate');
         foreach ($this->o_season->PointsAdjustments() as $o_point) {
             /* @var $o_point PointsAdjustment */
             # Convert sign to positive the non-maths way
             $i_positive_points = (int) str_replace('-', '', $o_point->GetPoints());
             $s_points = $i_positive_points > 1 ? ' points' : ' point';
             $s_reason = $o_point->GetReason() ? ' for ' . $o_point->GetReason() : '';
             # Display a message about each adjustment
             if ($o_point->GetPoints() > 0) {
                 $s_xhtml .= '<li>' . htmlentities($i_positive_points . $s_points . ' awarded to ' . $o_point->GetTeam()->GetName() . $s_reason, ENT_QUOTES, "UTF-8", false) . '</li>';
             } elseif ($o_point->GetPoints() < 0) {
                 $s_xhtml .= '<li>' . htmlentities($i_positive_points . $s_points . ' deducted from ' . $o_point->GetTeam()->GetName() . $s_reason, ENT_QUOTES, "UTF-8", false) . '</li>';
             }
         }
         $s_xhtml .= '</ul>';
     }
     if (count($this->a_results_missing)) {
         $s_xhtml .= '<p class="resultPending">Waiting for results from:</p><ul class="resultPending"><li>' . implode('</li><li>', $this->a_results_missing) . '</li></ul>';
     }
     return $s_xhtml;
 }
 public function OnPreRender()
 {
     $i = $this->first_result;
     $last_value = "";
     foreach ($this->bowling_data as $bowling) {
         $current_value = $bowling["wickets"] . "/" . $bowling["runs_conceded"];
         if ($current_value != $last_value) {
             # If 11th value is not same as 10th, stop. This can happen because DB query sees selects all performances with the same number of wickets as the tenth.
             if (!is_null($this->max_results) and $i > $this->max_results) {
                 break;
             }
             $pos = $i;
             $last_value = $current_value;
         } else {
             $pos = "=";
         }
         $i++;
         $position = new XhtmlCell(false, $pos);
         $position->SetCssClass("position");
         $player = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . $bowling["player_url"] . '">' . $bowling["player_name"] . "</a>");
         $player->SetCssClass("player");
         $player->AddAttribute("typeof", "schema:Person");
         $player->AddAttribute("about", "http://www.stoolball.org.uk/id/player" . $bowling["player_url"]);
         if ($this->display_team) {
             $team = new XhtmlCell(false, $bowling["team_name"]);
             $team->SetCssClass("team");
         }
         $opposition = new XhtmlCell(false, $bowling["opposition_name"]);
         $opposition->SetCssClass("team");
         $date = new XhtmlCell(false, Date::BritishDate($bowling["match_time"], false, true, $this->display_team));
         $date->SetCssClass("date");
         $wickets = new XhtmlCell(false, $bowling["wickets"]);
         $wickets->SetCssClass("numeric");
         $runs = new XhtmlCell(false, $bowling["runs_conceded"]);
         $runs->SetCssClass("numeric");
         if ($this->display_team) {
             $row = new XhtmlRow(array($position, $player, $team, $opposition, $date, $wickets, $runs));
         } else {
             $row = new XhtmlRow(array($position, $player, $opposition, $date, $wickets, $runs));
         }
         $this->AddRow($row);
     }
     parent::OnPreRender();
 }
 /**
  * Sets up controls for pages 2/3 of the wizard
  * @param Match $match
  * @param Team $batting_team
  * @param Collection $batting_data
  * @param Team $bowling_team
  * @param Collection $bowling_data
  * @param int $total
  * @param int $wickets_taken
  * @return void
  */
 private function CreateScorecardControls(Match $match, Team $batting_team, Collection $batting_data, Team $bowling_team, Collection $bowling_data, $total, $wickets_taken)
 {
     require_once "xhtml/tables/xhtml-table.class.php";
     $batting_table = new XhtmlTable();
     $batting_table->SetCaption($batting_team->GetName() . "'s batting");
     $batting_table->SetCssClass("scorecard scorecardEditor batting");
     $out_by_header = new XhtmlCell(true, '<span class="small">Fielder</span><span class="large">Caught<span class="wrapping-hair-space"> </span>/<span class="wrapping-hair-space"> </span><span class="nowrap">run-out by</span></span>');
     $out_by_header->SetCssClass("dismissedBy");
     $bowler_header = new XhtmlCell(true, "Bowler");
     $bowler_header->SetCssClass("bowler");
     $score_header = new XhtmlCell(true, "Runs");
     $score_header->SetCssClass("numeric");
     $balls_header = new XhtmlCell(true, "Balls");
     $balls_header->SetCssClass("numeric");
     $batting_headings = new XhtmlRow(array("Batsman", "How out", $out_by_header, $bowler_header, $score_header, $balls_header));
     $batting_headings->SetIsHeader(true);
     $batting_table->AddRow($batting_headings);
     $batting_data->ResetCounter();
     $byes = null;
     $wides = null;
     $no_balls = null;
     $bonus = null;
     # Loop = max players + 4, because if you have a full scorecard you have to keep looping to get the 4 extras players
     for ($i = 1; $i <= $match->GetMaximumPlayersPerTeam() + 4; $i++) {
         $batting = $batting_data->MoveNext() ? $batting_data->GetItem() : null;
         /* @var $batting Batting */
         # Grab the scores for extras players to use later
         if (!is_null($batting)) {
             switch ($batting->GetPlayer()->GetPlayerRole()) {
                 case Player::BYES:
                     $byes = $batting->GetRuns();
                     break;
                 case Player::WIDES:
                     $wides = $batting->GetRuns();
                     break;
                 case Player::NO_BALLS:
                     $no_balls = $batting->GetRuns();
                     break;
                 case Player::BONUS_RUNS:
                     $bonus = $batting->GetRuns();
                     break;
             }
         }
         # Don't write a table row for the last four loops, we'll do that next because they're different
         if ($i <= $match->GetMaximumPlayersPerTeam()) {
             $player = new TextBox("batName{$i}", (is_null($batting) or !$batting->GetPlayer()->GetPlayerRole() == Player::PLAYER) ? "" : $batting->GetPlayer()->GetName(), $this->IsValidSubmit());
             $player->SetMaxLength(100);
             $player->AddAttribute("autocomplete", "off");
             $player->AddCssClass("player batsman team" . $batting_team->GetId());
             $how = new XhtmlSelect("batHowOut{$i}", null, $this->IsValidSubmit());
             $how->SetCssClass("howOut");
             $how->AddOptions(array(Batting::DID_NOT_BAT => Batting::Text(Batting::DID_NOT_BAT), Batting::NOT_OUT => Batting::Text(Batting::NOT_OUT), Batting::CAUGHT => Batting::Text(Batting::CAUGHT), Batting::BOWLED => Batting::Text(Batting::BOWLED), Batting::CAUGHT_AND_BOWLED => str_replace(" and ", "/", Batting::Text(Batting::CAUGHT_AND_BOWLED)), Batting::RUN_OUT => Batting::Text(Batting::RUN_OUT), Batting::BODY_BEFORE_WICKET => "bbw", Batting::HIT_BALL_TWICE => Batting::Text(Batting::HIT_BALL_TWICE), Batting::TIMED_OUT => Batting::Text(Batting::TIMED_OUT), Batting::RETIRED_HURT => Batting::Text(Batting::RETIRED_HURT), Batting::RETIRED => Batting::Text(Batting::RETIRED), Batting::UNKNOWN_DISMISSAL => Batting::Text(Batting::UNKNOWN_DISMISSAL)), null);
             if (!is_null($batting) and $batting->GetPlayer()->GetPlayerRole() == Player::PLAYER and $this->IsValidSubmit()) {
                 $how->SelectOption($batting->GetHowOut());
             }
             $out_by = new TextBox("batOutBy{$i}", (is_null($batting) or is_null($batting->GetDismissedBy()) or !$batting->GetDismissedBy()->GetPlayerRole() == Player::PLAYER) ? "" : $batting->GetDismissedBy()->GetName(), $this->IsValidSubmit());
             $out_by->SetMaxLength(100);
             $out_by->AddAttribute("autocomplete", "off");
             $out_by->AddCssClass("player team" . $bowling_team->GetId());
             $bowled_by = new TextBox("batBowledBy{$i}", (is_null($batting) or is_null($batting->GetBowler()) or !$batting->GetBowler()->GetPlayerRole() == Player::PLAYER) ? "" : $batting->GetBowler()->GetName(), $this->IsValidSubmit());
             $bowled_by->SetMaxLength(100);
             $bowled_by->AddAttribute("autocomplete", "off");
             $bowled_by->AddCssClass("player team" . $bowling_team->GetId());
             $runs = new TextBox("batRuns{$i}", (is_null($batting) or $batting->GetPlayer()->GetPlayerRole() != Player::PLAYER) ? "" : $batting->GetRuns(), $this->IsValidSubmit());
             $runs->SetCssClass("numeric runs");
             $runs->AddAttribute("type", "number");
             $runs->AddAttribute("min", "0");
             $runs->AddAttribute("autocomplete", "off");
             $balls = new TextBox("batBalls{$i}", (is_null($batting) or $batting->GetPlayer()->GetPlayerRole() != Player::PLAYER) ? "" : $batting->GetBallsFaced(), $this->IsValidSubmit());
             $balls->SetCssClass("numeric balls");
             $balls->AddAttribute("type", "number");
             $balls->AddAttribute("min", "0");
             $balls->AddAttribute("autocomplete", "off");
             $batting_row = new XhtmlRow(array($player, $how, $out_by, $bowled_by, $runs, $balls));
             $batting_row->GetFirstCell()->SetCssClass("batsman");
             $batting_table->AddRow($batting_row);
         }
     }
     $batting_table->AddRow($this->CreateExtrasRow("batByes", "Byes", "extras", "numeric runs", $byes));
     $batting_table->AddRow($this->CreateExtrasRow("batWides", "Wides", "extras", "numeric runs", $wides));
     $batting_table->AddRow($this->CreateExtrasRow("batNoBalls", "No balls", "extras", "numeric runs", $no_balls));
     $batting_table->AddRow($this->CreateExtrasRow("batBonus", "Bonus or penalty runs", "extras", "numeric runs", $bonus));
     $batting_table->AddRow($this->CreateExtrasRow("batTotal", "Total", "totals", "numeric", $total));
     $batting_table->AddRow($this->CreateWicketsRow($match, $wickets_taken));
     $this->AddControl($batting_table);
     $total_batsmen = new TextBox("batRows", $match->GetMaximumPlayersPerTeam(), $this->IsValidSubmit());
     $total_batsmen->SetMode(TextBoxMode::Hidden());
     $this->AddControl($total_batsmen);
     $bowling_table = new XhtmlTable();
     $bowling_table->SetCaption($bowling_team->GetName() . "'s bowling, over-by-over");
     $bowling_table->SetCssClass("scorecard scorecardEditor bowling-scorecard bowling");
     $over_header = new XhtmlCell(true, 'Balls bowled <span class="qualifier">(excluding extras)</span>');
     $over_header->SetCssClass("numeric balls");
     $wides_header = new XhtmlCell(true, "Wides");
     $wides_header->SetCssClass("numeric");
     $no_balls_header = new XhtmlCell(true, "No balls");
     $no_balls_header->SetCssClass("numeric");
     $runs_header = new XhtmlCell(true, "Over total");
     $runs_header->SetCssClass("numeric");
     $bowling_headings = new XhtmlRow(array("Bowler", $over_header, $wides_header, $no_balls_header, $runs_header));
     $bowling_headings->SetIsHeader(true);
     $bowling_table->AddRow($bowling_headings);
     $bowling_data->ResetCounter();
     for ($i = 1; $i <= $match->GetOvers(); $i++) {
         $bowling = $bowling_data->MoveNext() ? $bowling_data->GetItem() : null;
         /* @var $bowling Over */
         $blank_row = (is_null($bowling) or is_null($bowling->GetOverNumber()));
         // don't list records generated from batting card to record wickets taken
         $player = new TextBox("bowlerName{$i}", $blank_row ? "" : $bowling->GetPlayer()->GetName(), $this->IsValidSubmit());
         $player->SetMaxLength(100);
         $player->AddAttribute("autocomplete", "off");
         $player->AddCssClass("player team" . $bowling_team->GetId());
         $balls = new TextBox("bowlerBalls{$i}", $blank_row ? "" : $bowling->GetBalls(), $this->IsValidSubmit());
         $balls->AddAttribute("autocomplete", "off");
         $balls->AddAttribute("type", "number");
         $balls->AddAttribute("min", "0");
         $balls->AddAttribute("max", "10");
         $balls->SetCssClass("numeric balls");
         $wides = new TextBox("bowlerWides{$i}", $blank_row ? "" : $bowling->GetWides(), $this->IsValidSubmit());
         $wides->AddAttribute("autocomplete", "off");
         $wides->AddAttribute("type", "number");
         $wides->AddAttribute("min", "0");
         $wides->SetCssClass("numeric wides");
         $no_balls = new TextBox("bowlerNoBalls{$i}", $blank_row ? "" : $bowling->GetNoBalls(), $this->IsValidSubmit());
         $no_balls->AddAttribute("autocomplete", "off");
         $no_balls->AddAttribute("type", "number");
         $no_balls->AddAttribute("min", "0");
         $no_balls->SetCssClass("numeric no-balls");
         $runs = new TextBox("bowlerRuns{$i}", $blank_row ? "" : $bowling->GetRunsInOver(), $this->IsValidSubmit());
         $runs->AddAttribute("autocomplete", "off");
         $runs->AddAttribute("type", "number");
         $runs->AddAttribute("min", "0");
         $runs->SetCssClass("numeric runs");
         $bowling_row = new XhtmlRow(array($player, $balls, $wides, $no_balls, $runs));
         $bowling_row->GetFirstCell()->SetCssClass("bowler");
         $bowling_table->AddRow($bowling_row);
     }
     $this->AddControl($bowling_table);
     $total_overs = new TextBox("bowlerRows", $match->GetOvers(), $this->IsValidSubmit());
     $total_overs->SetMode(TextBoxMode::Hidden());
     $this->AddControl($total_overs);
     if ($match->GetLastAudit() != null) {
         require_once "data/audit-control.class.php";
         $this->AddControl(new AuditControl($match->GetLastAudit(), "match"));
     }
     $home_batted_first = "";
     if (!is_null($match->Result()->GetHomeBattedFirst())) {
         $home_batted_first = (int) $match->Result()->GetHomeBattedFirst();
     }
     $teams = new TextBox("teams", $home_batted_first . ScorecardEditControl::DATA_SEPARATOR . $match->GetHomeTeamId() . ScorecardEditControl::DATA_SEPARATOR . $match->GetHomeTeam()->GetName() . ScorecardEditControl::DATA_SEPARATOR . $match->GetAwayTeamId() . ScorecardEditControl::DATA_SEPARATOR . $match->GetAwayTeam()->GetName() . ScorecardEditControl::DATA_SEPARATOR . $match->GetTitle());
     $teams->SetMode(TextBoxMode::Hidden());
     $this->AddControl($teams);
 }
 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));
     }
 }
 public function OnPreRender()
 {
     $i = $this->first_result;
     $last_value = "";
     foreach ($this->batting_data as $batting) {
         $current_value = $batting["runs_scored"];
         $not_out = ($batting["how_out"] == Batting::NOT_OUT or $batting["how_out"] == Batting::RETIRED or $batting["how_out"] == Batting::RETIRED_HURT);
         if ($not_out) {
             $current_value .= "*";
         }
         if ($current_value != $last_value) {
             # If 11th value is not same as 10th, stop. This can happen because DB query sees 40* and 40 as equal, but they're not.
             if (!is_null($this->max_results) and $i > $this->max_results) {
                 break;
             }
             $pos = $i;
             $last_value = $current_value;
         } else {
             $pos = "=";
         }
         $i++;
         $position = new XhtmlCell(false, $pos);
         $position->SetCssClass("position");
         $player = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . $batting["player_url"] . '">' . $batting["player_name"] . "</a>");
         $player->SetCssClass("player");
         $player->AddAttribute("typeof", "schema:Person");
         $player->AddAttribute("about", "http://www.stoolball.org.uk/id/player" . $batting["player_url"]);
         if ($this->display_team) {
             $team = new XhtmlCell(false, $batting["team_name"]);
             $team->SetCssClass("team");
         }
         $opposition = new XhtmlCell(false, $batting["opposition_name"]);
         $opposition->SetCssClass("team");
         $date = new XhtmlCell(false, Date::BritishDate($batting["match_time"], false, true, $this->display_team));
         $date->SetCssClass("date");
         $runs = new XhtmlCell(false, $current_value);
         $runs->SetCssClass("numeric");
         if (!$not_out) {
             $runs->AddCssClass("out");
         }
         $balls_faced = is_null($batting["balls_faced"]) ? "&#8211;" : '<span class="balls-faced">' . $batting["balls_faced"] . '</span>';
         $balls = new XhtmlCell(false, $balls_faced);
         $balls->SetCssClass("numeric");
         if ($this->display_team) {
             $row = new XhtmlRow(array($position, $player, $team, $opposition, $date, $runs, $balls));
         } else {
             $row = new XhtmlRow(array($position, $player, $opposition, $date, $runs, $balls));
         }
         $this->AddRow($row);
     }
     parent::OnPreRender();
 }
 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;
         }
     }
 }
 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 OnPreRender()
 {
     $i = $this->first_result;
     $last_value = "";
     if (is_array($this->data)) {
         foreach ($this->data as $performance) {
             $current_value = $performance["statistic"];
             if ($current_value !== $last_value) {
                 $pos = $i;
                 $last_value = $current_value;
             } else {
                 $pos = "=";
             }
             $i++;
             $fields = array();
             $position = new XhtmlCell(false, $pos);
             $position->SetCssClass("position");
             $fields[] = $position;
             $player = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . $performance["player_url"] . '">' . $performance["player_name"] . "</a>");
             $player->SetCssClass("player");
             $player->AddAttribute("typeof", "schema:Person");
             $player->AddAttribute("about", "http://www.stoolball.org.uk/id/player" . $performance["player_url"]);
             $fields[] = $player;
             if ($this->display_team) {
                 $team = new XhtmlCell(false, $performance["team_name"]);
                 $team->SetCssClass("team");
                 $fields[] = $team;
             }
             if (array_key_exists("total_matches", $performance)) {
                 $matches = new XhtmlCell(false, $performance["total_matches"]);
                 $matches->SetCssClass("numeric");
                 $fields[] = $matches;
             }
             $aggregate = new XhtmlCell(false, $current_value);
             $aggregate->SetCssClass("numeric");
             $fields[] = $aggregate;
             $row = new XhtmlRow($fields);
             $this->AddRow($row);
         }
     }
     parent::OnPreRender();
 }
 /**
  * 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);
     }
 }