/**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     require_once "stoolball/statistics/statistics-field.class.php";
     $catches = new StatisticsField("catches", "Catches", false, null);
     $player_name = new StatisticsField("player_name", null, true, null);
     return $this->statistics_data_source->ReadBestFiguresInAMatch($catches, array($player_name), 3, true);
 }
 function OnLoadPageData()
 {
     /* @var $competition Competition */
     # check parameter
     if (isset($_GET['competition']) and is_numeric($_GET['competition'])) {
         $comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
         $comp_manager->ReadById(array($_GET['competition']), null);
         $this->competition = $comp_manager->GetFirst();
         $this->season = $this->competition->GetWorkingSeason();
         unset($comp_manager);
     } else {
         $this->Redirect("/competitions/");
     }
     # must have found a competition
     if (!$this->competition instanceof Competition) {
         $this->Redirect("/competitions/");
     }
     # Get seasons in the competition
     $a_comp_ids = array($this->competition->GetId());
     $o_season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
     $o_season_manager->ReadByCompetitionId($a_comp_ids);
     $a_seasons = $o_season_manager->GetItems();
     $this->competition->SetSeasons($a_seasons);
     unset($o_season_manager);
     # Get stats highlights
     $this->statistics["querystring"] = "?competition=" . $this->competition->GetId();
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterByCompetition(array($this->competition->GetId()));
     require_once "_summary-data-query.php";
     unset($statistics_manager);
 }
 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);
 }
 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()
 {
     # Set up to get stats for current season
     $four_months = 60 * 60 * 24 * 30 * 4;
     $season_dates = Season::SeasonDates();
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterMaxResults(1);
     do {
         # get stats
         $statistics_manager->FilterAfterDate($season_dates[0]);
         $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
         $this->best_batting_count = count($this->best_batting);
         $this->best_bowling_count = count($this->best_bowling);
         $this->most_runs_count = count($this->most_runs);
         $this->most_wickets_count = count($this->most_wickets);
         $this->most_catches_count = count($this->most_catches);
         $has_player_stats = ($this->best_batting_count or $this->best_bowling_count or $this->most_runs_count or $this->most_wickets_count or $this->most_catches_count);
         if ($has_player_stats) {
             $start_year = gmdate("Y", $season_dates[0]);
             $end_year = gmdate("Y", $season_dates[1]);
             $this->highlight_label = ($start_year == $end_year ? $start_year : $start_year . "/" . substr($end_year, 2)) . " season";
         }
         # If there aren't any for this season (if it's the start of the season), go back 4 months and try again to get previous season
         $season_dates = Season::SeasonDates($season_dates[0] - $four_months);
     } while (!$has_player_stats);
     unset($statistics_manager);
 }
 function OnLoadPageData()
 {
     require_once "data/process-manager.class.php";
     $this->process = new ProcessManager();
     if ($this->process->ReadyToDeleteAll()) {
         $stats = $this->GetSettings()->GetTable("PlayerMatch");
         $sql = "TRUNCATE TABLE {$stats}";
         $this->GetDataConnection()->query($sql);
     }
     $matches = $this->GetSettings()->GetTable("MatchTeam");
     $mt = $this->GetSettings()->GetTable('MatchTeam');
     $sql = "SELECT match_id, match_team_id FROM {$matches} ORDER BY match_team_id " . $this->process->GetQueryLimit();
     $result = $this->GetDataConnection()->query($sql);
     require_once "stoolball/player-manager.class.php";
     $player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection());
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     while ($row = $result->fetch()) {
         $affected_players = $player_manager->ReadPlayersInMatch(array($row->match_id));
         # generate player statistics from the data entered
         if (count($affected_players)) {
             $statistics_manager->UpdateBattingStatistics($affected_players, array($row->match_team_id));
             # get the match_team_id for the bowling that goes with this batting
             $sql = "SELECT match_team_id FROM {$mt}\n\t\t\t\t\t\tWHERE match_id = (SELECT match_id FROM {$mt} WHERE match_team_id = {$row->match_team_id})\n\t\t\t\t\t\tAND match_team_id != {$row->match_team_id}\n\t\t\t\t\t\tAND team_role IN (" . TeamRole::Home() . ", " . TeamRole::Away() . ")";
             $result2 = $this->GetDataConnection()->query($sql);
             $row2 = $result2->fetch();
             $bowling_match_team_id = $row2->match_team_id;
             $statistics_manager->UpdateFieldingStatistics($affected_players, array($bowling_match_team_id));
             $statistics_manager->UpdateBowlingStatistics($affected_players, array($bowling_match_team_id));
             $statistics_manager->UpdatePlayerOfTheMatchStatistics($row->match_id);
             $statistics_manager->DeleteObsoleteStatistics($row->match_id);
         }
         $this->process->OneMoreDone();
     }
 }
 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 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);
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestPlayerAverage("balls_bowled", "wickets_with_bowling", false, "balls_bowled", 3);
 }
 function OnLoadPageData()
 {
     # Sanitise the name of the requested statistic
     $this->which_statistic = preg_replace("/[^a-z0-9-]/", "", $_GET["statistic"]);
     # Set up statistics manager
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     # Configure the requested statistic
     switch ($this->which_statistic) {
         case "individual-scores":
             require_once "stoolball/statistics/individual-scores.class.php";
             $this->statistic = new IndividualScores($statistics_manager);
             break;
         case "most-runs":
             require_once "stoolball/statistics/most-runs.class.php";
             $this->statistic = new MostRuns($statistics_manager);
             break;
         case "batting-average":
             require_once "stoolball/statistics/batting-average.class.php";
             $this->statistic = new BattingAverage($statistics_manager);
             break;
         case "batting-strike-rate":
             require_once "stoolball/statistics/batting-strike-rate.class.php";
             $this->statistic = new BattingStrikeRate($statistics_manager);
             break;
         case "bowling-performances":
             require_once "stoolball/statistics/bowling-performances.class.php";
             $this->statistic = new BowlingPerformances($statistics_manager);
             break;
         case "most-wickets":
             require_once "stoolball/statistics/most-wickets.class.php";
             $this->statistic = new MostWickets($statistics_manager);
             break;
         case "most-wickets-by-bowler-and-catcher":
             require_once "stoolball/statistics/most-wickets-by-bowler-and-catcher.class.php";
             $this->statistic = new MostWicketsForBowlerAndCatcher($statistics_manager);
             break;
         case "bowling-average":
             require_once "stoolball/statistics/bowling-average.class.php";
             $this->statistic = new BowlingAverage($statistics_manager);
             break;
         case "economy-rate":
             require_once "stoolball/statistics/economy-rate.class.php";
             $this->statistic = new EconomyRate($statistics_manager);
             break;
         case "bowling-strike-rate":
             require_once "stoolball/statistics/bowling-strike-rate.class.php";
             $this->statistic = new BowlingStrikeRate($statistics_manager);
             break;
         case "most-catches":
             require_once "stoolball/statistics/most-catches.class.php";
             $this->statistic = new MostCatches($statistics_manager);
             break;
         case "most-catches-in-innings":
             require_once "stoolball/statistics/most-catches-in-innings.class.php";
             $this->statistic = new MostCatchesInAnInnings($statistics_manager);
             break;
         case "most-run-outs":
             require_once "stoolball/statistics/most-run-outs.class.php";
             $this->statistic = new MostRunOuts($statistics_manager);
             break;
         case "most-run-outs-in-innings":
             require_once "stoolball/statistics/most-run-outs-in-innings.class.php";
             $this->statistic = new MostRunOutsInAnInnings($statistics_manager);
             break;
         case "player-performances":
             require_once "stoolball/statistics/player-performances.class.php";
             $this->statistic = new PlayerPerformances($statistics_manager);
             break;
         case "player-of-match":
             require_once "stoolball/statistics/player-of-match.class.php";
             $this->statistic = new PlayerOfTheMatch($statistics_manager);
             break;
         case "most-player-of-match":
             require_once "stoolball/statistics/most-player-of-match.class.php";
             $this->statistic = new MostPlayerOfTheMatch($statistics_manager);
             break;
         default:
             $matches = array();
             $is_match = preg_match("/^most-scores-of-([0-9]+)\$/", $this->which_statistic, $matches);
             if ($is_match === 1) {
                 $match_scores_of = $matches[1];
                 require_once "stoolball/statistics/most-scores-of.class.php";
                 $this->statistic = new MostScoresOf($match_scores_of, $statistics_manager);
             }
             $is_match = preg_match("/^most-([0-9][0-9]?)-wickets\$/", $this->which_statistic, $matches);
             if ($is_match === 1) {
                 $how_many_wickets = $matches[1];
                 require_once "stoolball/statistics/most-wicket-hauls-of.class.php";
                 $this->statistic = new \Stoolball\Statistics\MostWicketHaulsOf($how_many_wickets, $statistics_manager);
             }
             break;
     }
     # Is this a request for CSV data?
     $csv = (isset($_GET["format"]) and $_GET["format"] == "csv");
     if ($csv) {
         $statistics_manager->OutputAsCsv($this->statistic->ColumnHeaders());
     }
     # Apply player filter first because it can be used to limit the choices for other filters
     if ($this->statistic->SupportsFilterByPlayer()) {
         $this->filter .= StatisticsFilter::ApplyPlayerFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
     }
     # Apply filters common to all statistics
     $this->filter_control = new StatisticsFilterControl();
     if ($this->statistic->SupportsFilterByBattingPosition()) {
         $filter_batting_position = StatisticsFilter::SupportBattingPositionFilter($statistics_manager);
         $this->filter_control->SupportBattingPositionFilter($filter_batting_position);
         $this->filter .= $filter_batting_position[2];
     }
     $match_type_filter_description = "";
     # If player filter applied, no point filtering by player type because they're associated with a team of one player type.
     # There is the edge case of a ladies team playing in a mixed match, but it would be more confusing than useful to offer it.
     if (!isset($_GET['player'])) {
         $filter_player_type = StatisticsFilter::SupportPlayerTypeFilter($statistics_manager);
         $this->filter_control->SupportPlayerTypeFilter($filter_player_type);
         $match_type_filter_description .= $filter_player_type[2];
     }
     $filter_match_type = StatisticsFilter::SupportMatchTypeFilter($statistics_manager);
     $this->filter_control->SupportMatchTypeFilter($filter_match_type);
     $match_type_filter_description .= $filter_match_type[2];
     $this->filter .= StatisticsFilter::CombineMatchTypeDescriptions($match_type_filter_description);
     # If player filter applied, no point filtering by team. Check for player filter is stricter than this
     # but this is good enough. If this applies, but the player filter isn't applied, it's because someone
     # is playing with the query string, so that's tough.
     if (!isset($_GET['player'])) {
         $filter_team = StatisticsFilter::SupportTeamFilter($statistics_manager);
         $this->filter_control->SupportTeamFilter($filter_team);
         $this->filter .= $filter_team[2];
     }
     $filter_opposition = StatisticsFilter::SupportOppositionFilter($statistics_manager);
     $this->filter_control->SupportOppositionFilter($filter_opposition);
     $this->filter .= $filter_opposition[2];
     $filter_competition = StatisticsFilter::SupportCompetitionFilter($statistics_manager);
     $this->filter_control->SupportCompetitionFilter($filter_competition);
     $this->filter .= $filter_competition[2];
     $this->filter .= StatisticsFilter::ApplySeasonFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
     $filter_ground = StatisticsFilter::SupportGroundFilter($statistics_manager);
     $this->filter_control->SupportGroundFilter($filter_ground);
     $this->filter .= $filter_ground[2];
     $filter_date = StatisticsFilter::SupportDateFilter($statistics_manager);
     if (!is_null($filter_date[0])) {
         $this->filter_control->SupportAfterDateFilter($filter_date[0]);
     }
     if (!is_null($filter_date[1])) {
         $this->filter_control->SupportBeforeDateFilter($filter_date[1]);
     }
     $this->filter .= $filter_date[2];
     $this->filter .= StatisticsFilter::ApplyTournamentFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
     $filter_innings = StatisticsFilter::SupportInningsFilter($statistics_manager);
     $this->filter_control->SupportInningsFilter($filter_innings[1]);
     $this->filter .= $filter_innings[2];
     $filter_won_match = StatisticsFilter::SupportMatchResultFilter($statistics_manager);
     $this->filter_control->SupportMatchResultFilter($filter_won_match[1]);
     $this->filter .= $filter_won_match[2];
     # Configure paging of results
     if (!$csv and $this->statistic->SupportsPagedResults()) {
         require_once 'data/paged-results.class.php';
         $this->paging = new PagedResults();
         $this->paging->SetPageName($this->which_statistic);
         $this->paging->SetQueryString(preg_replace("/statistic={$this->which_statistic}&?/", "", $this->paging->GetQueryString()));
         $this->paging->SetPageSize(50);
         $this->paging->SetResultsTextSingular($this->statistic->ItemTypeSingular());
         $this->paging->SetResultsTextPlural($this->statistic->ItemTypePlural());
         $statistics_manager->FilterByPage($this->paging->GetPageSize(), $this->paging->GetCurrentPage());
     }
     $this->data = $this->statistic->ReadStatistic();
     if (is_array($this->data)) {
         if ($csv) {
             require_once "data/csv.class.php";
             CSV::PublishData($this->data);
         } else {
             $this->paging->SetTotalResults(array_shift($this->data));
         }
     }
     unset($statistics_manager);
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestAggregateOfQualifyingPerformances("runs_scored", $this->minimum_qualifying_score);
 }
 /**
  * @access public
  * @return void
  * @param int[] $a_ids
  * @desc Delete from the db the Matches matching the supplied ids.
  */
 public function DeleteMatch($a_ids)
 {
     # check parameter
     if (!is_array($a_ids)) {
         die('No matches to delete');
     }
     # build query
     $delete_sql = array();
     $s_match = $this->GetSettings()->GetTable('Match');
     $s_season_match = $this->GetSettings()->GetTable('SeasonMatch');
     $s_mt = $this->GetSettings()->GetTable('MatchTeam');
     $batting = $this->GetSettings()->GetTable('Batting');
     $bowling = $this->GetSettings()->GetTable('Bowling');
     $stats = $this->GetSettings()->GetTable('PlayerMatch');
     $s_ids = join(', ', $a_ids);
     # delete batting and bowling
     $match_team_ids = array();
     $result = $this->GetDataConnection()->query("SELECT match_team_id FROM {$s_mt} WHERE match_id IN ({$s_ids})");
     while ($row = $result->fetch()) {
         $match_team_ids[] = $row->match_team_id;
     }
     $result->closeCursor();
     if (count($match_team_ids)) {
         $match_team_ids = join(",", $match_team_ids);
         $delete_sql[] = "DELETE FROM {$batting} WHERE match_team_id IN ({$match_team_ids})";
         $delete_sql[] = "DELETE FROM {$bowling} WHERE match_team_id IN ({$match_team_ids})";
     }
     $this->GetDataConnection()->query("DELETE FROM {$stats} WHERE match_id IN ({$s_ids})");
     # delete teams
     $delete_sql[] = "DELETE FROM {$s_mt} WHERE match_id IN ({$s_ids})";
     # delete seasons
     $delete_sql[] = "DELETE FROM {$s_season_match} WHERE match_id IN ({$s_ids})";
     # if this is a tournament, delete the matches
     $tournament_match_ids = array();
     $s_sql = 'SELECT match_id FROM ' . $s_match . ' WHERE tournament_match_id IN (' . $s_ids . ') ';
     $result = $this->GetDataConnection()->query($s_sql);
     while ($row = $result->fetch()) {
         $tournament_match_ids[] = $row->match_id;
     }
     $result->closeCursor();
     if (count($tournament_match_ids)) {
         $this->DeleteMatch($tournament_match_ids);
     }
     # delete comments thread
     $delete_sql[] = "DELETE FROM nsa_forum_message WHERE item_id IN ({$s_ids}) AND item_type = " . ContentType::STOOLBALL_MATCH;
     # delete match(es)
     $delete_sql[] = "DELETE FROM {$s_match} WHERE match_id IN ({$s_ids});";
     # delete from short URL cache
     require_once 'http/short-url-manager.class.php';
     $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection());
     $s_sql = "SELECT short_url FROM {$s_match} WHERE match_id IN ({$s_ids})";
     $result = $this->GetDataConnection()->query($s_sql);
     while ($row = $result->fetch()) {
         $o_url_manager->Delete($row->short_url);
     }
     $result->closeCursor();
     unset($o_url_manager);
     # get players involved in the match before it's deleted, so that player statistics can be updated
     require_once 'stoolball/player-manager.class.php';
     $player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection());
     $player_ids = $player_manager->ReadPlayersInMatch($a_ids);
     unset($player_manager);
     # Run the collected delete commands
     foreach ($delete_sql as $sql) {
         $this->LoggedQuery($sql);
     }
     # update player stats, removing this match and any players who featured only in this match
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     if (count($player_ids)) {
         $statistics_manager->UpdatePlayerStatistics($player_ids);
     }
     unset($statistics_manager);
     return $this->GetDataConnection()->GetAffectedRows();
 }
 function OnLoadPageData()
 {
     /* @var Team $team */
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         $this->Redirect();
     }
     # get team
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByTeamType(array());
     $team_manager->ReadById(array($_GET['item']));
     $this->team = $team_manager->GetFirst();
     unset($team_manager);
     # must have found a team
     if (!$this->team instanceof Team) {
         $this->Redirect('/teams/');
     }
     # get match stats
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterByTeam(array($this->team->GetId()));
     $statistics_manager->ReadMatchStatistics();
     $this->stats = $statistics_manager->GetItems();
     # Get some stats on the best players
     $this->statistics_query = "?team=" . $this->team->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_query .= "&from=" . $season_dates[0] . "&to=" . $season_dates[1];
     }
     $statistics_manager->FilterMaxResults(10);
     $this->most_runs = $statistics_manager->ReadBestPlayerAggregate("runs_scored");
     $this->most_wickets = $statistics_manager->ReadBestPlayerAggregate("wickets");
     $this->most_catches = $statistics_manager->ReadBestPlayerAggregate("catches");
     $this->most_run_outs = $statistics_manager->ReadBestPlayerAggregate("run_outs");
     $this->most_player_of_match = $statistics_manager->ReadBestPlayerAggregate("player_of_match");
     unset($statistics_manager);
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestPlayerAverage("runs_scored", "dismissed", true, "runs_scored", 3);
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadMatchPerformances();
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestPlayerAggregate("runs_scored");
 }
 /**
  * Merges the records for two players, retaining the id of the destination player
  * @param int $source_player_id
  * @param int $destination_player_id
  * @return void
  */
 public function MergePlayers(Player $source_player, Player $destination_player)
 {
     if (!$source_player->GetId()) {
         throw new Exception("source_player must have an Id");
     }
     if (!$destination_player->GetId()) {
         throw new Exception("destination_player must have an Id");
     }
     if ($source_player->GetPlayerRole() != PLAYER::PLAYER) {
         throw new Exception("Cannot merge source player because it's an extras player");
     }
     if ($destination_player->GetPlayerRole() != PLAYER::PLAYER) {
         throw new Exception("Cannot merge destination player because it's an extras player");
     }
     $players = $this->GetSettings()->GetTable("Player");
     $batting = $this->GetSettings()->GetTable("Batting");
     $bowling = $this->GetSettings()->GetTable("Bowling");
     $matches = $this->GetSettings()->GetTable("Match");
     $statistics = $this->GetSettings()->GetTable("PlayerMatch");
     # Make a note of matches where source player was involved
     $sql = "SELECT DISTINCT match_team_id FROM {$batting} WHERE player_id = " . $source_player->GetId();
     $result = $this->GetDataConnection()->query($sql);
     $source_batted = array();
     while ($row = $result->fetch()) {
         $source_batted[] = $row->match_team_id;
     }
     $sql = "SELECT match_team_id FROM {$statistics}\n\t\t\t\tWHERE player_id = " . $source_player->GetId() . " AND (run_outs > 0 OR catches > 0)";
     $result = $this->GetDataConnection()->query($sql);
     $source_fielded = array();
     while ($row = $result->fetch()) {
         $source_fielded[] = $row->match_team_id;
     }
     $sql = "SELECT match_team_id FROM {$statistics}\n\t\t\t\tWHERE player_id = " . $source_player->GetId() . " AND wickets IS NOT NULL";
     $result = $this->GetDataConnection()->query($sql);
     $source_bowled = array();
     while ($row = $result->fetch()) {
         $source_bowled[] = $row->match_team_id;
     }
     $sql = "SELECT match_id FROM {$statistics}\n\t\t\t\tWHERE player_id = " . $source_player->GetId() . " AND player_of_match = 1";
     $result = $this->GetDataConnection()->query($sql);
     $source_player_of_match = array();
     while ($row = $result->fetch()) {
         $source_player_of_match[] = $row->match_id;
     }
     # Transfer batting and bowling
     $this->LoggedQuery("UPDATE {$batting} SET player_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE player_id = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$batting} SET dismissed_by_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE dismissed_by_id = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$batting} SET bowler_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE bowler_id = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$bowling} SET player_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE player_id = " . Sql::ProtectNumeric($source_player->GetId()));
     # Update dismissals in stats table too, because then fielding statistics will update correctly below.
     # Normally dismissals are updated with the batting, but here it's quite possible we are only updating the fielding.
     $this->LoggedQuery("UPDATE {$statistics} SET caught_by = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE caught_by = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$statistics} SET run_out_by = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE run_out_by = " . Sql::ProtectNumeric($source_player->GetId()));
     if (!$this->is_internal_delete) {
         # Doing an internal delete the destination player will be Unknown. Transfer batting and bowling
         # because that preserves the position for other bowlers and batters as well as related statistics
         # such as number of runs. But set player of the match to null because there's not much value in
         # setting it unknown.
         # Transfer player of the match award
         $this->LoggedQuery("UPDATE {$matches} SET player_of_match_id = " . Sql::ProtectNumeric($destination_player->GetId()) . ",\n\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\tWHERE player_of_match_id = " . Sql::ProtectNumeric($source_player->GetId()));
         $this->LoggedQuery("UPDATE {$matches} SET player_of_match_home_id = " . Sql::ProtectNumeric($destination_player->GetId()) . ",\n\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\tWHERE player_of_match_home_id = " . Sql::ProtectNumeric($source_player->GetId()));
         $this->LoggedQuery("UPDATE {$matches} SET player_of_match_away_id = " . Sql::ProtectNumeric($destination_player->GetId()) . ",\n\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\tWHERE player_of_match_away_id = " . Sql::ProtectNumeric($source_player->GetId()));
         # If a user has claimed either player, remember that. If two different claimants, prefer the destination one.
         if ($source_player->GetUser() instanceof User and $source_player->GetUser()->GetId()) {
             $this->LoggedQuery("UPDATE {$players}\n\t\t\t\tSET user_id = " . Sql::ProtectNumeric($source_player->GetUser()->GetId()) . ",\n\t\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\t\tWHERE player_id = " . Sql::ProtectNumeric($destination_player->GetId()) . " AND user_id = NULL");
         }
         # Now that the source player's data has been moved, delete the source player
         $this->Delete(array($source_player->GetId()));
     }
     # Recalculate all the derived data
     # Note: this method is tightly integrated with the Delete() method. They call each other. When the source player
     # is deleted, above, it will call back into this method before all the derived statistics for the source player
     # have gone. Therefore the queries at the top of this method will find the source player still exists. That in turn
     # leads to these methods being called for a player which has only derived statistics, and no actual data. It is
     # important therefore to call DeleteObsoleteStatistics() to clear out the redundant records as soon as they created.
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     if (count($source_batted)) {
         $statistics_manager->UpdateBattingStatistics(array($destination_player->GetId()), $source_batted);
     }
     if (count($source_fielded)) {
         $statistics_manager->UpdateFieldingStatistics(array($destination_player->GetId()), $source_fielded);
     }
     if (count($source_bowled)) {
         $statistics_manager->UpdateBowlingStatistics(array($destination_player->GetId()), $source_bowled);
     }
     foreach ($source_player_of_match as $match_id) {
         $statistics_manager->UpdatePlayerOfTheMatchStatistics($match_id);
         $statistics_manager->DeleteObsoleteStatistics($match_id);
     }
     $statistics_manager->UpdatePlayerStatistics(array($destination_player->GetId()));
     unset($statistics_manager);
 }
 /**
  * If the match result parameter is in the query string apply the match result filter
  * @param StatisticsManager $statistics_manager
  */
 public static function SupportMatchResultFilter(StatisticsManager $statistics_manager)
 {
     $filter_data = array(array(-1, 0, 1), null, "");
     if (isset($_GET['result']) and is_numeric($_GET['result'])) {
         if (in_array($_GET['result'], $filter_data[0])) {
             $filter_data[1] = (int) $_GET['result'];
             $statistics_manager->FilterByMatchResult($filter_data[1]);
             if ($filter_data[1] === -1) {
                 $filter_data[2] = "to lose a match ";
             } else {
                 if ($filter_data[1] === 0) {
                     $filter_data[2] = "to tie a match ";
                 } else {
                     $filter_data[2] = "to win a match ";
                 }
             }
         }
     }
     return $filter_data;
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadMostWicketsForBowlerAndCatcher();
 }
    public function OnLoadPageData()
    {
        # Now get statistics for the player
        $filter_by_player = array($this->player->GetId());
        $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
        $statistics_manager->FilterByPlayer($filter_by_player);
        # Apply filters common to all statistics
        StatisticsFilter::SupportMatchTypeFilter($statistics_manager);
        StatisticsFilter::SupportOppositionFilter($statistics_manager);
        StatisticsFilter::SupportCompetitionFilter($statistics_manager);
        StatisticsFilter::ApplySeasonFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
        StatisticsFilter::SupportGroundFilter($statistics_manager);
        StatisticsFilter::SupportDateFilter($statistics_manager);
        StatisticsFilter::SupportBattingPositionFilter($statistics_manager);
        StatisticsFilter::SupportInningsFilter($statistics_manager);
        StatisticsFilter::SupportMatchResultFilter($statistics_manager);
        # Now get the statistics for the player
        $this->player = new Player($this->GetSettings());
        $data = $statistics_manager->ReadBestBowlingPerformance(true);
        foreach ($data as $performance) {
            # Not useful for either average or economy
            if (is_null($performance["runs_conceded"])) {
                continue;
            }
            $bowling = new Bowling($this->player);
            $bowling->SetWickets($performance["wickets"]);
            $bowling->SetRunsConceded($performance["runs_conceded"]);
            $bowling->SetOvers($performance["overs"]);
            $match = new Match($this->GetSettings());
            $match->SetStartTime($performance["match_time"]);
            $bowling->SetMatch($match);
            $this->player->Bowling()->Add($bowling);
        }
        $statistics_manager->FilterByPlayer(null);
        $statistics_manager->FilterByBowler($filter_by_player);
        $statistics_manager->FilterByHowOut(array(Batting::BODY_BEFORE_WICKET, Batting::BOWLED, Batting::CAUGHT, Batting::CAUGHT_AND_BOWLED, Batting::HIT_BALL_TWICE));
        $this->player->SetHowWicketsTaken($statistics_manager->ReadHowWicketsFall());
        unset($statistics_manager);
        # How dismissed
        ?>
{
    <?php 
        if ($this->player->Bowling()->GetCount()) {
            ?>
        "economy": {
            "labels": [<?php 
            echo $this->BuildBowlingTimeline($this->player->Bowling()->GetItems());
            ?>
],
            "datasets": [
                {
                    "label": "Economy in each match",
                    "data": [<?php 
            echo $this->BuildMatchEconomyData($this->player->Bowling()->GetItems());
            ?>
]
                },
                {
                    "label": "Economy overall",
                    "data": [<?php 
            echo $this->BuildEconomyData($this->player->Bowling()->GetItems());
            ?>
]
                }
            ]
        },                    
        "bowlingAverage": {
            "labels": [<?php 
            echo $this->BuildBowlingTimeline($this->player->Bowling()->GetItems());
            ?>
],
            "datasets": [
                {
                    "label": "Average in each match",
                    "data": [<?php 
            echo $this->BuildMatchBowlingAverageData($this->player->Bowling()->GetItems());
            ?>
]
                },
                {
                    "label": "Average overall",
                    "data": [<?php 
            echo $this->BuildBowlingAverageData($this->player->Bowling()->GetItems());
            ?>
]
                }
            ]
        },                    
        <?php 
        }
        ?>
    "wickets": [
        <?php 
        $how_out = $this->player->GetHowWicketsTaken();
        $len = count($how_out);
        $count = 0;
        foreach ($how_out as $key => $value) {
            $label = ucfirst(html_entity_decode(Batting::Text($key)));
            echo '{ "label":"' . $label . '","value":' . $value . "}";
            $count++;
            if ($count < $len) {
                echo ',';
            }
        }
        ?>
        
    ]    
}
        <?php 
        exit;
    }
 function OnLoadPageData()
 {
     /* @var Team $team */
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         $this->Redirect();
     }
     # new data manager
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     # get teams
     $team_manager->FilterByTeamType(array());
     $team_manager->ReadById(array($_GET['item']));
     $this->team = $team_manager->GetFirst();
     # must have found a team
     if (!$this->team instanceof Team) {
         $this->Redirect('/teams/');
     }
     # Update search engine
     if ($this->team->GetSearchUpdateRequired()) {
         require_once "search/team-search-adapter.class.php";
         $this->SearchIndexer()->DeleteFromIndexById("team" . $this->team->GetId());
         $adapter = new TeamSearchAdapter($this->team);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
         $this->SearchIndexer()->CommitChanges();
         $team_manager->SearchUpdated($this->team->GetId());
     }
     unset($team_manager);
     $this->is_one_time_team = $this->team->GetTeamType() == Team::ONCE;
     # get matches and match stats
     if (!$this->is_one_time_team) {
         $a_season_dates = Season::SeasonDates();
         $this->season_key = date('Y', $a_season_dates[0]);
         if ($this->season_key != date('Y', $a_season_dates[1])) {
             $this->season_key .= "/" . date('y', $a_season_dates[1]);
         }
         $match_manager->FilterByDateStart($a_season_dates[0]);
     }
     $match_manager->FilterByTeam(array($this->team->GetId()));
     $match_manager->ReadMatchSummaries();
     $this->a_matches = $match_manager->GetItems();
     unset($match_manager);
     $club = $this->team->GetClub();
     $this->has_facebook_group_url = ($club->GetFacebookUrl() and strpos($club->GetFacebookUrl(), '/groups/') !== false);
     $this->has_facebook_page_url = ($club->GetFacebookUrl() and !$this->has_facebook_group_url);
     if (!$this->has_facebook_page_url) {
         require_once 'stoolball/statistics/statistics-manager.class.php';
         $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
         $statistics_manager->FilterByTeam(array($this->team->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 whether to show add league/cup links
     $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
     $season_manager->ReadCurrentSeasonsByTeamId(array($this->team->GetId()), array(MatchType::CUP, MatchType::LEAGUE));
     $this->seasons = $season_manager->GetItems();
     unset($season_manager);
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestAggregateOfQualifyingPerformances("wickets", $this->minimum_qualifying_wickets);
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestBattingPerformance();
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestPlayerAverage("runs_conceded", "overs_decimal", false, "runs_conceded", 3);
 }
 private function generateQuartileFiles()
 {
     $files_list = glob($this->storage_directory . '*' . $this->log_suffix);
     foreach ($files_list as $file) {
         $quartile_file_name = $this->storage_directory . basename($file, $this->log_suffix) . $this->quartile_extension;
         $stats_manager = new StatisticsManager($this->extractDatasFromFormattedFile($file, ',', 1));
         $quartile_datas = $stats_manager->getQuartiles();
         $this->writeArrayToFile($quartile_file_name, 'w', $quartile_datas);
         $this->writeDocumentationtoFile($quartile_file_name, $this->quartile_documentation);
     }
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestPlayerAggregate("wickets");
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     return $this->statistics_data_source->ReadBestPlayerAggregate("player_of_match");
 }
 public function OnLoadPageData()
 {
     # Always get the player's unfiltered profile, because it's needed for the page description
     require_once "stoolball/player-manager.class.php";
     $player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection());
     $player_manager->ReadPlayerById($this->player->GetId());
     $this->player_unfiltered = $player_manager->GetFirst();
     if (!$this->player_unfiltered instanceof Player) {
         http_response_code(404);
         $this->not_found = true;
         return;
     }
     # Update search engine
     if ($this->player_unfiltered->GetSearchUpdateRequired()) {
         require_once "search/player-search-adapter.class.php";
         $this->SearchIndexer()->DeleteFromIndexById("player" . $this->player->GetId());
         $adapter = new PlayerSearchAdapter($this->player_unfiltered);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
         $this->SearchIndexer()->CommitChanges();
         $player_manager->SearchUpdated($this->player->GetId());
     }
     unset($player_manager);
     # Check first for a player created using 'add player', who hasn't played yet
     if ($this->player_unfiltered->GetTotalMatches() == 0) {
         $this->player = $this->player_unfiltered;
     } else {
         # Now get statistics for the player
         $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
         $statistics_manager->FilterByPlayer(array($this->player->GetId()));
         # Apply filters common to all statistics
         $this->filter_control = new StatisticsFilterControl();
         $filter_batting_position = StatisticsFilter::SupportBattingPositionFilter($statistics_manager);
         $this->filter_control->SupportBattingPositionFilter($filter_batting_position);
         $this->filter .= $filter_batting_position[2];
         $filter_match_type = StatisticsFilter::SupportMatchTypeFilter($statistics_manager);
         $this->filter_control->SupportMatchTypeFilter($filter_match_type);
         $this->filter .= $filter_match_type[2];
         $filter_opposition = StatisticsFilter::SupportOppositionFilter($statistics_manager);
         $this->filter_control->SupportOppositionFilter($filter_opposition);
         $this->filter .= $filter_opposition[2];
         $filter_competition = StatisticsFilter::SupportCompetitionFilter($statistics_manager);
         $this->filter_control->SupportCompetitionFilter($filter_competition);
         $this->filter .= $filter_competition[2];
         $this->filter .= StatisticsFilter::ApplySeasonFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
         $filter_ground = StatisticsFilter::SupportGroundFilter($statistics_manager);
         $this->filter_control->SupportGroundFilter($filter_ground);
         $this->filter .= $filter_ground[2];
         $filter_date = StatisticsFilter::SupportDateFilter($statistics_manager);
         if (!is_null($filter_date[0])) {
             $this->filter_control->SupportAfterDateFilter($filter_date[0]);
         }
         if (!is_null($filter_date[1])) {
             $this->filter_control->SupportBeforeDateFilter($filter_date[1]);
         }
         $this->filter .= $filter_date[2];
         $filter_innings = StatisticsFilter::SupportInningsFilter($statistics_manager);
         $this->filter_control->SupportInningsFilter($filter_innings[1]);
         $this->filter .= $filter_innings[2];
         $filter_won_match = StatisticsFilter::SupportMatchResultFilter($statistics_manager);
         $this->filter_control->SupportMatchResultFilter($filter_won_match[1]);
         $this->filter .= $filter_won_match[2];
         # Now get the statistics for the player
         $data = $statistics_manager->ReadPlayerSummary();
         if (count($data)) {
             $this->player = $data[0];
         } else {
             if ($this->filter) {
                 # If no matches matched the filter, ensure we have the player's name and team
                 $this->player = $this->player_unfiltered;
                 $this->filter_matched_nothing = true;
             } else {
                 $this->regenerating = true;
             }
         }
         $data = $statistics_manager->ReadBestBattingPerformance(false);
         foreach ($data as $performance) {
             $batting = new Batting($this->player, $performance["how_out"], null, null, $performance["runs_scored"], $performance["balls_faced"]);
             $this->player->Batting()->Add($batting);
         }
         if ($this->player->GetPlayerRole() == Player::PLAYER) {
             $data = $statistics_manager->ReadBestPlayerAggregate("player_of_match");
             $this->player->SetTotalPlayerOfTheMatchNominations(count($data) ? $data[0]["statistic"] : 0);
         }
         unset($statistics_manager);
     }
 }
 /**
  * Gets the statistical data from the data source
  */
 public function ReadStatistic()
 {
     $this->statistics_data_source->FilterPlayerOfTheMatch(true);
     return $this->statistics_data_source->ReadMatchPerformances();
 }
 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);
 }