function OnLoadPageData()
 {
     /* @var Match $tournament */
     # check parameter
     if (!isset($_GET['match']) or !is_numeric($_GET['match'])) {
         $this->Redirect();
     }
     # get tournament
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager->ReadByMatchId(array($_GET['match']));
     $this->tournament = $match_manager->GetFirst();
     unset($match_manager);
     # must have found a match
     if (!$this->tournament instanceof Match) {
         $this->page_not_found = true;
         return;
     }
     # 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->FilterByTournament(array($this->tournament->GetId()));
     $this->statistics["querystring"] = "?tournament=" . $this->tournament->GetId();
     require_once "_summary-data-query.php";
     unset($statistics_manager);
 }
 /**
  * If the tournament parameter is in the query string apply tournament filter
  * @param SiteSettings $settings
  * @param MySqlConnection $connection
  * @param StatisticsManager $statistics_manager
  */
 public static function ApplyTournamentFilter(SiteSettings $settings, MySqlConnection $connection, StatisticsManager $statistics_manager)
 {
     $filter = "";
     if (isset($_GET['tournament']) and is_numeric($_GET['tournament'])) {
         require_once 'stoolball/match-manager.class.php';
         $match_manager = new MatchManager($settings, $connection);
         $match_manager->ReadByMatchId(array($_GET['tournament']));
         $tournament = $match_manager->GetFirst();
         unset($match_manager);
         if (!is_null($tournament)) {
             $statistics_manager->FilterByTournament(array($tournament->GetId()));
             $filter = "in the " . $tournament->GetTitle() . " on " . Date::BritishDate($tournament->GetStartTime()) . " ";
         }
     }
     return $filter;
 }
 public function OnLoadPageData()
 {
     /* @var $topic ForumTopic */
     /* @var $match Match */
     # new data manager
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     # get match
     $match_manager->ReadByMatchId(array($_GET['item']));
     $match_manager->ExpandMatchScorecards();
     $this->match = $match_manager->GetFirst();
     # must have found a match
     if (!$this->match instanceof Match) {
         header('Location: /matches/');
         exit;
     }
     # Update search engine
     if ($this->match->GetSearchUpdateRequired()) {
         require_once "search/match-search-adapter.class.php";
         $this->SearchIndexer()->DeleteFromIndexById("match" . $this->match->GetId());
         $adapter = new MatchSearchAdapter($this->match);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
         $this->SearchIndexer()->CommitChanges();
         $match_manager->SearchUpdated($this->match->GetId());
     }
     # tidy up
     unset($match_manager);
     # Get comments
     $this->review_item = new ReviewItem($this->GetSettings());
     $this->review_item->SetId($this->match->GetId());
     $this->review_item->SetType(ContentType::STOOLBALL_MATCH);
     $this->review_item->SetTitle($this->match->GetTitle());
     $this->review_item->SetNavigateUrl("https://" . $this->GetSettings()->GetDomain() . $this->review_item->GetNavigateUrl());
     $this->review_item->SetLinkedDataUri($this->match->GetLinkedDataUri());
     $topic_manager = new TopicManager($this->GetSettings(), $this->GetDataConnection());
     if ($this->IsPostback()) {
         $this->SavePostedComments($topic_manager);
     }
     $topic_manager->ReadCommentsForReviewItem($this->review_item);
     $this->topic = $topic_manager->GetFirst();
     unset($topic_manager);
     if ($this->match->GetMatchType() == MatchType::TOURNAMENT or $this->match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         # Get stats highlights
         require_once 'stoolball/statistics/statistics-manager.class.php';
         $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
         if ($this->match->GetMatchType() == MatchType::TOURNAMENT) {
             $statistics_manager->FilterByTournament(array($this->match->GetId()));
         } else {
             $statistics_manager->FilterByTournament(array($this->match->GetTournament()->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);
     }
 }