private function IndexMatches() { require_once "data/process-manager.class.php"; $this->process = new ProcessManager("matches", 200); if ($this->process->ReadyToDeleteAll()) { $this->SearchIndexer()->DeleteFromIndexByType("match"); } $match = $this->GetSettings()->GetTable('Match'); $match_batch = $this->GetDataConnection()->query("SELECT match_id FROM {$match} ORDER BY start_time, match_id" . $this->process->GetQueryLimit()); $match_ids = array(); while ($row = $match_batch->fetch()) { $match_ids[] = $row->match_id; } if (count($match_ids)) { require_once 'stoolball/match-manager.class.php'; require_once 'search/match-search-adapter.class.php'; $manager = new MatchManager($this->GetSettings(), $this->GetDataConnection()); $manager->ReadByMatchId($match_ids); $results = $manager->GetItems(); unset($manager); foreach ($results as $match) { $adapter = new MatchSearchAdapter($match); $this->SearchIndexer()->Index($adapter->GetSearchableItem()); $this->process->OneMoreDone(); } $this->SearchIndexer()->CommitChanges(); } }
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); } }