function OnLoadPageData()
 {
     # Set up to get stats for current season
     $four_months = 60 * 60 * 24 * 30 * 4;
     $season_dates = Season::SeasonDates();
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterMaxResults(1);
     do {
         # get stats
         $statistics_manager->FilterAfterDate($season_dates[0]);
         $this->best_batting = $statistics_manager->ReadBestBattingPerformance();
         $this->best_bowling = $statistics_manager->ReadBestBowlingPerformance();
         $this->most_runs = $statistics_manager->ReadBestPlayerAggregate("runs_scored");
         $this->most_wickets = $statistics_manager->ReadBestPlayerAggregate("wickets");
         $this->most_catches = $statistics_manager->ReadBestPlayerAggregate("catches");
         # See what stats we've got
         $this->best_batting_count = count($this->best_batting);
         $this->best_bowling_count = count($this->best_bowling);
         $this->most_runs_count = count($this->most_runs);
         $this->most_wickets_count = count($this->most_wickets);
         $this->most_catches_count = count($this->most_catches);
         $has_player_stats = ($this->best_batting_count or $this->best_bowling_count or $this->most_runs_count or $this->most_wickets_count or $this->most_catches_count);
         if ($has_player_stats) {
             $start_year = gmdate("Y", $season_dates[0]);
             $end_year = gmdate("Y", $season_dates[1]);
             $this->highlight_label = ($start_year == $end_year ? $start_year : $start_year . "/" . substr($end_year, 2)) . " season";
         }
         # If there aren't any for this season (if it's the start of the season), go back 4 months and try again to get previous season
         $season_dates = Season::SeasonDates($season_dates[0] - $four_months);
     } while (!$has_player_stats);
     unset($statistics_manager);
 }
 /**
  * If the to or from parameters are in the query string apply date filter and return dates
  * @param StatisticsManager $statistics_manager
  */
 public static function SupportDateFilter(StatisticsManager $statistics_manager)
 {
     $filter_data = array(null, null, "");
     $filter_data[0] = "";
     if (isset($_GET['from'])) {
         # Replace slashes with hyphens in submitted date because then it's treated as a British date, not American
         $date = is_numeric($_GET['from']) ? (int) $_GET['from'] : strtotime(str_replace("/", "-", $_GET['from']));
         if ($date !== false) {
             $filter_data[0] = $date;
         }
     }
     $to = "";
     if (isset($_GET['to'])) {
         # Replace slashes with hyphens in submitted date because then it's treated as a British date, not American
         $date = is_numeric($_GET['to']) ? (int) $_GET['to'] : strtotime(str_replace("/", "-", $_GET['to']));
         if ($date !== false) {
             $filter_data[1] = $date;
         }
     }
     if ($filter_data[0]) {
         $statistics_manager->FilterAfterDate($filter_data[0]);
     }
     if ($filter_data[1]) {
         $statistics_manager->FilterBeforeDate($filter_data[1]);
     }
     if ($filter_data[0] and $filter_data[1]) {
         # Test whether this is a season
         $three_months_later = intval($filter_data[0]) + 60 * 60 * 24 * 30 * 3;
         $season_dates = Season::SeasonDates($three_months_later);
         if ($filter_data[0] == $season_dates[0] and $filter_data[1] == $season_dates[1]) {
             $start_year = gmdate("Y", $filter_data[0]);
             $end_year = gmdate("Y", $filter_data[1]);
             if ($start_year == $end_year) {
                 $filter_data[2] = "in the {$start_year} season ";
             } else {
                 $filter_data[2] = "in the {$start_year}/" . substr($end_year, 2, 2) . " season ";
             }
         } else {
             $filter_data[2] = "between " . Date::BritishDate($filter_data[0], false, true, false) . " and " . Date::BritishDate($filter_data[1], false, true, false) . " ";
         }
     } else {
         if ($filter_data[0]) {
             $filter_data[2] = "since " . Date::BritishDate($filter_data[0], false, true, false) . " ";
         } else {
             if ($filter_data[1]) {
                 $filter_data[2] = "before " . Date::BritishDate($filter_data[1], false, true, false) . " ";
             }
         }
     }
     return $filter_data;
 }
 function OnLoadPageData()
 {
     /* @var Team $team */
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         $this->Redirect();
     }
     # get team
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByTeamType(array());
     $team_manager->ReadById(array($_GET['item']));
     $this->team = $team_manager->GetFirst();
     unset($team_manager);
     # must have found a team
     if (!$this->team instanceof Team) {
         $this->Redirect('/teams/');
     }
     # get match stats
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterByTeam(array($this->team->GetId()));
     $statistics_manager->ReadMatchStatistics();
     $this->stats = $statistics_manager->GetItems();
     # Get some stats on the best players
     $this->statistics_query = "?team=" . $this->team->GetId();
     if ($this->season) {
         # use midpoint of season to get season dates for filter
         $start_year = substr($this->season, 0, 4);
         $end_year = strlen($this->season) == 7 ? $start_year + 1 : $start_year;
         if ($start_year == $end_year) {
             $season_dates = Season::SeasonDates(mktime(0, 0, 0, 7, 1, $start_year));
         } else {
             $season_dates = Season::SeasonDates(mktime(0, 0, 0, 12, 31, $start_year));
         }
         $statistics_manager->FilterAfterDate($season_dates[0]);
         $statistics_manager->FilterBeforeDate($season_dates[1]);
         $this->statistics_query .= "&from=" . $season_dates[0] . "&to=" . $season_dates[1];
     }
     $statistics_manager->FilterMaxResults(10);
     $this->most_runs = $statistics_manager->ReadBestPlayerAggregate("runs_scored");
     $this->most_wickets = $statistics_manager->ReadBestPlayerAggregate("wickets");
     $this->most_catches = $statistics_manager->ReadBestPlayerAggregate("catches");
     $this->most_run_outs = $statistics_manager->ReadBestPlayerAggregate("run_outs");
     $this->most_player_of_match = $statistics_manager->ReadBestPlayerAggregate("player_of_match");
     unset($statistics_manager);
 }
 function OnLoadPageData()
 {
     /* @var Ground $ground */
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         $this->Redirect();
     }
     # get ground
     $ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
     $ground_manager->ReadById(array($_GET['item']));
     $this->ground = $ground_manager->GetFirst();
     unset($ground_manager);
     # must have found a ground
     if (!$this->ground instanceof Ground) {
         $this->Redirect('/play/');
     }
     # Get some stats on the best players
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterByGround(array($this->ground->GetId()));
     $this->seasons_with_statistics = $statistics_manager->ReadSeasonsWithPlayerStatistics();
     $this->statistics["querystring"] = "?ground=" . $this->ground->GetId();
     if ($this->season) {
         # use midpoint of season to get season dates for filter
         $start_year = substr($this->season, 0, 4);
         $end_year = strlen($this->season) == 7 ? $start_year + 1 : $start_year;
         if ($start_year == $end_year) {
             $season_dates = Season::SeasonDates(mktime(0, 0, 0, 7, 1, $start_year));
         } else {
             $season_dates = Season::SeasonDates(mktime(0, 0, 0, 12, 31, $start_year));
         }
         $statistics_manager->FilterAfterDate($season_dates[0]);
         $statistics_manager->FilterBeforeDate($season_dates[1]);
         $this->statistics["querystring"] .= "&from=" . $season_dates[0] . "&to=" . $season_dates[1];
     }
     require_once "_summary-data-query.php";
     unset($statistics_manager);
 }