public function OnLoadPageData()
    {
        # Now get statistics for the player
        $filter_by_player = array($this->player->GetId());
        $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
        $statistics_manager->FilterByPlayer($filter_by_player);
        # Apply filters common to all statistics
        StatisticsFilter::SupportMatchTypeFilter($statistics_manager);
        StatisticsFilter::SupportOppositionFilter($statistics_manager);
        StatisticsFilter::SupportCompetitionFilter($statistics_manager);
        StatisticsFilter::ApplySeasonFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
        StatisticsFilter::SupportGroundFilter($statistics_manager);
        StatisticsFilter::SupportDateFilter($statistics_manager);
        StatisticsFilter::SupportBattingPositionFilter($statistics_manager);
        StatisticsFilter::SupportInningsFilter($statistics_manager);
        StatisticsFilter::SupportMatchResultFilter($statistics_manager);
        # Now get the statistics for the player
        $this->player = new Player($this->GetSettings());
        $data = $statistics_manager->ReadBestBowlingPerformance(true);
        foreach ($data as $performance) {
            # Not useful for either average or economy
            if (is_null($performance["runs_conceded"])) {
                continue;
            }
            $bowling = new Bowling($this->player);
            $bowling->SetWickets($performance["wickets"]);
            $bowling->SetRunsConceded($performance["runs_conceded"]);
            $bowling->SetOvers($performance["overs"]);
            $match = new Match($this->GetSettings());
            $match->SetStartTime($performance["match_time"]);
            $bowling->SetMatch($match);
            $this->player->Bowling()->Add($bowling);
        }
        $statistics_manager->FilterByPlayer(null);
        $statistics_manager->FilterByBowler($filter_by_player);
        $statistics_manager->FilterByHowOut(array(Batting::BODY_BEFORE_WICKET, Batting::BOWLED, Batting::CAUGHT, Batting::CAUGHT_AND_BOWLED, Batting::HIT_BALL_TWICE));
        $this->player->SetHowWicketsTaken($statistics_manager->ReadHowWicketsFall());
        unset($statistics_manager);
        # How dismissed
        ?>
{
    <?php 
        if ($this->player->Bowling()->GetCount()) {
            ?>
        "economy": {
            "labels": [<?php 
            echo $this->BuildBowlingTimeline($this->player->Bowling()->GetItems());
            ?>
],
            "datasets": [
                {
                    "label": "Economy in each match",
                    "data": [<?php 
            echo $this->BuildMatchEconomyData($this->player->Bowling()->GetItems());
            ?>
]
                },
                {
                    "label": "Economy overall",
                    "data": [<?php 
            echo $this->BuildEconomyData($this->player->Bowling()->GetItems());
            ?>
]
                }
            ]
        },                    
        "bowlingAverage": {
            "labels": [<?php 
            echo $this->BuildBowlingTimeline($this->player->Bowling()->GetItems());
            ?>
],
            "datasets": [
                {
                    "label": "Average in each match",
                    "data": [<?php 
            echo $this->BuildMatchBowlingAverageData($this->player->Bowling()->GetItems());
            ?>
]
                },
                {
                    "label": "Average overall",
                    "data": [<?php 
            echo $this->BuildBowlingAverageData($this->player->Bowling()->GetItems());
            ?>
]
                }
            ]
        },                    
        <?php 
        }
        ?>
    "wickets": [
        <?php 
        $how_out = $this->player->GetHowWicketsTaken();
        $len = count($how_out);
        $count = 0;
        foreach ($how_out as $key => $value) {
            $label = ucfirst(html_entity_decode(Batting::Text($key)));
            echo '{ "label":"' . $label . '","value":' . $value . "}";
            $count++;
            if ($count < $len) {
                echo ',';
            }
        }
        ?>
        
    ]    
}
        <?php 
        exit;
    }
 /**
  * Gets total occurrences for each type of dismissal based on current filters
  * @return An array indexed by type of dismissal, or CSV download
  */
 public function ReadHowWicketsFall()
 {
     $from = $this->FromFilteredPlayerStatistics();
     $where = "WHERE how_out IS NOT NULL ";
     $where = $this->ApplyFilters($where);
     $sql = "SELECT how_out, COUNT(how_out) AS total\r\n                {$from}\r\n                {$where}\r\n                GROUP BY how_out";
     if (count($this->filter_how_out)) {
         $how_out = array_flip($this->filter_how_out);
         foreach ($how_out as $method => $value) {
             $how_out[$method] = 0;
         }
     } else {
         $how_out = array_fill_keys(array(Batting::BODY_BEFORE_WICKET, Batting::BOWLED, Batting::CAUGHT, Batting::CAUGHT_AND_BOWLED, Batting::DID_NOT_BAT, Batting::HIT_BALL_TWICE, Batting::NOT_OUT, Batting::RETIRED, Batting::RETIRED_HURT, Batting::RUN_OUT, Batting::TIMED_OUT, Batting::UNKNOWN_DISMISSAL), 0);
     }
     $result = $this->GetDataConnection()->query($sql);
     $csv = is_array($this->output_as_csv);
     while ($row = $result->fetch()) {
         $how_out[$row->how_out] = $row->total;
     }
     asort($how_out, SORT_NUMERIC);
     $how_out = array_reverse($how_out, true);
     # Optionally add a header row and download a CSV file rather than returning the
     # data
     if ($csv) {
         $csv_data = array();
         $csv_data[] = array("How out", "Total");
         foreach ($how_out as $method => $total) {
             $csv_data[Batting::Text($method)] = $total;
         }
         $how_out = $csv_data;
     }
     return $how_out;
 }
 /**
  * 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);
 }
 /**
  * Creates a batting scorecard for one innings with as much data as is available
  * @param Match $match
  * @param bool $is_home_innings
  * @return void
  */
 private function CreateBattingCard(Match $match, $is_home_innings)
 {
     $batting_data = $is_home_innings ? $match->Result()->HomeBatting() : $match->Result()->AwayBatting();
     $batting_team = $is_home_innings ? $match->GetHomeTeam() : $match->GetAwayTeam();
     # If no batsmen, only minimal scorecard
     $minimal_scorecard = true;
     $batting_data->ResetCounter();
     while ($batting_data->MoveNext()) {
         $batting = $batting_data->GetItem();
         /* @var $batting Batting */
         if ($batting->GetPlayer()->GetPlayerRole() == Player::PLAYER) {
             $minimal_scorecard = false;
             break;
         }
     }
     # Get total and wickets
     $total = $is_home_innings ? $match->Result()->GetHomeRuns() : $match->Result()->GetAwayRuns();
     $wickets = $is_home_innings ? $match->Result()->GetHomeWickets() : $match->Result()->GetAwayWickets();
     if ($wickets == -1) {
         $wickets = "all out";
     }
     # If no total, wickets, or batters, don't show anything
     if ($minimal_scorecard and is_null($total) and is_null($wickets)) {
         return;
     }
     $batting_table = new XhtmlTable();
     $batting_table->SetCaption(htmlentities($batting_team->GetName() . "'s batting", ENT_QUOTES, "UTF-8", false));
     $batting_table->SetCssClass("scorecard batting");
     if (!$minimal_scorecard) {
         $score_header = new XhtmlCell(true, "Runs");
         $score_header->SetCssClass("numeric");
         $balls_header = new XhtmlCell(true, 'Balls');
         $balls_header->SetCssClass("numeric balls-faced");
         $batting_headings = new XhtmlRow(array("Batsman", "How out", "Bowler", $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;
     while ($batting_data->MoveNext()) {
         $batting = $batting_data->GetItem();
         /* @var $batting Batting */
         # Grab the scores for extras players to use later
         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;
         }
         # If it is an extras player, don't create an ordinary row
         if ($batting->GetPlayer()->GetPlayerRole() != Player::PLAYER) {
             continue;
             # continue doesn't work if it's inside the switch
         }
         $player = new XhtmlCell(false, '<a property="schema:name" rel="schema:url" href="' . htmlentities($batting->GetPlayer()->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($batting->GetPlayer()->GetName(), ENT_QUOTES, "UTF-8", false) . '</a>');
         $player->SetCssClass("batter");
         $player->AddAttribute("typeof", "schema:Person");
         $player->AddAttribute("about", $batting->GetPlayer()->GetLinkedDataUri());
         $how = Batting::Text($batting->GetHowOut());
         if ($batting->GetHowOut() == Batting::NOT_OUT) {
             $how = "<strong>" . htmlentities($how, ENT_QUOTES, "UTF-8", false) . "</strong>";
         }
         if (($batting->GetHowOut() == Batting::CAUGHT or $batting->GetHowOut() == Batting::RUN_OUT) and !is_null($batting->GetDismissedBy()) and $batting->GetDismissedBy()->GetPlayerRole() == Player::PLAYER) {
             $how .= ' <span class="playerName" typeof="schema:Person" about="' . htmlentities($batting->GetDismissedBy()->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">(<a property="schema:name" rel="schema:url" href="' . htmlentities($batting->GetDismissedBy()->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($batting->GetDismissedBy()->GetName(), ENT_QUOTES, "UTF-8", false) . '</a>' . ")</span>";
         }
         $bowled_by = new XhtmlCell(false, (is_null($batting->GetBowler()) or !$batting->GetBowler()->GetPlayerRole() == Player::PLAYER) ? "" : '<span typeof="schema:Person" about="' . htmlentities($batting->GetBowler()->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '"><a property="schema:name" rel="schema:url" href="' . htmlentities($batting->GetBowler()->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($batting->GetBowler()->GetName(), ENT_QUOTES, "UTF-8", false) . '</a></span>');
         $bowled_by->AddCssClass("bowler");
         $runs = new XhtmlCell(false, htmlentities($batting->GetRuns(), ENT_QUOTES, "UTF-8", false));
         $runs->SetCssClass("numeric runs");
         $balls_faced = is_null($batting->GetBallsFaced()) ? "" : '<span class="balls-faced">' . htmlentities($batting->GetBallsFaced(), ENT_QUOTES, "UTF-8", false) . '</span>';
         $balls = new XhtmlCell(false, $balls_faced);
         $balls->SetCssClass("numeric");
         $row = new XhtmlRow(array($player, $how, $bowled_by, $runs, $balls));
         $batting_table->AddRow($row);
     }
     if (!is_null($byes) or !$minimal_scorecard) {
         $this->CreateExtrasRow($batting_table, "Byes", "extras", $byes);
     }
     if (!is_null($wides) or !$minimal_scorecard) {
         $this->CreateExtrasRow($batting_table, "Wides", "extras", $wides);
     }
     if (!is_null($no_balls) or !$minimal_scorecard) {
         $this->CreateExtrasRow($batting_table, "No balls", "extras", $no_balls);
     }
     if ($bonus < 0) {
         $this->CreateExtrasRow($batting_table, "Penalty runs", "extras", $bonus);
         # don't show a 0 here, only if actual runs taken away
     } else {
         if ($bonus > 0) {
             $this->CreateExtrasRow($batting_table, "Bonus runs", "extras", $bonus);
             # don't show a 0 here, only if actual runs awarded
         }
     }
     $this->CreateExtrasRow($batting_table, "Total", "totals", $total, $minimal_scorecard);
     $this->CreateExtrasRow($batting_table, "Wickets", "totals", $wickets, $minimal_scorecard);
     $this->AddControl($batting_table);
 }
    public function OnLoadPageData()
    {
        # Now get statistics for the player
        $filter_by_player = array($this->player->GetId());
        $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
        $statistics_manager->FilterByPlayer($filter_by_player);
        # Apply filters common to all statistics
        StatisticsFilter::SupportMatchTypeFilter($statistics_manager);
        StatisticsFilter::SupportOppositionFilter($statistics_manager);
        StatisticsFilter::SupportCompetitionFilter($statistics_manager);
        StatisticsFilter::ApplySeasonFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
        StatisticsFilter::SupportGroundFilter($statistics_manager);
        StatisticsFilter::SupportDateFilter($statistics_manager);
        StatisticsFilter::SupportBattingPositionFilter($statistics_manager);
        StatisticsFilter::SupportInningsFilter($statistics_manager);
        StatisticsFilter::SupportMatchResultFilter($statistics_manager);
        # Now get the statistics for the player
        $this->player = new Player($this->GetSettings());
        $data = $statistics_manager->ReadBestBattingPerformance(false, true);
        foreach ($data as $performance) {
            $batting = new Batting($this->player, $performance["how_out"], null, null, $performance["runs_scored"]);
            $match = new Match($this->GetSettings());
            $match->SetStartTime($performance["match_time"]);
            $batting->SetMatch($match);
            $this->player->Batting()->Add($batting);
        }
        unset($statistics_manager);
        # How dismissed
        ?>
{
    <?php 
        $score_spread = $this->player->ScoreSpread();
        if (is_array($score_spread)) {
            ?>
    "scoreSpread": {
        "labels":  [
        <?php 
            $len = count($score_spread);
            $count = 0;
            foreach ($score_spread as $key => $value) {
                echo '"' . $key . '"';
                $count++;
                if ($count < $len) {
                    echo ',';
                }
            }
            ?>
         
        ],
        "datasets": [
             {
                 "label": "Not out", 
                "data":  [
                <?php 
            $len = count($score_spread);
            $count = 0;
            foreach ($score_spread as $key => $value) {
                echo $value["not-out"];
                $count++;
                if ($count < $len) {
                    echo ',';
                }
            }
            ?>
                ]
            }, 
             {
                 "label": "Out", 
                "data":  [
                <?php 
            $len = count($score_spread);
            $count = 0;
            foreach ($score_spread as $key => $value) {
                echo $value["out"];
                $count++;
                if ($count < $len) {
                    echo ',';
                }
            }
            ?>
                ]
            }
        ]
    },
    <?php 
        }
        if ($this->player->Batting()->GetCount()) {
            ?>
        "battingForm": {
            "labels": [<?php 
            echo $this->BuildBattingTimeline($this->player->Batting()->GetItems());
            ?>
],
            "datasets": [
                {
                    "label": "Scores",
                    "data": [<?php 
            echo $this->BuildScoresData($this->player->Batting()->GetItems());
            ?>
]
                },
                {
                    "label": "Average",
                    "data": [<?php 
            echo $this->BuildBattingAverageData($this->player->Batting()->GetItems());
            ?>
]
                }
            ]
        },                    
        <?php 
        }
        ?>
    "dismissals": [
        <?php 
        $how_out = $this->player->HowOut();
        $len = count($how_out);
        $count = 0;
        foreach ($how_out as $key => $value) {
            if ($key == Batting::DID_NOT_BAT) {
                continue;
            }
            $label = ucfirst(html_entity_decode(Batting::Text($key)));
            echo '{ "label":"' . $label . '","value":' . $value . "}";
            $count++;
            if ($count < $len) {
                echo ',';
            }
        }
        ?>
        
    ]
}
        <?php 
        exit;
    }