function OnLoadPageData() { /* @var Match $tournament */ # check parameter if (!isset($_GET['match']) or !is_numeric($_GET['match'])) { $this->Redirect(); } # get match $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection()); $match_manager->ReadByMatchId(array($_GET['match'])); $match_manager->ExpandMatchScorecards(); $this->match = $match_manager->GetFirst(); unset($match_manager); # must have found a match if (!$this->match instanceof Match) { $this->page_not_found = true; return; } $result = $this->match->Result(); $this->has_statistics = $result->HomeOvers()->GetCount() or $result->AwayOvers()->GetCount(); }
function OnLoadPageData() { /* @var $match_manager MatchManager */ # get id of Match $i_id = $this->match_manager->GetItemId(); # Get details of match but, if invalid, don't replace submitted details with saved ones if ($i_id and $this->IsValid()) { $this->match_manager->ReadByMatchId(array($i_id)); $this->match_manager->ExpandMatchScorecards(); $this->match = $this->match_manager->GetFirst(); if ($this->match instanceof Match) { $this->b_user_is_match_owner = AuthenticationManager::GetUser()->GetId() == $this->match->GetAddedBy()->GetId(); $this->b_is_tournament = $this->match->GetMatchType() == MatchType::TOURNAMENT; } } unset($this->match_manager); # Tournament or match in the future or not played is page not found $editable_results = array(MatchResult::UNKNOWN, MatchResult::HOME_WIN, MatchResult::AWAY_WIN, MatchResult::TIE, MatchResult::ABANDONED); if (!$this->match instanceof Match or $this->b_is_tournament or $this->match->GetStartTime() > gmdate('U') or !in_array($this->match->Result()->GetResultType(), $editable_results)) { http_response_code(404); $this->page_not_found = true; } }
public function OnLoadPageData() { $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection()); $match_manager->ReadByMatchId(array($_GET['match'])); $match_manager->ExpandMatchScorecards(); $this->match = $match_manager->GetFirst(); unset($match_manager); if ($this->match->GetHomeTeam() instanceof Team and $this->match->GetAwayTeam() instanceof Team) { ?> { "worm": { "labels": [ <?php $overs = $this->HowManyOversInTheMatch(); echo $this->BuildOversLabels(0, $overs); ?> ], "datasets": [ <?php $home_batted_first = $this->match->Result()->GetHomeBattedFirst(); if ($home_batted_first === true || is_null($home_batted_first)) { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetHomeTeam()->GetName(), $home_batted_first === true); ?> ", "data": [0<?php echo $this->BuildCumulativeOverTotals($this->match->Result()->AwayOvers()->GetItems()); ?> ] }, { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetAwayTeam()->GetName(), $home_batted_first === false); ?> ", "data": [0<?php echo $this->BuildCumulativeOverTotals($this->match->Result()->HomeOvers()->GetItems()); ?> ] } <?php } else { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetAwayTeam()->GetName(), $home_batted_first === false); ?> ", "data": [0<?php echo $this->BuildCumulativeOverTotals($this->match->Result()->HomeOvers()->GetItems()); ?> ] }, { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetHomeTeam()->GetName(), $home_batted_first === true); ?> ", "data": [0<?php echo $this->BuildCumulativeOverTotals($this->match->Result()->AwayOvers()->GetItems()); ?> ] } <?php } ?> ] }, "runRate": { "labels": [ <?php echo $this->BuildOversLabels(0, $overs); ?> ], "datasets": [ <?php $home_batted_first = $this->match->Result()->GetHomeBattedFirst(); if ($home_batted_first === true || is_null($home_batted_first)) { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetHomeTeam()->GetName() . " run rate", $home_batted_first === true); ?> ", "data": [0<?php echo $this->BuildCumulativeRunRate($this->match->Result()->AwayOvers()->GetItems()); ?> ] }, { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetAwayTeam()->GetName() . " run rate", null); ?> ", "data": [0<?php echo $this->BuildCumulativeRunRate($this->match->Result()->HomeOvers()->GetItems()); ?> ] }, { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetAwayTeam()->GetName() . " rate required", null); ?> ", "data": [<?php echo $this->BuildRunRateRequired($this->match->Result()->AwayOvers()->GetItems(), $this->match->Result()->HomeOvers()->GetItems(), $overs); ?> ] } <?php } else { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetAwayTeam()->GetName() . " run rate", $home_batted_first === false); ?> ", "data": [0<?php echo $this->BuildCumulativeRunRate($this->match->Result()->HomeOvers()->GetItems()); ?> ] }, { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetHomeTeam()->GetName() . " run rate", null); ?> ", "data": [0<?php echo $this->BuildCumulativeRunRate($this->match->Result()->AwayOvers()->GetItems()); ?> ] }, { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetHomeTeam()->GetName() . " rate required", null); ?> ", "data": [<?php echo $this->BuildRunRateRequired($this->match->Result()->HomeOvers()->GetItems(), $this->match->Result()->AwayOvers()->GetItems(), $overs); ?> ] } <?php } ?> ] }, "manhattanFirstInnings": { "labels": [ <?php $overs = $this->HowManyOversInTheMatch(); echo $this->BuildOversLabels(1, $overs); ?> ], "datasets": [ <?php if ($home_batted_first === true || is_null($home_batted_first)) { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetHomeTeam()->GetName(), $home_batted_first === true); ?> ", "data": [<?php echo $this->BuildOverTotals($this->match->Result()->AwayOvers()->GetItems(), $overs); ?> ] } <?php } else { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetAwayTeam()->GetName(), $home_batted_first === false); ?> ", "data": [<?php echo $this->BuildOverTotals($this->match->Result()->HomeOvers()->GetItems(), $overs); ?> ] } <?php } ?> ] }, "manhattanSecondInnings": { "labels": [ <?php $overs = $this->HowManyOversInTheMatch(); echo $this->BuildOversLabels(1, $overs); ?> ], "datasets": [ <?php if ($home_batted_first === false) { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetHomeTeam()->GetName(), $home_batted_first === true); ?> ", "data": [<?php echo $this->BuildOverTotals($this->match->Result()->AwayOvers()->GetItems(), $overs); ?> ] } <?php } else { ?> { "label": "<?php echo $this->BuildTeamNameLabel($this->match->GetAwayTeam()->GetName(), $home_batted_first === false); ?> ", "data": [<?php echo $this->BuildOverTotals($this->match->Result()->HomeOvers()->GetItems(), $overs); ?> ] } <?php } ?> ] } <?php } ?> } <?php exit; }
function OnLoadPageData() { /* @var $match_manager MatchManager */ /* @var $editor MatchEditControl */ # get id of Match $i_id = $this->match_manager->GetItemId(); if ($i_id) { # Get details of match but, if invalid, don't replace submitted details with saved ones if ($this->IsValid()) { $this->match_manager->ReadByMatchId(array($i_id)); $this->match_manager->ExpandMatchScorecards(); $this->match = $this->match_manager->GetFirst(); if ($this->match instanceof Match) { $this->b_user_is_match_owner = AuthenticationManager::GetUser()->GetId() == $this->match->GetAddedBy()->GetId(); $this->b_is_tournament = $this->match->GetMatchType() == MatchType::TOURNAMENT; } } unset($this->match_manager); # get all competitions if user has permission to change the season if ($this->b_user_is_match_admin) { require_once 'stoolball/competition-manager.class.php'; $o_comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $o_comp_manager->ReadAllSummaries(); $this->editor->SetSeasons(CompetitionManager::GetSeasonsFromCompetitions($o_comp_manager->GetItems())); unset($o_comp_manager); } if ($this->b_user_is_match_admin or $this->b_user_is_match_owner) { # get all teams $season_ids = array(); if ($this->match instanceof Match) { foreach ($this->match->Seasons() as $season) { $season_ids[] = $season->GetId(); } } require_once 'stoolball/team-manager.class.php'; $o_team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection()); if ($this->match instanceof Match and $this->match->GetMatchType() == MatchType::TOURNAMENT_MATCH) { $o_team_manager->FilterByTournament(array($this->match->GetTournament()->GetId())); $o_team_manager->FilterByTeamType(array()); # override default to allow all team types $o_team_manager->ReadTeamSummaries(); } else { if ($this->b_user_is_match_admin or !count($season_ids) or $this->match->GetMatchType() == MatchType::FRIENDLY) { $o_team_manager->ReadById(); # we need full data on the teams to get the seasons they are playing in; } else { # If the user can't change the season, why let them select a team that's not in the season? $o_team_manager->ReadBySeasonId($season_ids); } } $this->editor->SetTeams(array($o_team_manager->GetItems())); unset($o_team_manager); # get all grounds require_once 'stoolball/ground-manager.class.php'; $o_ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection()); $o_ground_manager->ReadAll(); $this->editor->SetGrounds($o_ground_manager->GetItems()); unset($o_ground_manager); } } # Tournament or match not found is page not found if (!$this->match instanceof Match or $this->b_is_tournament) { http_response_code(404); $this->page_not_found = true; } }
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); } }