コード例 #1
0
 function OnLoadPageData()
 {
     # new data managers
     $o_comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
     $o_team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     # get comps
     $o_comp_manager->SetExcludeInactive(true);
     $o_comp_manager->ReadAllSummaries();
     $this->a_comps = $o_comp_manager->GetItems();
     # get teams
     $o_team_manager->FilterByActive(true);
     foreach ($this->a_comps as $o_comp) {
         /* @var $o_comp Competition */
         $a_seasons = array($o_comp->GetLatestSeason()->GetId());
         $o_team_manager->ReadBySeasonId($a_seasons);
         while ($o_team_manager->MoveNext()) {
             $o_comp->GetLatestSeason()->AddTeam($o_team_manager->GetItem());
         }
         $o_team_manager->Clear();
     }
     # tidy up
     unset($o_comp_manager);
     unset($o_team_manager);
 }
コード例 #2
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;
     }
 }
コード例 #3
0
 function OnLoadPageData()
 {
     /* @var $match_manager MatchManager */
     /* @var $editor TournamentEditControl */
     # get id of Match
     $i_id = $this->match_manager->GetItemId();
     if (!$i_id) {
         return;
     }
     # no need to read if redisplaying invalid form
     if ($this->IsValid()) {
         $this->match_manager->ReadByMatchId(array($i_id));
         $this->tournament = $this->match_manager->GetFirst();
         if ($this->tournament instanceof Match) {
             $this->b_user_is_match_owner = AuthenticationManager::GetUser()->GetId() == $this->tournament->GetAddedBy()->GetId();
             $this->b_is_tournament = $this->tournament->GetMatchType() == MatchType::TOURNAMENT;
         } else {
             return;
         }
     }
     if ($this->b_user_is_match_admin or $this->b_user_is_match_owner) {
         # 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->Grounds()->SetItems($o_ground_manager->GetItems());
         unset($o_ground_manager);
         # get teams in seasons, in order to promote home grounds of teams
         $season_ids = array();
         foreach ($this->tournament->Seasons() as $season) {
             $season_ids[] = $season->GetId();
         }
         require_once 'stoolball/team-manager.class.php';
         $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
         if (count($season_ids)) {
             $team_manager->ReadBySeasonId($season_ids);
             $this->editor->ProbableTeams()->SetItems($team_manager->GetItems());
         }
         unset($team_manager);
     }
 }
