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()
 {
     require_once 'stoolball/competition-manager.class.php';
     $comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
     $comp_manager->ReadCompetitionsInCategories(array(17, 33, 45, 61, 62, 72, 73));
     $competitions = $comp_manager->GetItems();
     unset($comp_manager);
     $season_ids = array();
     foreach ($competitions as $competition) {
         /*@var $competition Competition */
         $season = $competition->GetLatestSeason();
         $season_ids[] = $season->GetId();
     }
     # Fixtures
     require_once 'stoolball/match-manager.class.php';
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager->FilterByMaximumResults(5);
     $match_manager->FilterByDateStart(gmdate('U'));
     $match_manager->ReadBySeasonId($season_ids);
     $this->matches = $match_manager->GetItems();
     unset($match_manager);
     # Get stats highlights
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterBySeason($season_ids);
     $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);
     unset($statistics_manager);
 }
 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);
 }
 function OnLoadPageData()
 {
     /* @var $o_match Match */
     /* @var $o_team Team */
     # new data manager
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     # create repeater control, and save any posted data
     $this->repeater = new DataEditRepeater($this, 'CreateEditControl');
     $this->repeater->SetCssClass('matchResults');
     $this->repeater->SetPersistedParameters(array('team', 'season', "tournament"));
     $this->repeater->SetButtonText('Save all results');
     $this->repeater->SetShowButtonsAtTop(true);
     if ($this->IsPostback() and !$this->IsRefresh() and $this->IsValid()) {
         require_once 'forums/topic-manager.class.php';
         require_once 'forums/review-item.class.php';
         require_once 'forums/subscription-manager.class.php';
         $topic_manager = new TopicManager($this->GetSettings(), $this->GetDataConnection());
         foreach ($this->repeater->GetDataObjects() as $o_current_match) {
             /* @var $o_current_match Match */
             $match_manager->SaveResult($o_current_match);
             $match_manager->ExpandMatchUrl($o_current_match);
             $match_manager->NotifyMatchModerator($o_current_match->GetId());
             if (trim($o_current_match->GetNewComment())) {
                 $item_to_comment_on = new ReviewItem($this->GetSettings());
                 $item_to_comment_on->SetType(ContentType::STOOLBALL_MATCH);
                 $item_to_comment_on->SetId($o_current_match->GetId());
                 $item_to_comment_on->SetNavigateUrl("https://" . $this->GetSettings()->GetDomain() . $o_current_match->GetNavigateUrl());
                 $message = $topic_manager->SaveComment($item_to_comment_on, $o_current_match->GetNewComment());
                 # send subscription emails - new object each time to reset list of who's already recieved an email
                 $subs_manager = new SubscriptionManager($this->GetSettings(), $this->GetDataConnection());
                 $subs_manager->SendCommentsSubscriptions($item_to_comment_on, $message);
                 unset($subs_manager);
             }
         }
         $this->b_saved = true;
     }
     # get matches
     if (!is_null($this->i_team_id)) {
         $a_season_times = Season::SeasonDates();
         $match_manager->FilterByTeam(array($this->i_team_id));
         $match_manager->FilterByDateStart($a_season_times[0]);
         $match_manager->FilterByDateEnd($a_season_times[1]);
         $match_manager->ReadMatchSummaries();
     } else {
         if (!is_null($this->i_season_id)) {
             $match_manager->ReadBySeasonId(array($this->i_season_id), true);
         } else {
             if (!is_null($this->tournament_id)) {
                 $match_manager->FilterByTournament($this->tournament_id);
                 $this->a_matches = $match_manager->ReadMatchSummaries();
             }
         }
     }
     $this->a_matches = $match_manager->GetItems();
     # Make sure we have some matches
     if (count($this->a_matches)) {
         # If it's matches for a team, get the team
         if (!is_null($this->i_team_id)) {
             # Should only need to look at the first match, because the team must be a
             # part of that match in order for the match to be in this list
             $o_match =& $this->a_matches[0];
             $o_team = $o_match->GetHomeTeam();
             if ($o_team instanceof Team and $o_team->GetId() == $this->i_team_id) {
                 $this->team = $o_team;
             } else {
                 foreach ($o_match->GetAwayTeams() as $o_team) {
                     if ($o_team->GetId() == $this->i_team_id) {
                         $this->team = $o_team;
                         break;
                     }
                 }
             }
             if (!is_object($this->team)) {
                 $this->Redirect();
             }
             # Now that we have short URL data, if data has just been saved for team, redirect back to team
             if ($this->b_saved) {
                 $this->Redirect($this->team->GetNavigateUrl());
             }
         } else {
             if (!is_null($this->i_season_id)) {
                 # get details of the season
                 require_once 'stoolball/competition-manager.class.php';
                 $o_comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
                 $o_comp_manager->ReadById(null, array($this->i_season_id));
                 $o_competition = $o_comp_manager->GetFirst();
                 unset($o_comp_manager);
                 if ($o_competition instanceof Competition) {
                     $this->season = $o_competition->GetWorkingSeason();
                 }
                 if (!$this->season instanceof Season) {
                     $this->Redirect();
                 }
                 # Now that we have short URL data, if data has just been saved for season, redirect back to season
                 if ($this->b_saved) {
                     $this->Redirect($this->season->GetNavigateUrl());
                 }
             } else {
                 if (!is_null($this->tournament_id)) {
                     $match_manager->ReadByMatchId(array($this->tournament_id));
                     $this->tournament = $match_manager->GetFirst();
                     if (!is_null($this->tournament)) {
                         # If the tournament has just been saved, now we have its URL so redirect to the thanks page
                         if ($this->b_saved) {
                             $this->Redirect($this->tournament->GetNavigateUrl());
                         }
                     }
                 }
             }
         }
     } else {
         $this->Redirect();
     }
     unset($match_manager);
 }