function OnLoadPageData()
 {
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         $this->Redirect();
     }
     # new data managers
     $ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
     # get ground
     $ground_manager->ReadById(array($_GET['item']));
     $this->ground = $ground_manager->GetFirst();
     # must have found a ground
     if (!$this->ground instanceof Ground) {
         $this->Redirect();
     }
     # Get teams based at the ground
     require_once "stoolball/team-manager.class.php";
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByGround(array($this->ground->GetId()));
     $team_manager->FilterByTeamType(array(Team::CLOSED_GROUP, Team::OCCASIONAL, Team::REGULAR, Team::REPRESENTATIVE, Team::SCHOOL_YEARS, Team::SCHOOL_CLUB, Team::SCHOOL_OTHER));
     $team_manager->ReadTeamSummaries();
     $this->ground->Teams()->SetItems($team_manager->GetItems());
     # Update search engine
     if ($this->ground->GetSearchUpdateRequired()) {
         require_once "search/ground-search-adapter.class.php";
         $this->SearchIndexer()->DeleteFromIndexById("ground" . $this->ground->GetId());
         $adapter = new GroundSearchAdapter($this->ground);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
         $this->SearchIndexer()->CommitChanges();
         $ground_manager->SearchUpdated($this->ground->GetId());
     }
     unset($team_manager);
     unset($ground_manager);
     # Read statistics highlights for the ground
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterByGround(array($this->ground->GetId()));
     $statistics_manager->FilterMaxResults(1);
     $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 available
     $best_batting_count = count($this->best_batting);
     $best_bowling_count = count($this->best_bowling);
     $best_batters = count($this->most_runs);
     $best_bowlers = count($this->most_wickets);
     $best_catchers = count($this->most_catches);
     $this->has_player_stats = ($best_batting_count or $best_batters or $best_bowling_count or $best_bowlers or $best_catchers);
     if (!$this->has_player_stats) {
         $player_of_match = $statistics_manager->ReadBestPlayerAggregate("player_of_match");
         $this->has_player_stats = (bool) count($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);
 }
 /**
  * Get the grounds available for filtering, and if the ground parameter is in the query string apply ground filter
  * @param StatisticsManager $statistics_manager
  */
 public static function SupportGroundFilter(StatisticsManager $statistics_manager)
 {
     $filter_data = array(array(), null, "");
     $filter_data[0] = $statistics_manager->ReadGroundsForFilter();
     if (isset($_GET['ground']) and is_numeric($_GET['ground'])) {
         if (array_key_exists($_GET['ground'], $filter_data[0])) {
             $statistics_manager->FilterByGround(array($filter_data[0][$_GET['ground']]->GetId()));
             $filter_data[1] = $filter_data[0][$_GET['ground']]->GetId();
             $filter_data[2] = "at " . $filter_data[0][$_GET['ground']]->GetNameAndTown() . " ";
         }
     }
     return $filter_data;
 }