private function IndexTeams() { $this->SearchIndexer()->DeleteFromIndexByType("team"); require_once 'stoolball/team-manager.class.php'; require_once 'search/team-search-adapter.class.php'; $manager = new TeamManager($this->GetSettings(), $this->GetDataConnection()); $manager->FilterByActive(true); $manager->ReadAll(); $teams = $manager->GetItems(); unset($manager); foreach ($teams as $team) { $adapter = new TeamSearchAdapter($team); $this->SearchIndexer()->Index($adapter->GetSearchableItem()); } $this->SearchIndexer()->CommitChanges(); }
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); }