function OnLoadPageData() { # get item to be deleted if (!is_object($this->data_object)) { $id = $this->manager->GetItemId($this->data_object); $this->manager->ReadById(array($id)); $this->data_object = $this->manager->GetFirst(); } # tidy up unset($this->manager); }
public function OnLoadPageData() { require_once 'stoolball/competition-manager.class.php'; $manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); if ($this->season_id) { $manager->ReadById(null, array($this->season_id)); } else { $manager->ReadById(array($this->competition_id)); } $this->competition = $manager->GetFirst(); $this->season = $this->competition->GetWorkingSeason(); unset($manager); # If the competition was requested, redirect to the current season if ($this->competition_id) { http_response_code(303); header("Location: " . $this->season->GetMapUrl()); return; } $this->has_map = count($this->season->GetTeams()); # Get other seasons require_once 'stoolball/season-manager.class.php'; $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); } } }
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); }
public function OnLoadPageData() { require_once 'stoolball/competition-manager.class.php'; $manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $manager->ReadById(null, array($this->season_id)); $competition = $manager->GetFirst(); unset($manager); if (!$competition instanceof Competition) { return; } require_once 'stoolball/ground-manager.class.php'; $manager = new GroundManager($this->GetSettings(), $this->GetDataConnection()); $manager->FilterBySeason(array($competition->GetWorkingSeason()->GetId())); $manager->ReadAll(); $grounds = $manager->GetItems(); unset($manager); ?> $(function() { // Make the placeholder big enough for a map var mapControl = document.getElementById("map"); mapControl.style.width = '100%'; mapControl.style.height = '500px'; // Create the map var var bounds = new google.maps.LatLngBounds(); var myOptions = { mapTypeId : google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(mapControl, myOptions); var markers = []; var info; <?php foreach ($grounds as $ground) { /* @var $ground Ground */ if (!$ground->GetAddress()->GetLatitude() or !$ground->GetAddress()->GetLongitude()) { continue; } $content = "'<div class=\"map-info\">' +\n\t'<h2>" . str_replace("'", "\\'", Html::Encode($ground->GetNameAndTown())) . "</h2>' +\n\t'<p>Home to: "; $teams = $ground->Teams()->GetItems(); $length = count($teams); for ($i = 0; $i < $length; $i++) { if ($i > 0 and $i == $length - 1) { $content .= " and "; } else { if ($i > 0) { $content .= ", "; } } $content .= '<a href="' . Html::Encode($teams[$i]->GetNavigateUrl()) . '">' . str_replace("'", "\\'", Html::Encode($teams[$i]->GetNameAndType())) . '</a>'; } $content .= "</p></div>'"; # And marker and click event to trigger info window. Wrap info window in function to isolate marker, otherwise the last marker # is always used for the position of the info window. echo "var marker = new google.maps.Marker({\n\t\t\tposition : new google.maps.LatLng(" . $ground->GetAddress()->GetLatitude() . "," . $ground->GetAddress()->GetLongitude() . "),\n\t\t\tshadow: Stoolball.Maps.WicketShadow(),\n\t\t\ticon: Stoolball.Maps.WicketIcon(),\n\t\t\ttitle : '" . str_replace("'", "\\'", $ground->GetNameAndTown()) . "'\n\t\t });\n\t\t markers.push(marker);\n\t\t bounds.extend(marker.position);\n\n\t\t (function(marker){\n\t\t\t google.maps.event.addListener(marker, 'click', function()\n\t\t\t {\n\t\t\t \tvar content = {$content};\n\t\t\t \tif (!info) info = new google.maps.InfoWindow();\n\t\t\t \tinfo.setContent(content);\n\t\t\t \tinfo.open(map, marker);\n\t\t\t });\n\t\t })(marker);\n\t\t "; } ?> map.fitBounds(bounds); var style = [{ url: '/images/features/map-markers.gif', height: 67, width: 31, textColor: '#ffffff', textSize: 10 }]; var clusterer = new MarkerClusterer(map, markers, { 'gridSize': 30, styles: style}); }); <?php exit; }
function OnPostback() { $this->season = $this->edit->GetDataObject(); if (!$this->season->GetId()) { $existing_season_id = $this->season_manager->CheckIfSeasonExists($this->season->GetCompetition()->GetId(), $this->season->GetStartYear(), $this->season->GetEndYear()); if ($existing_season_id) { require_once 'data/validation/required-field-validator.class.php'; $season = new Season($this->GetSettings()); $season->SetId($existing_season_id); $validator = new RequiredFieldValidator('This_Validator_Will_Fail', "The season you're adding already exists – <a href=\"" . $season->GetNavigateUrl() . "\">edit season</a>"); $validator->SetValidIfNotFound(false); $this->edit->AddValidator($validator); } } # Get the competition. This is used to build the page title and, when saving, the short URL. # It is also re-indexed in search below. $this->competition_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $this->competition_manager->ReadById(array($this->season->GetCompetition()->GetId())); $this->season->SetCompetition($this->competition_manager->GetFirst()); unset($this->competition_manager); # save data if valid if ($this->IsValid()) { $b_saved_new = !(bool) $this->season->GetId(); $id = $this->season_manager->SaveSeason($this->season); $this->season->SetId($id); # Add the competition to the search engine. Re-request so we have team names as well as IDs. require_once "search/competition-search-adapter.class.php"; $this->SearchIndexer()->DeleteFromIndexById("competition" . $this->season->GetCompetition()->GetId()); $adapter = new CompetitionSearchAdapter($this->season->GetCompetition()); $this->SearchIndexer()->Index($adapter->GetSearchableItem()); $this->SearchIndexer()->CommitChanges(); # If just saved a new season, redirect to load this page from scratch # (When just loading data on this page, didn't load correctly into aggregated editors) if ($b_saved_new) { $this->Redirect($this->season->GetEditSeasonUrl()); } $this->Redirect($this->season->GetNavigateUrl()); } }
public function OnLoadPageData() { if (!is_null($this->i_match_id)) { require_once 'stoolball/match-manager.class.php'; $o_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection()); $o_manager->ReadByMatchId(array($this->i_match_id)); $o_match = $o_manager->GetFirst(); if ($o_match instanceof Match) { $this->s_cal_title = $o_match->GetTitle() . ' – ' . $o_match->GetStartTimeFormatted(); $this->s_cal_url = $o_match->GetCalendarNavigateUrl(); } unset($o_manager); } else { if (!is_null($this->i_team_id)) { require_once 'stoolball/team-manager.class.php'; $o_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection()); $o_manager->ReadById(array($this->i_team_id)); $o_team = $o_manager->GetFirst(); if ($o_team instanceof Team) { $this->s_cal_title = $o_team->GetName() . '\'s current season'; $this->s_cal_url = $o_team->GetCalendarNavigateUrl(); } unset($o_manager); } else { if (!is_null($this->i_season_id)) { require_once 'stoolball/competition-manager.class.php'; $o_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $o_manager->ReadById(null, array($this->i_season_id)); $o_comp = $o_manager->GetFirst(); if ($o_comp instanceof Competition) { $o_season = $o_comp->GetWorkingSeason(); $this->s_cal_title = $o_season->GetCompetitionName(); $this->s_cal_url = $o_season->GetCalendarNavigateUrl(); } unset($o_manager); } else { if ($this->tournament_player_type) { $this->s_matches = $this->tournament_player_type . " tournaments"; $this->s_cal_url = "/tournaments/" . $this->tournament_player_type . "/calendar"; } } } } if (is_null($this->s_cal_url)) { header('Location: /play/'); exit; } }
function OnLoadPageData() { /* @var $o_competition Competition */ # check parameter if (!isset($_GET['season']) or !is_numeric($_GET['season'])) { http_response_code(400); exit; } if (isset($_GET['season']) and is_numeric($_GET['season'])) { $comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $comp_manager->ReadById(null, array($_GET['season'])); $this->competition = $comp_manager->GetFirst(); unset($comp_manager); } # must have found a competition if (!$this->competition instanceof Competition) { http_response_code(404); exit; } $this->season = $this->competition->GetWorkingSeason(); if (is_object($this->season)) { # 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); # 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); } else { # Must have a season http_response_code(404); exit; } }
function OnPostback() { # Get the item info and store it $id = $this->manager->GetItemId($this->data_object); $this->manager->ReadById(array($id)); $this->data_object = $this->manager->GetFirst(); # Check whether cancel was clicked if (isset($_POST['cancel'])) { $this->Redirect($this->data_object->GetNavigateUrl()); } # Check whether delete was clicked if (isset($_POST['delete'])) { # Only offer delete option if there's more than one season. Don't want to delete last season because # that leaves an empty competition which won't display. Instead, must delete whole competition with its one remaining season. # How many seasons in this competition? if (is_object($this->data_object) and $this->data_object->GetCompetition() instanceof Competition and $this->data_object->GetCompetition()->GetId()) { $this->manager->Clear(); $this->manager->ReadByCompetitionId(array($this->data_object->GetCompetition()->GetId())); $this->seasons_in_competition = $this->manager->GetCount(); } if ($this->seasons_in_competition > 1) { # Check again that the requester has permission to delete this item if ($this->has_permission) { # Delete it $this->manager->Delete(array($id)); # Update the competition in the search engine, because the latest season may have changed. require_once 'stoolball/competition-manager.class.php'; require_once "search/competition-search-adapter.class.php"; $this->SearchIndexer()->DeleteFromIndexById("competition" . $this->data_object->GetCompetition()->GetId()); $competition_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $competition_manager->ReadById(array($this->data_object->GetCompetition()->GetId())); $competition = $competition_manager->GetFirst(); $adapter = new CompetitionSearchAdapter($competition); $this->SearchIndexer()->Index($adapter->GetSearchableItem()); $this->SearchIndexer()->CommitChanges(); # Note success $this->deleted = true; } } } }
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); }
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); }