function OnPostback() { # get object $this->team = $this->edit->GetDataObject(); # Check user has permission to edit this team. Authentication for team owners is based on the URI # so make sure we get that from the database, not untrusted user input. if ($this->team->GetId() and !AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS)) { $this->team_manager->ReadById(array($this->team->GetId())); $check_team = $this->team_manager->GetFirst(); $this->team->SetShortUrl($check_team->GetShortUrl()); } if ($this->team->GetId() and !AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->team->GetLinkedDataUri()) or !$this->team->GetId() and !AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS)) { $this->GetAuthenticationManager()->GetPermission(); } # save data if valid if ($this->IsValid()) { $i_id = $this->team_manager->SaveTeam($this->team); $this->team->SetId($i_id); $this->Redirect($this->team->GetNavigateUrl()); } }
public function __construct(Team $team) { $this->team = $team; $this->searchable = new SearchItem(); $this->searchable->SearchItemId("team" . $team->GetId()); $this->searchable->SearchItemType("team"); $this->searchable->Url($team->GetNavigateUrl()); $this->searchable->Title($team->GetNameAndType()); $this->searchable->Description($this->GetSearchDescription()); $this->searchable->WeightOfType(1000); $keywords = array($team->GetName(), $team->GetGround()->GetAddress()->GetLocality(), $team->GetGround()->GetAddress()->GetTown()); $this->searchable->Keywords(implode(" ", $keywords)); $content = array($team->GetGround()->GetAddress()->GetAdministrativeArea(), $team->GetIntro(), $team->GetPlayingTimes(), $team->GetCost(), $team->GetContact()); $this->searchable->FullText(implode(" ", $content)); $this->searchable->RelatedLinksHtml('<ul>' . '<li><a href="' . $team->GetStatsNavigateUrl() . '">Statistics</a></li>' . '<li><a href="' . $team->GetPlayersNavigateUrl() . '">Players</a></li>' . '<li><a href="' . $team->GetCalendarNavigateUrl() . '">Match calendar</a></li>' . '</ul>'); }
function OnPageLoad() { echo new XhtmlElement('h1', 'Delete team: ' . htmlentities($this->data_object->GetName(), ENT_QUOTES, "UTF-8", false)); if ($this->deleted) { ?> <p>The team has been deleted.</p> <p><a href="/teams">View all teams</a></p> <?php } else { if ($this->has_permission) { ?> <p>Deleting a team cannot be undone. All players will be deleted, and the team will be removed from existing matches.</p> <p>Are you sure you want to delete this team?</p> <form action="<?php echo htmlentities($this->data_object->GetDeleteTeamUrl(), ENT_QUOTES, "UTF-8", false); ?> " method="post" class="deleteButtons"> <div> <input type="submit" value="Delete team" name="delete" /> <input type="submit" value="Cancel" name="cancel" /> </div> </form> <?php $this->AddSeparator(); require_once 'stoolball/user-edit-panel.class.php'; $panel = new UserEditPanel($this->GetSettings(), 'this team'); $panel->AddLink('view this team', $this->data_object->GetNavigateUrl()); $panel->AddLink('edit this team', $this->data_object->GetEditTeamUrl()); echo $panel; } else { ?> <p>Sorry, you're not allowed to delete this team.</p> <p><a href="<?php echo htmlentities($this->data_object->GetNavigateUrl(), ENT_QUOTES, "UTF-8", false); ?> ">Go back to the team</a></p> <?php } } }
function OnPageLoad() { require_once 'stoolball/statistics-calculator.class.php'; $calculator = new StatisticsCalculator(); $calculator->AnalyseMatchData($this->stats, $this->team); $title = "Team statistics for " . $this->team->GetNameAndType(); if ($this->season) { $title .= " in the {$this->season} season"; } echo "<h1>" . htmlentities($title, ENT_QUOTES, "UTF-8", false) . "</h1>"; # See what stats we've got available $has_team_stats = $calculator->EnoughDataForStats($this->season); $has_most_runs = count($this->most_runs); $has_most_wickets = count($this->most_wickets); $has_catch_stats = count($this->most_catches); $has_run_outs = count($this->most_run_outs); $has_player_of_match_stats = count($this->most_player_of_match); $has_player_stats = ($has_most_runs or $has_most_wickets or $has_catch_stats or $has_run_outs or $has_player_of_match_stats); require_once 'xhtml/navigation/tabs.class.php'; $tabs = array('Summary' => $this->team->GetNavigateUrl()); if ($has_player_stats) { $tabs['Players'] = $this->team->GetPlayersNavigateUrl(); } $tabs['Statistics'] = ''; echo new Tabs($tabs); ?> <div class="box tab-box"> <div class="dataFilter"></div> <div class="box-content"> <?php if (!$has_team_stats and !$has_player_stats) { $scope = $this->team->GetNameAndType(); if ($this->season) { $scope .= " in the {$this->season} season"; } $scope = htmlentities($scope, ENT_QUOTES, "UTF-8", false); echo "<p>There aren't any statistics for {$scope} yet.</p>" . '<p>To find out how to add them, see <a href="/play/manage/website/matches-and-results-why-you-should-add-yours/">Matches and results - why you should add yours</a>.</p>'; } else { require_once 'stoolball/team-runs-table.class.php'; require_once 'stoolball/statistics/player-statistics-table.class.php'; echo '<div class="statsGroup">'; if ($has_team_stats or $has_most_runs) { echo '<div class="statsColumns"> <h2>Batting statistics</h2> <div class="statsColumn">'; if ($has_most_runs) { echo new PlayerStatisticsTable("Most runs", "Runs", $this->most_runs, false); if ($has_most_runs >= 10) { echo '<p class="statsViewAll"><a href="/play/statistics/most-runs' . $this->statistics_query . '">Most runs – view all and filter</a></p>'; } } echo "</div><div class=\"statsColumn\">"; if ($has_team_stats) { echo new TeamRunsTable($calculator->TotalMatchesWithRunData($this->season), $calculator->RunsScored($this->season), $calculator->RunsConceded($this->season), $calculator->HighestInnings($this->season), $calculator->LowestInnings($this->season), $calculator->AverageInnings($this->season)); } if ($has_most_runs) { echo '<p class="statsViewAll"><a href="/play/statistics/individual-scores' . $this->statistics_query . '">Individual scores</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/most-scores-of-100' . $this->statistics_query . '">Most scores of 100 or more</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/most-scores-of-50' . $this->statistics_query . '">Most scores of 50 or more</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/batting-average' . $this->statistics_query . '">Batting averages</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/batting-strike-rate' . $this->statistics_query . '">Batting strike rates</a></p>'; } echo "</div></div>"; } if ($has_most_wickets or $has_team_stats) { echo '<div class="statsColumns"> <h2>Bowling statistics and match results</h2> <div class="statsColumn">'; if ($has_most_wickets) { # Show top bowlers $table = new PlayerStatisticsTable("Most wickets", "Wickets", $this->most_wickets, false); $table->SetCssClass($table->GetCssClass() . " bowling"); echo $table; if ($has_most_wickets >= 10) { echo '<p class="statsViewAll"><a href="/play/statistics/most-wickets' . $this->statistics_query . '">Most wickets – view all and filter</a></p>'; } echo '<p class="statsViewAll"><a href="/play/statistics/most-5-wickets' . $this->statistics_query . '">Most times taking 5 wickets in an innings</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/most-wickets-by-bowler-and-catcher' . $this->statistics_query . '">Most wickets by a bowling and catching combination</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/bowling-performances' . $this->statistics_query . '">Bowling performances</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/bowling-average' . $this->statistics_query . '">Bowling averages</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/economy-rate' . $this->statistics_query . '">Economy rates</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/bowling-strike-rate' . $this->statistics_query . '">Bowling strike rates</a></p>'; } ?> </div><div class="statsColumn"> <span class="chart-js-template" id="all-results-chart"></span> <span class="chart-js-template" id="home-results-chart"></span> <span class="chart-js-template" id="away-results-chart"></span> </div></div> <?php } ?> <span class="chart-js-template" id="opponents-chart"></span><?php if ($has_catch_stats or $has_run_outs) { echo '<div class="statsColumns"> <h2>Fielding statistics</h2> <div class="statsColumn">'; if ($has_catch_stats) { # Show top catchers $table = new PlayerStatisticsTable("Most catches", "Catches", $this->most_catches, false); $table->SetCssClass($table->GetCssClass() . " bowling"); echo $table; if ($has_catch_stats >= 10) { echo '<p class="statsViewAll"><a href="/play/statistics/most-catches' . $this->statistics_query . '">Most catches – view all and filter</a></p>'; } echo '<p class="statsViewAll"><a href="/play/statistics/most-catches-in-innings' . $this->statistics_query . '">Most catches in an innings – view all and filter</a></p>'; } echo "</div><div class=\"statsColumn\">"; if ($has_run_outs) { $table = new PlayerStatisticsTable("Most run-outs", "Run-outs", $this->most_run_outs, false); $table->SetCssClass($table->GetCssClass() . " bowling"); echo $table; if ($has_run_outs >= 10) { echo '<p class="statsViewAll"><a href="/play/statistics/most-run-outs' . $this->statistics_query . '">Most run-outs – view all and filter</a></p>'; } echo '<p class="statsViewAll"><a href="/play/statistics/most-run-outs-in-innings' . $this->statistics_query . '">Most run-outs in an innings – view all and filter</a></p>'; } echo "</div></div>"; } echo '<h2>All-round performance statistics</h2>'; if ($has_player_of_match_stats) { echo new PlayerStatisticsTable("Most player of the match nominations", "Nominations", $this->most_player_of_match, false); echo '<p class="statsViewAll"><a href="/play/statistics/player-performances' . $this->statistics_query . '">Player performances – view all and filter</a></p>'; echo '<p class="statsViewAll"><a href="/play/statistics/player-of-match' . $this->statistics_query . '">Player of the match nominations – view all and filter</a></p>'; if ($has_player_of_match_stats >= 10) { echo '<p class="statsViewAll"><a href="/play/statistics/most-player-of-match' . $this->statistics_query . '">Most player of the match nominations – view all and filter</a></p>'; } } else { echo '<p><a href="/play/statistics/player-performances' . $this->statistics_query . '">Player performances – view all and filter</a></p>'; } echo "</div>"; # close statsGroup # Link to other seasons if (count($calculator->SeasonYears()) > 1) { echo new XhtmlElement('h2', 'More statistics for ' . htmlentities($this->team->GetName(), ENT_QUOTES, "UTF-8", false)); echo '<div class="season-list"><ul>'; if ($this->season) { echo "<li><a href=\"" . htmlentities($this->team->GetStatsNavigateUrl(), ENT_QUOTES, "UTF-8", false) . "\">All seasons</a></li>"; } foreach ($calculator->SeasonYears() as $season_years) { $season_url = str_replace("/", "-", $season_years); # Link to season if it's not the current season. Important to use !== because # we're comparing numeric strings and with != 2009-10 is equal to 2009 if (!isset($_GET['params']) or $season_url !== $_GET["params"]) { echo "<li><a href=\"" . htmlentities($this->team->GetStatsNavigateUrl() . "/" . $season_url, ENT_QUOTES, "UTF-8", false) . "\">" . htmlentities($season_years, ENT_QUOTES, "UTF-8", false) . " season</a></li>"; } } echo "</ul></div>"; } } ?> </div> </div> <?php }
function OnLoadPageData() { /* @var $o_last_match Match */ /* @var $season Season */ /* @var $team Team */ # First best guess at where user came from is the page field posted back, # second best is tournaments page. Either can be tampered with, so there will be # a check later before they're used for redirection. If there's a context # season or team its URL will be read from the db and overwrite this later. if (isset($_POST['page'])) { $this->destination_url_if_cancelled = $_POST['page']; } else { $this->destination_url_if_cancelled = "/tournaments"; } # new data manager $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection()); $match_manager->FilterByMatchType(array(MatchType::TOURNAMENT)); # Check whether cancel was clicked if ($this->IsPostback() and $this->editor->CancelClicked()) { # new tournament, nothing saved yet, so just send user back where they came from $this->Cancel(); } # Save match if ($this->IsPostback() and $this->IsValid()) { # Get posted match $this->tournament = $this->editor->GetDataObject(); # Save match $match_manager->SaveFixture($this->tournament); if (count($this->tournament->GetAwayTeams())) { $match_manager->SaveTeams($this->tournament); } if ($this->season instanceof Season) { $this->tournament->Seasons()->Add($this->season); $match_manager->SaveSeasons($this->tournament, true); } http_response_code(303); $this->Redirect($this->tournament->AddTournamentTeamsUrl()); } if (isset($this->season)) { $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection()); $season_manager->ReadById(array($this->season->GetId())); $this->season = $season_manager->GetFirst(); $this->editor->SetContextSeason($this->season); $this->destination_url_if_cancelled = $this->season->GetNavigateUrl(); unset($season_manager); # If we're adding a match to a season, get last game in season for its date $match_manager->ReadLastInSeason($this->season->GetId()); } if (isset($this->team)) { # Get more information about the team itself require_once 'stoolball/team-manager.class.php'; $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection()); $team_manager->ReadById(array($this->team->GetId())); $this->team = $team_manager->GetFirst(); $this->editor->SetContextTeam($this->team); $this->destination_url_if_cancelled = $this->team->GetNavigateUrl(); # Get the last game already scheduled for the team to use its date $match_manager->ReadLastForTeam($this->team->GetId()); # Read teams played in the last year in order to get their grounds, which will be put at the top of the select list $team_manager->ReadRecentOpponents(array($this->team->GetId()), 12); $this->editor->ProbableTeams()->SetItems($team_manager->GetItems()); unset($team_manager); } # Use the date of the most recent tournament if it was this year, otherwise just use the default of today $o_last_match = $match_manager->GetFirst(); if (is_object($o_last_match) and gmdate('Y', $o_last_match->GetStartTime()) == gmdate('Y')) { if ($o_last_match->GetIsStartTimeKnown()) { # If the last match has a time, use it $this->editor->SetDefaultTime($o_last_match->GetStartTime()); } else { # If the last match has no time, use 11am BST $this->editor->SetDefaultTime(gmmktime(10, 0, 0, gmdate('m', $o_last_match->GetStartTime()), gmdate('d', $o_last_match->GetStartTime()), gmdate('Y', $o_last_match->GetStartTime()))); } } unset($match_manager); # Get grounds $o_ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection()); $o_ground_manager->ReadAll(); $a_grounds = $o_ground_manager->GetItems(); $this->editor->Grounds()->SetItems($a_grounds); unset($o_ground_manager); }
private function CreateTeamLink(Team $team) { $span = new XhtmlElement('span'); $span->AddAttribute("typeof", "schema:SportsTeam"); $span->AddAttribute("about", $team->GetLinkedDataUri()); $link = new XhtmlElement('a', Html::Encode($team->GetName())); $link->AddAttribute("property", "schema:name"); $link->AddAttribute('href', $team->GetNavigateUrl()); $link->AddAttribute("rel", "schema:url"); $span->AddControl($link); return $span; }
function OnLoadPageData() { /* @var $o_match Match */ /* @var $o_team Team */ # new data manager $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection()); # create repeater control, and save any posted data $this->repeater = new DataEditRepeater($this, 'CreateEditControl'); $this->repeater->SetCssClass('matchResults'); $this->repeater->SetPersistedParameters(array('team', 'season', "tournament")); $this->repeater->SetButtonText('Save all results'); $this->repeater->SetShowButtonsAtTop(true); if ($this->IsPostback() and !$this->IsRefresh() and $this->IsValid()) { require_once 'forums/topic-manager.class.php'; require_once 'forums/review-item.class.php'; require_once 'forums/subscription-manager.class.php'; $topic_manager = new TopicManager($this->GetSettings(), $this->GetDataConnection()); foreach ($this->repeater->GetDataObjects() as $o_current_match) { /* @var $o_current_match Match */ $match_manager->SaveResult($o_current_match); $match_manager->ExpandMatchUrl($o_current_match); $match_manager->NotifyMatchModerator($o_current_match->GetId()); if (trim($o_current_match->GetNewComment())) { $item_to_comment_on = new ReviewItem($this->GetSettings()); $item_to_comment_on->SetType(ContentType::STOOLBALL_MATCH); $item_to_comment_on->SetId($o_current_match->GetId()); $item_to_comment_on->SetNavigateUrl("https://" . $this->GetSettings()->GetDomain() . $o_current_match->GetNavigateUrl()); $message = $topic_manager->SaveComment($item_to_comment_on, $o_current_match->GetNewComment()); # send subscription emails - new object each time to reset list of who's already recieved an email $subs_manager = new SubscriptionManager($this->GetSettings(), $this->GetDataConnection()); $subs_manager->SendCommentsSubscriptions($item_to_comment_on, $message); unset($subs_manager); } } $this->b_saved = true; } # get matches if (!is_null($this->i_team_id)) { $a_season_times = Season::SeasonDates(); $match_manager->FilterByTeam(array($this->i_team_id)); $match_manager->FilterByDateStart($a_season_times[0]); $match_manager->FilterByDateEnd($a_season_times[1]); $match_manager->ReadMatchSummaries(); } else { if (!is_null($this->i_season_id)) { $match_manager->ReadBySeasonId(array($this->i_season_id), true); } else { if (!is_null($this->tournament_id)) { $match_manager->FilterByTournament($this->tournament_id); $this->a_matches = $match_manager->ReadMatchSummaries(); } } } $this->a_matches = $match_manager->GetItems(); # Make sure we have some matches if (count($this->a_matches)) { # If it's matches for a team, get the team if (!is_null($this->i_team_id)) { # Should only need to look at the first match, because the team must be a # part of that match in order for the match to be in this list $o_match =& $this->a_matches[0]; $o_team = $o_match->GetHomeTeam(); if ($o_team instanceof Team and $o_team->GetId() == $this->i_team_id) { $this->team = $o_team; } else { foreach ($o_match->GetAwayTeams() as $o_team) { if ($o_team->GetId() == $this->i_team_id) { $this->team = $o_team; break; } } } if (!is_object($this->team)) { $this->Redirect(); } # Now that we have short URL data, if data has just been saved for team, redirect back to team if ($this->b_saved) { $this->Redirect($this->team->GetNavigateUrl()); } } else { if (!is_null($this->i_season_id)) { # get details of the season require_once 'stoolball/competition-manager.class.php'; $o_comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $o_comp_manager->ReadById(null, array($this->i_season_id)); $o_competition = $o_comp_manager->GetFirst(); unset($o_comp_manager); if ($o_competition instanceof Competition) { $this->season = $o_competition->GetWorkingSeason(); } if (!$this->season instanceof Season) { $this->Redirect(); } # Now that we have short URL data, if data has just been saved for season, redirect back to season if ($this->b_saved) { $this->Redirect($this->season->GetNavigateUrl()); } } else { if (!is_null($this->tournament_id)) { $match_manager->ReadByMatchId(array($this->tournament_id)); $this->tournament = $match_manager->GetFirst(); if (!is_null($this->tournament)) { # If the tournament has just been saved, now we have its URL so redirect to the thanks page if ($this->b_saved) { $this->Redirect($this->tournament->GetNavigateUrl()); } } } } } } else { $this->Redirect(); } unset($match_manager); }
public function OnPageLoad() { echo '<article typeof="schema:SportsTeam" about="' . htmlentities($this->team->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">'; echo '<h1>Players for <span property="schema:name">' . htmlentities($this->team->GetName(), ENT_QUOTES, "UTF-8", false) . "</span></h1>"; require_once 'xhtml/navigation/tabs.class.php'; $tabs = array('Summary' => $this->team->GetNavigateUrl()); $tabs['Players'] = ''; $tabs['Statistics'] = $this->team->GetStatsNavigateUrl(); echo new Tabs($tabs); ?> <div class="box tab-box"> <div class="dataFilter"></div> <div class="box-content"> <?php if (count($this->players) > 4) { $threshold = (int) gmdate("Y") - 1; $list_open = false; echo '<div class="player-list">'; foreach ($this->players as $player) { /* @var $player Player */ if ($player->GetPlayerRole() == Player::PLAYER and (gmdate("Y", $player->GetLastPlayedDate()) >= $threshold or $player->GetLastPlayedDate() == 0)) { if (!$list_open) { echo '<h2>Current and recent players</h2><ol rel="schema:members">'; $list_open = true; } echo '<li typeof="schema:Person" about="' . htmlentities($player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '"><a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a></li>"; } } if ($list_open) { echo "</ol>"; } $list_open = false; foreach ($this->players as $player) { /* @var $player Player */ if ($player->GetPlayerRole() == Player::PLAYER and gmdate("Y", $player->GetLastPlayedDate()) < $threshold and $player->GetLastPlayedDate() != 0) { if (!$list_open) { echo '<h2>Former players</h2><ol rel="schema:members">'; $list_open = true; } echo '<li typeof="schema:Person" about="' . htmlentities($player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '"><a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a></li>"; } } if ($list_open) { echo "</ol>"; } $list_open = false; foreach ($this->players as $player) { /* @var $player Player */ if ($player->GetPlayerRole() != Player::PLAYER) { if (!$list_open) { echo "<h2>Extras</h2><ul>"; $list_open = true; } echo '<li><a href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a></li>"; } } if ($list_open) { echo "</ul>"; } echo "</div>"; } else { ?> <p>There aren't any player statistics for this team yet.</p> <p>To find out how to add them, see <a href="/play/manage/website/matches-and-results-why-you-should-add-yours/">Matches and results – why you should add yours</a>.</p> <?php } ?> </div> </div> </article> <?php $this->AddSeparator(); if (AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->team->GetLinkedDataUri())) { # Create a panel with actions $panel = new UserEditPanel($this->GetSettings()); $panel->AddCssClass("with-tabs"); #$panel->AddLink("add a player", $this->team->GetPlayerAddNavigateUrl()); echo $panel; $this->BuySomething(); } else { echo '<div class="with-tabs">'; $this->BuySomething(); echo '</div>'; } }