function OnLoadPageData()
 {
     /* @var $o_competition Competition */
     # check parameter
     if (!isset($_GET['season']) or !is_numeric($_GET['season'])) {
         http_response_code(400);
         exit;
     }
     if (isset($_GET['season']) and is_numeric($_GET['season'])) {
         $comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
         $comp_manager->ReadById(null, array($_GET['season']));
         $this->competition = $comp_manager->GetFirst();
         unset($comp_manager);
     }
     # must have found a competition
     if (!$this->competition instanceof Competition) {
         http_response_code(404);
         exit;
     }
     $this->season = $this->competition->GetWorkingSeason();
     if (is_object($this->season)) {
         # get matches
         $o_match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
         $o_match_manager->ReadBySeasonId(array($this->season->GetId()));
         $a_matches = $o_match_manager->GetItems();
         $this->season->SetMatches($a_matches);
         # Get other seasons
         $a_comp_ids = array($this->competition->GetId());
         $o_season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
         $o_season_manager->ReadByCompetitionId($a_comp_ids);
         $a_other_seasons = $o_season_manager->GetItems();
         $this->competition->SetSeasons(array());
         foreach ($a_other_seasons as $season) {
             if ($season->GetId() == $this->season->GetId()) {
                 $this->competition->AddSeason($this->season, true);
             } else {
                 $this->competition->AddSeason($season, false);
             }
         }
         unset($o_season_manager);
     } else {
         # Must have a season
         http_response_code(404);
         exit;
     }
 }
 function OnLoadPageData()
 {
     /* @var $o_competition Competition */
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         http_response_code(400);
         exit;
     }
     # new data managers
     $o_comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
     # get competition
     $latest = (isset($_GET['latest']) and $_GET['latest'] == '1');
     if ($latest) {
         $o_comp_manager->ReadById(array($_GET['item']), null);
     } else {
         $o_comp_manager->ReadById(null, array($_GET['item']));
     }
     $this->competition = $o_comp_manager->GetFirst();
     $this->season = $this->competition->GetWorkingSeason();
     # must have found a competition
     if (!$this->competition instanceof Competition or !$this->season instanceof Season) {
         http_response_code(404);
         exit;
     }
     # If the competition was requested, redirect to the current season
     if ($latest) {
         http_response_code(303);
         header("Location: " . $this->season->GetNavigateUrl());
         return;
     }
     # Update search engine. Only do this for the latest season as then we have the right teams already.
     if ($this->competition->GetSearchUpdateRequired() and $latest) {
         $this->SearchIndexer()->DeleteFromIndexById("competition" . $this->competition->GetId());
         require_once "search/competition-search-adapter.class.php";
         $adapter = new CompetitionSearchAdapter($this->competition);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
         $this->SearchIndexer()->CommitChanges();
         $o_comp_manager->SearchUpdated($this->competition->GetId());
     }
     unset($o_comp_manager);
     # get matches
     $o_match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $o_match_manager->ReadBySeasonId(array($this->season->GetId()));
     $a_matches = $o_match_manager->GetItems();
     $this->season->SetMatches($a_matches);
     # While we're here, check if there are any outstanding notifications to be sent
     $o_match_manager->NotifyMatchModerator();
     unset($o_match_manager);
     # Get stats highlights
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterBySeason(array($this->season->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);
     # Get other seasons
     $a_comp_ids = array($this->competition->GetId());
     $o_season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
     $o_season_manager->ReadByCompetitionId($a_comp_ids);
     $a_other_seasons = $o_season_manager->GetItems();
     $this->competition->SetSeasons(array());
     foreach ($a_other_seasons as $season) {
         if ($season->GetId() == $this->season->GetId()) {
             $this->competition->AddSeason($this->season, true);
         } else {
             $this->competition->AddSeason($season, false);
         }
     }
     unset($o_season_manager);
 }