コード例 #1
0
 function OnPageInit()
 {
     $this->manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $this->manager->FilterByTeamType(array());
     $this->has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS);
     if (!$this->has_permission) {
         header("HTTP/1.1 401 Unauthorized");
     }
     parent::OnPageInit();
 }
コード例 #2
0
 function OnLoadPageData()
 {
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         $this->Redirect();
     }
     # new data managers
     $ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
     # get ground
     $ground_manager->ReadById(array($_GET['item']));
     $this->ground = $ground_manager->GetFirst();
     # must have found a ground
     if (!$this->ground instanceof Ground) {
         $this->Redirect();
     }
     # Get teams based at the ground
     require_once "stoolball/team-manager.class.php";
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByGround(array($this->ground->GetId()));
     $team_manager->FilterByTeamType(array(Team::CLOSED_GROUP, Team::OCCASIONAL, Team::REGULAR, Team::REPRESENTATIVE, Team::SCHOOL_YEARS, Team::SCHOOL_CLUB, Team::SCHOOL_OTHER));
     $team_manager->ReadTeamSummaries();
     $this->ground->Teams()->SetItems($team_manager->GetItems());
     # Update search engine
     if ($this->ground->GetSearchUpdateRequired()) {
         require_once "search/ground-search-adapter.class.php";
         $this->SearchIndexer()->DeleteFromIndexById("ground" . $this->ground->GetId());
         $adapter = new GroundSearchAdapter($this->ground);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
         $this->SearchIndexer()->CommitChanges();
         $ground_manager->SearchUpdated($this->ground->GetId());
     }
     unset($team_manager);
     unset($ground_manager);
     # Read statistics highlights for the ground
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     $statistics_manager->FilterByGround(array($this->ground->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);
 }
 function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Club/ facility name", "Address 1", "Address 2", "Address 3", "Address 4", "Address 5", "City", "Postcode", "Country", "Tel", "Email", "Website", "Activities", "Opening times");
     require_once 'stoolball/team-manager.class.php';
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByTeamType(array(Team::REGULAR));
     $team_manager->ReadById();
     while ($team_manager->MoveNext()) {
         /* @var $team Team */
         $team = $team_manager->GetItem();
         # NHS choices can only import records with a postcode
         if (!$team->GetGround()->GetAddress()->GetPostcode()) {
             continue;
         }
         $address = array();
         if ($team->GetGround()->GetAddress()->GetSaon()) {
             $address[] = $team->GetGround()->GetAddress()->GetSaon();
         }
         if ($team->GetGround()->GetAddress()->GetPaon()) {
             $address[] = $team->GetGround()->GetAddress()->GetPaon();
         }
         if ($team->GetGround()->GetAddress()->GetStreetDescriptor()) {
             $address[] = $team->GetGround()->GetAddress()->GetStreetDescriptor();
         }
         if ($team->GetGround()->GetAddress()->GetLocality()) {
             $address[] = $team->GetGround()->GetAddress()->GetLocality();
         }
         if ($team->GetGround()->GetAddress()->GetAdministrativeArea()) {
             $address[] = $team->GetGround()->GetAddress()->GetAdministrativeArea();
         }
         $data[] = array($team->GetName() . " Stoolball Club", isset($address[0]) ? $address[0] : "", isset($address[1]) ? $address[1] : "", isset($address[2]) ? $address[2] : "", isset($address[3]) ? $address[3] : "", isset($address[4]) ? $address[4] : "", $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), "stoolball", preg_replace('/\\[[^]]+\\]/', "", $team->GetPlayingTimes()));
     }
     unset($team_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
コード例 #4
0
 function OnLoadPageData()
 {
     /* @var Team $team */
     # check parameter
     if (!isset($_GET['item']) or !is_numeric($_GET['item'])) {
         $this->Redirect();
     }
     # get team
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByTeamType(array());
     $team_manager->ReadById(array($_GET['item']));
     $this->team = $team_manager->GetFirst();
     unset($team_manager);
     # must have found a team
     if (!$this->team instanceof Team) {
         $this->Redirect('/teams/');
     }
     # get match stats
     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->ReadMatchStatistics();
     $this->stats = $statistics_manager->GetItems();
     # Get some stats on the best players
     $this->statistics_query = "?team=" . $this->team->GetId();
     if ($this->season) {
         # use midpoint of season to get season dates for filter
         $start_year = substr($this->season, 0, 4);
         $end_year = strlen($this->season) == 7 ? $start_year + 1 : $start_year;
         if ($start_year == $end_year) {
             $season_dates = Season::SeasonDates(mktime(0, 0, 0, 7, 1, $start_year));
         } else {
             $season_dates = Season::SeasonDates(mktime(0, 0, 0, 12, 31, $start_year));
         }
         $statistics_manager->FilterAfterDate($season_dates[0]);
         $statistics_manager->FilterBeforeDate($season_dates[1]);
         $this->statistics_query .= "&from=" . $season_dates[0] . "&to=" . $season_dates[1];
     }
     $statistics_manager->FilterMaxResults(10);
     $this->most_runs = $statistics_manager->ReadBestPlayerAggregate("runs_scored");
     $this->most_wickets = $statistics_manager->ReadBestPlayerAggregate("wickets");
     $this->most_catches = $statistics_manager->ReadBestPlayerAggregate("catches");
     $this->most_run_outs = $statistics_manager->ReadBestPlayerAggregate("run_outs");
     $this->most_player_of_match = $statistics_manager->ReadBestPlayerAggregate("player_of_match");
     unset($statistics_manager);
 }
コード例 #5
0
 function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Team id", "Team name", "Player type", "Home ground name", "Street name", "Locality", "Town", "Administrative area", "Postcode", "Country", "Latitude", "Longitude", "Contact phone", "Contact email", "Website", "Description");
     require_once 'stoolball/team-manager.class.php';
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByTeamType(array(Team::REGULAR));
     $team_manager->ReadById();
     while ($team_manager->MoveNext()) {
         $team = $team_manager->GetItem();
         /* @var $team Team */
         # Spogo can only import records with contact details
         if (!$team->GetContactPhone() and !$team->GetContactEmail()) {
             continue;
         }
         # Combine free text fields into a description field
         $description = $team->GetIntro();
         if ($description) {
             $description .= "\n\n";
         }
         if ($team->GetPlayingTimes()) {
             $description .= $team->GetPlayingTimes() . "\n\n";
         }
         if ($team->GetCost()) {
             $description .= $team->GetCost();
         }
         # Add this team to the data array
         $data[] = array($team->GetId(), $team->GetName() . " Stoolball Club", PlayerType::Text($team->GetPlayerType()), $team->GetGround()->GetAddress()->GetPaon(), $team->GetGround()->GetAddress()->GetStreetDescriptor(), $team->GetGround()->GetAddress()->GetLocality(), $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetAdministrativeArea(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $team->GetGround()->GetAddress()->GetLatitude(), $team->GetGround()->GetAddress()->GetLongitude(), $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), trim(html_entity_decode(strip_tags($description), ENT_QUOTES)));
     }
     unset($team_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
コード例 #6
0
 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;
     }
 }
コード例 #7
0
 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);
 }