コード例 #4
0
 function OnLoadPageData()
 {
     /* @var $o_last_match Match */
     /* @var $season Season */
     /* @var $team Team */
     # new data manager
     $o_match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     # Collect season to add this match to, starting with the URL
     # get season and teams (was at this stage because editor needed teams to build its
     # posted data object, but that's no longer the case so probably could be later if needed)
     if (isset($this->i_season_id)) {
         $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
         $season_manager->ReadById(array($this->i_season_id));
         $this->season = $season_manager->GetFirst();
         unset($season_manager);
         $this->edit->Seasons()->Add($this->season);
         # If there are at least 2 teams in the season, show only those teams, otherwise show all teams of the relevant player type
         if (count($this->season->GetTeams()) > 1) {
             $this->edit->SetTeams(array($this->season->GetTeams()));
         } else {
             require_once 'stoolball/team-manager.class.php';
             $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
             $team_manager->FilterByPlayerType(array($this->season->GetCompetition()->GetPlayerType()));
             $team_manager->ReadTeamSummaries();
             $this->edit->SetTeams(array($team_manager->GetItems()));
             unset($team_manager);
         }
     }
     # Not elseif, because when you've added a match there's a season, but we still need this to run to populate
     # the choices for the next match to be added
     if ($this->team instanceof Team) {
         # Otherwise it should be a 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();
         if (!is_null($this->team)) {
             $this->edit->SetContextTeam($this->team);
             $season_ids = array();
             $team_groups = array();
             $a_exclude_team_ids = array();
             $team_manager->FilterByActive(true);
             # Add the home team first
             $team_groups[] = array($this->team);
             $a_exclude_team_ids[] = $this->team->GetId();
             # Get the seasons this team is in...
             $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
             if ($this->i_match_type == MatchType::FRIENDLY) {
                 # For a friendly, any group of teams they play with is fine
                 $season_manager->ReadCurrentSeasonsByTeamId(array($this->team->GetId()));
             } else {
                 # For anything else, get the seasons *for this type of match*
                 $season_manager->ReadCurrentSeasonsByTeamId(array($this->team->GetId()), array($this->i_match_type));
             }
             $seasons = $season_manager->GetItems();
             unset($season_manager);
             $this->edit->Seasons()->Clear();
             # on postback, the season just added is already there, so clear to prevent a duplicate
             foreach ($seasons as $season) {
                 $this->edit->Seasons()->Add($season);
                 $season_ids[] = $season->GetId();
             }
             #... and their opponent teams in those seasons
             if (count($season_ids)) {
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadBySeasonId($season_ids);
                 $season_teams = $team_manager->GetItems();
                 if (count($season_teams)) {
                     $team_groups['This season\'s teams'] = $season_teams;
                 }
                 foreach ($season_teams as $team) {
                     $a_exclude_team_ids[] = $team->GetId();
                 }
             }
             # ...and if this is a friendly it could be any other team
             if ($this->i_match_type == MatchType::FRIENDLY) {
                 # get any other teams they played in the last 2 years, and combine with existing results
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadRecentOpponents(array($this->team->GetId()), 24);
                 $recent_opponents = $team_manager->GetItems();
                 if (count($recent_opponents)) {
                     $team_groups['Recent opponents'] = $recent_opponents;
                 }
                 foreach ($recent_opponents as $team) {
                     $a_exclude_team_ids[] = $team->GetId();
                 }
                 # get any other teams they might play, and combine with existing results
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadAll();
                 $team_groups['Other teams'] = $team_manager->GetItems();
             }
             # What if there are still no opponents to choose from? In that case select all teams.
             if (count($team_groups) == 1) {
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadAll();
                 $team_groups[] = $team_manager->GetItems();
             }
             # Offer those teams to select from
             if ($total_groups = count($team_groups)) {
                 # If only two groups (home team + 1 group), don't group teams. Remove the only key from the array.
                 if ($total_groups == 2) {
                     $keys = array_keys($team_groups);
                     $team_groups = array($team_groups[$keys[0]], $team_groups[$keys[1]]);
                 }
                 $this->edit->SetTeams($team_groups);
             }
         }
         unset($team_manager);
     }
     # Save match
     if ($this->IsPostback() and $this->IsValid()) {
         # Get posted match
         $this->match = $this->edit->GetDataObject();
         if (!$this->IsRefresh()) {
             # Save match
             $o_match_manager->SaveFixture($this->match);
             $o_match_manager->SaveSeasons($this->match, true);
             $o_match_manager->NotifyMatchModerator($this->match->GetId());
             # Update 'next 5 matches'
             $o_match_manager->ReadNext();
             $this->a_next_matches = $o_match_manager->GetItems();
         }
         # Reset control for new match
         $this->edit->SetDataObject(new Match($this->GetSettings()));
     }
     $o_match_manager->FilterByMatchType(array($this->i_match_type));
     if (isset($this->i_season_id)) {
         # If we're adding a match to a season, get last game in season for its date
         $o_match_manager->ReadLastInSeason($this->season->GetId());
     } else {
         if ($this->team instanceof Team) {
             # Get the last game already scheduled for the team to use its date
             $o_match_manager->ReadLastForTeam($this->team->GetId());
         }
     }
     $o_last_match = $o_match_manager->GetFirst();
     if (is_object($o_last_match)) {
         $current_season = Season::SeasonDates();
         if (gmdate('Y', $o_last_match->GetStartTime()) < gmdate('Y', $current_season[0])) {
             # If the last match this team played was last season, use the time but not the date
             $this->edit->SetDefaultTime(gmmktime(gmdate('H', $o_last_match->GetStartTime()), gmdate('i', $o_last_match->GetStartTime()), 0, gmdate('m'), gmdate('d'), gmdate('Y')));
         } else {
             # If the last match was this season and has a time, use it
             if ($o_last_match->GetIsStartTimeKnown()) {
                 $this->edit->SetDefaultTime($o_last_match->GetStartTime());
             } else {
                 # If the last match has no time, use 6.30pm BST
                 $this->edit->SetDefaultTime(gmmktime(17, 30, 0, gmdate('m', $o_last_match->GetStartTime()), gmdate('d', $o_last_match->GetStartTime()), gmdate('Y', $o_last_match->GetStartTime())));
             }
         }
     }
     unset($o_match_manager);
     # Get grounds
     $o_ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
     $o_ground_manager->ReadAll();
     $a_grounds = $o_ground_manager->GetItems();
     $this->edit->SetGrounds($a_grounds);
     unset($o_ground_manager);
 }