/**
  * Adds a cell to the end of the row
  *
  * @param XhtmlCell $m_cell_or_data
  */
 function AddCell($m_cell_or_data)
 {
     if ($m_cell_or_data instanceof XhtmlCell) {
         parent::AddControl($m_cell_or_data);
     } else {
         $o_cell = new XhtmlCell(false, $m_cell_or_data);
         $o_cell->SetElementName($this->b_is_header ? 'th' : 'td');
         parent::AddControl($o_cell);
     }
     $this->i_columns = -1;
 }
 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 = "";
     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->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();
 }
 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 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);
     }
 }
 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;
 }
 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();
 }