private function IndexGrounds()
 {
     require_once 'stoolball/ground-manager.class.php';
     require_once "stoolball/team-manager.class.php";
     require_once 'search/ground-search-adapter.class.php';
     $this->SearchIndexer()->DeleteFromIndexByType("ground");
     $manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
     $manager->FilterByActive(true);
     $manager->ReadAll();
     $grounds = $manager->GetItems();
     unset($manager);
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     foreach ($grounds as $ground) {
         /* @var $ground Ground */
         # Get teams based at the ground
         $team_manager->FilterByGround(array($ground->GetId()));
         $team_manager->FilterByActive(true);
         $team_manager->ReadTeamSummaries();
         $teams = $team_manager->GetItems();
         $ground->Teams()->SetItems($teams);
         $adapter = new GroundSearchAdapter($ground);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
     }
     $this->SearchIndexer()->CommitChanges();
     unset($team_manager);
 }
 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);
 }