本文整理汇总了PHP中Team::GetId方法的典型用法代码示例。如果您正苦于以下问题:PHP Team::GetId方法的具体用法?PHP Team::GetId怎么用?PHP Team::GetId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Team
的用法示例。
在下文中一共展示了Team::GetId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: OnLoadPageData
public function OnLoadPageData()
{
$player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection());
$player_manager->ReadPlayersInTeam(array($this->team->GetId()));
$this->players = $player_manager->GetItems();
unset($player_manager);
if (count($this->players)) {
$this->team = $this->players[0]->Team();
}
}
示例2: BuildPostedItem
/**
* Re-build from data posted by this control a single data object which this control is editing
*
* @param int $i_counter
* @param int $i_id
*/
protected function BuildPostedItem($i_counter = null, $i_id = null)
{
$s_key = $this->GetNamingPrefix() . 'Points' . $i_counter;
$s_award_key = $this->GetNamingPrefix() . 'Awarded' . $i_counter;
$i_points = (int) (isset($_POST[$s_key]) and is_numeric($_POST[$s_key])) ? $_POST[$s_key] : 0;
if (isset($_POST[$s_award_key]) and $_POST[$s_award_key] == '2') {
$i_points = $i_points - $i_points * 2;
}
$s_key = $this->GetNamingPrefix() . 'PointsTeam' . $i_counter;
$o_team = null;
$o_team = new Team($this->GetSettings());
if (isset($_POST[$s_key]) and is_numeric($_POST[$s_key])) {
$o_team->SetId($_POST[$s_key]);
}
$s_key = $this->GetNamingPrefix() . 'Reason' . $i_counter;
$s_reason = (isset($_POST[$s_key]) and strlen($_POST[$s_key]) <= 200) ? $_POST[$s_key] : '';
if ($i_points != 0 or $o_team->GetId() or $s_reason) {
$o_adjust = new PointsAdjustment($i_id, $i_points, $o_team, $s_reason);
$i_date = $this->BuildPostedItemModifiedDate($i_counter, $o_adjust);
$o_adjust->SetDate($i_date);
$this->DataObjects()->Add($o_adjust);
} else {
$this->IgnorePostedItem($i_counter);
}
}
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:31,代码来源:points-adjustments-editor.class.php
示例3: OnLoadPageData
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);
}
示例4: OnPostback
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());
}
}
示例5: __construct
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>');
}
示例6: BuildPostedItem
/**
* Re-build from data posted by this control a single data object which this control is editing
*
* @param int $i_counter
* @param int $i_id
*/
protected function BuildPostedItem($i_counter = null, $i_id = null)
{
$s_key = $this->GetNamingPrefix() . 'Team' . $i_counter;
$o_team = null;
$o_team = new Team($this->GetSettings());
if (isset($_POST[$s_key]) and is_numeric($_POST[$s_key])) {
$o_team->SetId($_POST[$s_key]);
}
$s_key = $this->GetNamingPrefix() . 'TeamValue' . $i_counter;
if (isset($_POST[$s_key])) {
$o_team->SetName($_POST[$s_key]);
}
$s_key = $this->GetNamingPrefix() . 'WithdrawnLeague' . $i_counter;
$b_withdrawn_league = (isset($_POST[$s_key]) and $_POST[$s_key] == '1');
if ($o_team->GetId() or $b_withdrawn_league) {
$team_in_season = new TeamInSeason($o_team, null, $b_withdrawn_league);
$this->DataObjects()->Add($team_in_season);
} else {
$this->IgnorePostedItem($i_counter);
}
}
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:27,代码来源:teams-in-season-editor.class.php
示例7: GetDataObjectHash
/**
* Gets a hash of the specified team
*
* @param Team $data_object
* @return string
*/
protected function GetDataObjectHash($data_object)
{
return $this->GenerateHash(array($data_object->GetId()));
}
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:10,代码来源:teams-in-tournament-editor.class.php
示例8: CreateFixtureControls
/**
* Creates the controls when the editor is in its fixture view
*
*/
private function CreateFixtureControls(Match $match, XhtmlElement $match_box)
{
$css_class = 'TournamentEdit';
if ($this->GetCssClass()) {
$css_class .= ' ' . $this->GetCssClass();
}
$match_outer_1 = new XhtmlElement('div');
$match_outer_1->SetCssClass($css_class);
$this->SetCssClass('');
$match_outer_1->SetXhtmlId($this->GetNamingPrefix());
$match_outer_2 = new XhtmlElement('div');
$this->AddControl($match_outer_1);
$match_outer_1->AddControl($match_outer_2);
$match_outer_2->AddControl($match_box);
if ($match->GetId()) {
$heading = "Edit tournament";
} else {
$heading = "Add your tournament";
}
if ($this->show_step_number) {
$heading .= ' – step 1 of 3';
}
$o_title_inner_1 = new XhtmlElement('span', $heading);
$o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
$o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
$match_box->AddControl(new XhtmlElement('h2', $o_title_inner_3, "large"));
# Tournament title
$suggested_title = $match->GetTitle();
if (isset($this->context_season)) {
$suggested_title = $this->GetContextSeason()->GetCompetition()->GetName();
if (strpos(strtolower($suggested_title), 'tournament') === false) {
$suggested_title .= ' tournament';
}
} else {
if (isset($this->context_team)) {
$suggested_title = $this->GetContextTeam()->GetName();
if (strpos(strtolower($suggested_title), 'tournament') === false) {
$suggested_title .= ' tournament';
}
}
}
if ($suggested_title == "To be confirmed tournament") {
$suggested_title = "";
}
if ($suggested_title == "To be confirmed v To be confirmed") {
$suggested_title = "";
}
$title = new TextBox($this->GetNamingPrefix() . 'Title', $suggested_title, $this->IsValidSubmit());
$title->SetMaxLength(200);
$match_box->AddControl(new FormPart('Tournament name', $title));
# Open or invite?
require_once 'xhtml/forms/radio-button.class.php';
$qualify_set = new XhtmlElement('fieldset');
$qualify_set->SetCssClass('formPart radioButtonList');
$qualify_set->AddControl(new XhtmlElement('legend', 'Who can play?', 'formLabel'));
$qualify_radios = new XhtmlElement('div', null, 'formControl');
$qualify_set->AddControl($qualify_radios);
$qualify_radios->AddControl(new RadioButton($this->GetNamingPrefix() . 'Open', $this->GetNamingPrefix() . 'Qualify', 'any team may enter', MatchQualification::OPEN_TOURNAMENT, $match->GetQualificationType() === MatchQualification::OPEN_TOURNAMENT or !$match->GetId(), $this->IsValidSubmit()));
$qualify_radios->AddControl(new RadioButton($this->GetNamingPrefix() . 'Qualify', $this->GetNamingPrefix() . 'Qualify', 'only invited or qualifying teams can enter', MatchQualification::CLOSED_TOURNAMENT, $match->GetQualificationType() === MatchQualification::CLOSED_TOURNAMENT, $this->IsValidSubmit()));
$match_box->AddControl($qualify_set);
# Player type
$suggested_type = 2;
if (isset($this->context_season)) {
$suggested_type = $this->context_season->GetCompetition()->GetPlayerType();
} elseif (isset($this->context_team)) {
$suggested_type = $this->context_team->GetPlayerType();
}
if (!is_null($match->GetPlayerType())) {
$suggested_type = $match->GetPlayerType();
}
# Saved value overrides suggestion
$player_set = new XhtmlElement('fieldset');
$player_set->SetCssClass('formPart radioButtonList');
$player_set->AddControl(new XhtmlElement('legend', 'Type of teams', 'formLabel'));
$player_radios = new XhtmlElement('div', null, 'formControl');
$player_set->AddControl($player_radios);
$player_radios_1 = new XhtmlElement('div', null, 'column');
$player_radios_2 = new XhtmlElement('div', null, 'column');
$player_radios->AddControl($player_radios_1);
$player_radios->AddControl($player_radios_2);
$player_radios_1->AddControl(new RadioButton($this->GetNamingPrefix() . 'Ladies', $this->GetNamingPrefix() . 'PlayerType', 'Ladies', 2, $suggested_type === 2, $this->IsValidSubmit()));
$player_radios_1->AddControl(new RadioButton($this->GetNamingPrefix() . 'Mixed', $this->GetNamingPrefix() . 'PlayerType', 'Mixed', 1, $suggested_type === 1, $this->IsValidSubmit()));
$player_radios_2->AddControl(new RadioButton($this->GetNamingPrefix() . 'Girls', $this->GetNamingPrefix() . 'PlayerType', 'Junior girls', 5, $suggested_type === 5, $this->IsValidSubmit()));
$player_radios_2->AddControl(new RadioButton($this->GetNamingPrefix() . 'Children', $this->GetNamingPrefix() . 'PlayerType', 'Junior mixed', 4, $suggested_type === 6, $this->IsValidSubmit()));
$match_box->AddControl($player_set);
# How many?
$per_side_box = new XhtmlSelect($this->GetNamingPrefix() . "Players", null, $this->IsValid());
$per_side_box->SetBlankFirst(true);
for ($i = 6; $i <= 16; $i++) {
$per_side_box->AddControl(new XhtmlOption($i));
}
if ($match->GetIsMaximumPlayersPerTeamKnown()) {
$per_side_box->SelectOption($match->GetMaximumPlayersPerTeam());
} else {
if (!$match->GetId()) {
# Use eight as sensible default for new tournaments
//.........这里部分代码省略.........
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:101,代码来源:tournament-edit-control.class.php
示例9: GetTeamId
/**
* Gets the unique id of the team
*
* @return int
*/
public function GetTeamId()
{
return $this->team instanceof Team ? $this->team->GetId() : null;
}
示例10: EnsureTeamArray
/**
* Ensures that an entry exists for the given team in the internal opponents
* array
*
* @param string $season_key
* @param Team $team
*/
private function EnsureTeamArray($season_key, Team $team)
{
if (!array_key_exists($season_key, $this->opponents)) {
$this->opponents[$season_key] = array();
}
if (!array_key_exists($team->GetId(), $this->opponents[$season_key])) {
$this->opponents[$season_key][$team->GetId()] = array();
$this->opponents[$season_key][$team->GetId()]['team'] = $team;
$this->opponents[$season_key][$team->GetId()]['matches'] = 0;
$this->opponents[$season_key][$team->GetId()]['wins'] = 0;
$this->opponents[$season_key][$team->GetId()]['losses'] = 0;
$this->opponents[$season_key][$team->GetId()]['equal'] = 0;
$this->opponents[$season_key][$team->GetId()]['cancelled'] = 0;
}
}
示例11: OnLoadPageData
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);
}
示例12: CreateControls
protected function CreateControls()
{
$o_match = $this->GetDataObject();
if (is_null($o_match)) {
$o_match = new Match($this->GetSettings());
}
/* @var $o_match Match */
/* @var $o_team Team */
$b_got_home = !is_null($o_match->GetHomeTeam());
$b_got_away = !is_null($o_match->GetAwayTeam());
$b_is_new_match = !(bool) $o_match->GetId();
$b_is_tournament_match = false;
if ($this->i_match_type == MatchType::TOURNAMENT_MATCH) {
$b_is_tournament_match = $this->tournament instanceof Match;
} else {
if ($o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH and $o_match->GetTournament() instanceof Match) {
$this->SetTournament($o_match->GetTournament());
$this->SetMatchType($o_match->GetMatchType());
$b_is_tournament_match = true;
}
}
$o_match_outer_1 = new XhtmlElement('div');
$o_match_outer_1->SetCssClass('MatchFixtureEdit');
$o_match_outer_1->AddCssClass($this->GetCssClass());
$this->SetCssClass('');
$o_match_outer_1->SetXhtmlId($this->GetNamingPrefix());
$o_match_outer_2 = new XhtmlElement('div');
$o_match_box = new XhtmlElement('div');
$this->AddControl($o_match_outer_1);
$o_match_outer_1->AddControl($o_match_outer_2);
$o_match_outer_2->AddControl($o_match_box);
if ($this->GetShowHeading()) {
$s_heading = str_replace('{0}', MatchType::Text($this->i_match_type), $this->GetHeading());
# Add match type if required
$o_title_inner_1 = new XhtmlElement('span', htmlentities($s_heading, ENT_QUOTES, "UTF-8", false));
$o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
$o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
$o_match_box->AddControl(new XhtmlElement('h2', $o_title_inner_3, "medium large"));
}
# Offer choice of season if appropriate
$season_count = $this->seasons->GetCount();
if ($season_count == 1 and $this->i_match_type != MatchType::PRACTICE) {
$o_season_id = new TextBox($this->GetNamingPrefix() . 'Season', $this->seasons->GetFirst()->GetId());
$o_season_id->SetMode(TextBoxMode::Hidden());
$o_match_box->AddControl($o_season_id);
} elseif ($season_count > 1 and $this->i_match_type != MatchType::PRACTICE) {
$o_season_id = new XhtmlSelect($this->GetNamingPrefix() . 'Season', '', $this->IsValidSubmit());
foreach ($this->Seasons()->GetItems() as $season) {
$o_season_id->AddControl(new XhtmlOption($season->GetCompetitionName(), $season->GetId()));
}
$o_match_box->AddControl(new FormPart('Competition', $o_season_id));
}
# Start date and time
$match_time_known = (bool) $o_match->GetStartTime();
if (!$match_time_known) {
# if no date set, use specified default
if ($this->i_default_time) {
$o_match->SetStartTime($this->i_default_time);
if ($b_is_tournament_match) {
$o_match->SetIsStartTimeKnown(false);
}
} else {
# if no date set and no default, default to today at 6.30pm BST
$i_now = gmdate('U');
$o_match->SetStartTime(gmmktime(17, 30, 00, (int) gmdate('n', $i_now), (int) gmdate('d', $i_now), (int) gmdate('Y', $i_now)));
}
}
$o_date = new DateControl($this->GetNamingPrefix() . 'Start', $o_match->GetStartTime(), $o_match->GetIsStartTimeKnown(), $this->IsValidSubmit());
$o_date->SetShowTime(true);
$o_date->SetRequireTime(false);
$o_date->SetMinuteInterval(5);
# if no date set and only one season to choose from, limit available dates to the length of that season
if (!$match_time_known and $season_count == 1) {
if ($this->Seasons()->GetFirst()->GetStartYear() == $this->Seasons()->GetFirst()->GetEndYear()) {
$i_mid_season = gmmktime(0, 0, 0, 6, 30, $this->Seasons()->GetFirst()->GetStartYear());
} else {
$i_mid_season = gmmktime(0, 0, 0, 12, 31, $this->Seasons()->GetFirst()->GetStartYear());
}
$season_dates = Season::SeasonDates($i_mid_season);
$season_start_month = gmdate('n', $season_dates[0]);
$season_end_month = gmdate('n', $season_dates[1]);
if ($season_start_month) {
$o_date->SetMonthStart($season_start_month);
}
if ($season_end_month) {
$o_date->SetMonthEnd($season_end_month + 1);
}
// TODO: need a better way to handle this, allowing overlap. Shirley has indoor matches until early April.
$season_start_year = $this->Seasons()->GetFirst()->GetStartYear();
$season_end_year = $this->Seasons()->GetFirst()->GetEndYear();
if ($season_start_year) {
$o_date->SetYearStart($season_start_year);
}
if ($season_end_year) {
$o_date->SetYearEnd($season_end_year);
}
}
if ($b_is_tournament_match) {
$o_date->SetShowDate(false);
$o_date->SetShowTime(false);
//.........这里部分代码省略.........
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:101,代码来源:match-fixture-edit-control.class.php
示例13: SaveTeam
/**
* @return int
* @param Team $team
* @desc Save the supplied Team to the database, and return the id
*/
public function SaveTeam(Team $team)
{
# First job is to check permissions. There are several scenarios:
# - adding regular teams requires the highest privileges
# - adding once-only teams requires low privileges
# - editing teams has less access for a team owner than for a site admin
#
# Important to check the previous team type from the database before trusting
# the one submitted, as changing the team type changes editing privileges
$user = AuthenticationManager::GetUser();
$is_admin = $user->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS);
$is_team_owner = $user->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $team->GetLinkedDataUri());
$adding = !(bool) $team->GetId();
$old_team = null;
if (!$adding) {
$this->ReadById(array($team->GetId()));
$old_team = $this->GetFirst();
$team->SetTeamType($this->GetPermittedTeamType($old_team->GetTeamType(), $team->GetTeamType()));
}
$is_once_only = $team->GetTeamType() == Team::ONCE;
# To add a regular team we need global manage teams permission
if ($adding and !$is_once_only and !$is_admin) {
throw new Exception("Unauthorised");
}
# To edit a team we need global manage teams permission, or team owner permission
if (!$adding and !$is_admin and !$is_team_owner) {
throw new Exception("Unauthorised");
}
# Only an admin can change the short URL after the team is created
if ($adding or $is_admin) {
# Set up short URL manager
# Before changing the short URL, important that $old_team has a note of the current resource URI
require_once 'http/short-url-manager.class.php';
$o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection());
$new_short_url = $o_url_manager->EnsureShortUrl($team);
}
# build query
$i_club_id = !is_null($team->GetClub()) ? $team->GetClub()->GetId() : null;
$allowed_html = array('p', 'br', 'strong', 'em', 'a[href]', 'ul', 'ol', 'li');
$school_years = $team->GetSchoolYears();
$school_years_sql = "year1 = " . Sql::ProtectBool(array_key_exists(1, $school_years) and $school_years[1], false, false) . ", \r\n year2 = " . Sql::ProtectBool(array_key_exists(2, $school_years) and $school_years[2], false, false) . ", \r\n year3 = " . Sql::ProtectBool(array_key_exists(3, $school_years) and $school_years[3], false, false) . ", \r\n year4 = " . Sql::ProtectBool(array_key_exists(4, $school_years) and $school_years[4], false, false) . ", \r\n year5 = " . Sql::ProtectBool(array_key_exists(5, $school_years) and $school_years[5], false, false) . ", \r\n year6 = " . Sql::ProtectBool(array_key_exists(6, $school_years) and $school_years[6], false, false) . ", \r\n year7 = " . Sql::ProtectBool(array_key_exists(7, $school_years) and $school_years[7], false, false) . ", \r\n year8 = " . Sql::ProtectBool(array_key_exists(8, $school_years) and $school_years[8], false, false) . ", \r\n year9 = " . Sql::ProtectBool(array_key_exists(9, $school_years) and $school_years[9], false, false) . ", \r\n year10 = " . Sql::ProtectBool(array_key_exists(10, $school_years) and $school_years[10], false, false) . ", \r\n year11 = " . Sql::ProtectBool(array_key_exists(11, $school_years) and $school_years[11], false, false) . ", \r\n year12 = " . Sql::ProtectBool(array_key_exists(12, $school_years) and $school_years[12], false, false) . ", ";
# if no id, it's a new Team; otherwise update the Team
if ($adding) {
$sql = 'INSERT INTO nsa_team SET ' . "team_name = " . $this->SqlString($team->GetName()) . ", \r\n comparable_name = " . Sql::ProtectString($this->GetDataConnection(), $team->GetComparableName(), false) . ",\r\n club_id = " . Sql::ProtectNumeric($i_club_id, true) . ", \r\n website = " . $this->SqlString($team->GetWebsiteUrl()) . ", " . 'ground_id = ' . Sql::ProtectNumeric($team->GetGround()->GetId(), true) . ', ' . 'active = ' . Sql::ProtectBool($team->GetIsActive()) . ", \r\n team_type = " . Sql::ProtectNumeric($team->GetTeamType()) . ", \r\n {$school_years_sql}\r\n player_type_id = " . Sql::ProtectNumeric($team->GetPlayerType()) . ",\r\n intro = " . $this->SqlHtmlString($team->GetIntro(), $allowed_html) . ",\r\n playing_times = " . $this->SqlHtmlString($team->GetPlayingTimes(), $allowed_html) . ", \r\n cost = " . $this->SqlHtmlString($team->GetCost(), $allowed_html) . ", " . "contact = " . $this->SqlHtmlString($team->GetContact(), $allowed_html) . ", " . "contact_nsa = " . $this->SqlHtmlString($team->GetPrivateContact(), $allowed_html) . ", " . "short_url = " . $this->SqlString($team->GetShortUrl()) . ", \r\n update_search = " . ($is_once_only ? "0" : "1") . ", \r\n date_added = " . gmdate('U') . ', ' . 'date_changed = ' . gmdate('U') . ", " . "modified_by_id = " . Sql::ProtectNumeric($user->GetId());
# run query
$this->LoggedQuery($sql);
# get autonumber
$team->SetId($this->GetDataConnection()->insertID());
# Create default extras players
require_once "player-manager.class.php";
$player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection());
$player_manager->CreateExtrasPlayersForTeam($team->GetId());
unset($player_manager);
# Create owner role
require_once "authentication/authentication-manager.class.php";
require_once "authentication/role.class.php";
$authentication_manager = new AuthenticationManager($this->GetSettings(), $this->GetDataConnection(), null);
$role = new Role();
$role->setRoleName("Team owner: " . $team->GetName());
$role->Permissions()->AddPermission(PermissionType::MANAGE_TEAMS, $team->GetLinkedDataUri());
$authentication_manager->SaveRole($role);
$sql = "UPDATE nsa_team SET owner_role_id = " . Sql::ProtectNumeric($role->getRoleId(), false, false) . ' WHERE team_id = ' . Sql::ProtectNumeric($team->GetId());
$this->LoggedQuery($sql);
# If creating a once-only team, make the current user an owner
if ($is_once_only and !$is_admin) {
$authentication_manager->AddUserToRole($user->GetId(), $role->getRoleId());
$authentication_manager->LoadUserPermissions();
}
unset($authentication_manager);
} else {
# Now update the team, depending on permissions
$sql = 'UPDATE nsa_team SET ' . "website = " . $this->SqlString($team->GetWebsiteUrl()) . ", " . "intro = " . $this->SqlHtmlString($team->GetIntro(), $allowed_html) . ", " . "cost = " . $this->SqlHtmlString($team->GetCost(), $allowed_html) . ", " . "contact = " . $this->SqlHtmlString($team->GetContact(), $allowed_html) . ", " . "contact_nsa = " . $this->SqlHtmlString($team->GetPrivateContact(), $allowed_html) . ", \r\n update_search = " . ($is_once_only ? "0" : "1") . ", \r\n date_changed = " . gmdate('U') . ", \r\n modified_by_id = " . Sql::ProtectNumeric($user->GetId()) . ' ';
if (!$is_once_only) {
$sql .= ", \r\n active = " . Sql::ProtectBool($team->GetIsActive()) . ", \r\n team_type = " . Sql::ProtectNumeric($team->GetTeamType()) . ",\r\n {$school_years_sql}\r\n ground_id = " . Sql::ProtectNumeric($team->GetGround()->GetId(), true) . ", \r\n playing_times = " . $this->SqlHtmlString($team->GetPlayingTimes(), $allowed_html);
}
if ($is_admin or $is_once_only) {
$sql .= ",\r\n team_name = " . $this->SqlString($team->GetName());
}
if ($is_admin) {
$sql .= ",\r\n club_id = " . Sql::ProtectNumeric($i_club_id, true) . ", \r\n player_type_id = " . Sql::ProtectNumeric($team->GetPlayerType()) . ", \r\n comparable_name = " . Sql::ProtectString($this->GetDataConnection(), $team->GetComparableName(), false) . ",\r\n short_url = " . $this->SqlString($team->GetShortUrl()) . " ";
}
$sql .= "WHERE team_id = " . Sql::ProtectNumeric($team->GetId());
$this->LoggedQuery($sql);
# In case team name changed, update stats table
if ($is_admin or $is_once_only) {
$sql = "UPDATE nsa_player_match SET team_name = " . $this->SqlString($team->GetName()) . " WHERE team_id = " . Sql::ProtectNumeric($team->GetId());
$this->LoggedQuery($sql);
$sql = "UPDATE nsa_player_match SET opposition_name = " . $this->SqlString($team->GetName()) . " WHERE opposition_id = " . Sql::ProtectNumeric($team->GetId());
$this->LoggedQuery($sql);
}
}
if ($adding or $is_admin) {
# Regenerate short URLs
if (is_object($new_short_url)) {
$new_short_url->SetParameterValuesFromObject($team);
//.........这里部分代码省略.........
示例14: OnLoadPageData
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);
}
示例15: CreateScorecardControls
/**
* Sets up controls for pages 2/3 of the wizard
* @param Match $match
* @param Team $batting_team
* @param Collection $batting_data
* @param Team $bowling_team
* @param Collection $bowling_data
* @param int $total
* @param int $wickets_taken
* @return void
*/
private function CreateScorecardControls(Match $match, Team $batting_team, Collection $batting_data, Team $bowling_team, Collection $bowling_data, $total, $wickets_taken)
{
require_once "xhtml/tables/xhtml-table.class.php";
$batting_table = new XhtmlTable();
$batting_table->SetCaption($batting_team->GetName() . "'s batting");
$batting_table->SetCssClass("scorecard scorecardEditor batting");
$out_by_header = new XhtmlCell(true, '<span class="small">Fielder</span><span class="large">Caught<span class="wrapping-hair-space"> </span>/<span class="wrapping-hair-space"> </span><span class="nowrap">run-out by</span></span>');
$out_by_header->SetCssClass("dismissedBy");
$bowler_header = new XhtmlCell(true, "Bowler");
$bowler_header->SetCssClass("bowler");
$score_header = new XhtmlCell(true, "Runs");
$score_header->SetCssClass("numeric");
$balls_header = new XhtmlCell(true, "Balls");
$balls_header->SetCssClass("numeric");
$batting_headings = new XhtmlRow(array("Batsman", "How out", $out_by_header, $bowler_header, $score_header, $balls_header));
$batting_headings->SetIsHeader(true);
$batting_table->AddRow($batting_headings);
$batting_data->ResetCounter();
$byes = null;
$wides = null;
$no_balls = null;
$bonus = null;
# Loop = max players + 4, because if you have a full scorecard you have to keep looping to get the 4 extras players
for ($i = 1; $i <= $match->GetMaximumPlayersPerTeam() + 4; $i++) {
$batting = $batting_data->MoveNext() ? $batting_data->GetItem() : null;
/* @var $batting Batting */
# Grab the scores for extras players to use later
if (!is_null($batting)) {
switch ($batting->GetPlayer()->GetPlayerRole()) {
case Player::BYES:
$byes = $batting->GetRuns();
break;
case Player::WIDES:
$wides = $batting->GetRuns();
break;
case Player::NO_BALLS:
$no_balls = $batting->GetRuns();
break;
case Player::BONUS_RUNS:
$bonus = $batting->GetRuns();
break;
}
}
# Don't write a table row for the last four loops, we'll do that next because they're different
if ($i <= $match->GetMaximumPlayersPerTeam()) {
$player = new TextBox("batName{$i}", (is_null($batting) or !$batting->GetPlayer()->GetPlayerRole() == Player::PLAYER) ? "" : $batting->GetPlayer()->GetName(), $this->IsValidSubmit());
$player->SetMaxLength(100);
$player->AddAttribute("autocomplete", "off");
$player->AddCssClass("player batsman team" . $batting_team->GetId());
$how = new XhtmlSelect("batHowOut{$i}", null, $this->IsValidSubmit());
$how->SetCssClass("howOut");
$how->AddOptions(array(Batting::DID_NOT_BAT => Batting::Text(Batting::DID_NOT_BAT), Batting::NOT_OUT => Batting::Text(Batting::NOT_OUT), Batting::CAUGHT => Batting::Text(Batting::CAUGHT), Batting::BOWLED => Batting::Text(Batting::BOWLED), Batting::CAUGHT_AND_BOWLED => str_replace(" and ", "/", Batting::Text(Batting::CAUGHT_AND_BOWLED)), Batting::RUN_OUT => Batting::Text(Batting::RUN_OUT), Batting::BODY_BEFORE_WICKET => "bbw", Batting::HIT_BALL_TWICE => Batting::Text(Batting::HIT_BALL_TWICE), Batting::TIMED_OUT => Batting::Text(Batting::TIMED_OUT), Batting::RETIRED_HURT => Batting::Text(Batting::RETIRED_HURT), Batting::RETIRED => Batting::Text(Batting::RETIRED), Batting::UNKNOWN_DISMISSAL => Batting::Text(Batting::UNKNOWN_DISMISSAL)), null);
if (!is_null($batting) and $batting->GetPlayer()->GetPlayerRole() == Player::PLAYER and $this->IsValidSubmit()) {
$how->SelectOption($batting->GetHowOut());
}
$out_by = new TextBox("batOutBy{$i}", (is_null($batting) or is_null($batting->GetDismissedBy()) or !$batting->GetDismissedBy()->GetPlayerRole() == Player::PLAYER) ? "" : $batting->GetDismissedBy()->GetName(), $this->IsValidSubmit());
$out_by->SetMaxLength(100);
$out_by->AddAttribute("autocomplete", "off");
$out_by->AddCssClass("player team" . $bowling_team->GetId());
$bowled_by = new TextBox("batBowledBy{$i}", (is_null($batting) or is_null($batting->GetBowler()) or !$batting->GetBowler()->GetPlayerRole() == Player::PLAYER) ? "" : $batting->GetBowler()->GetName(), $this->IsValidSubmit());
$bowled_by->SetMaxLength(100);
$bowled_by->AddAttribute("autocomplete", "off");
$bowled_by->AddCssClass("player team" . $bowling_team->GetId());
$runs = new TextBox("batRuns{$i}", (is_null($batting) or $batting->GetPlayer()->GetPlayerRole() != Player::PLAYER) ? "" : $batting->GetRuns(), $this->IsValidSubmit());
$runs->SetCssClass("numeric runs");
$runs->AddAttribute("type", "number");
$runs->AddAttribute("min", "0");
$runs->AddAttribute("autocomplete", "off");
$balls = new TextBox("batBalls{$i}", (is_null($batting) or $batting->GetPlayer()->GetPlayerRole() != Player::PLAYER) ? "" : $batting->GetBallsFaced(), $this->IsValidSubmit());
$balls->SetCssClass("numeric balls");
$balls->AddAttribute("type", "number");
$balls->AddAttribute("min", "0");
$balls->AddAttribute("autocomplete", "off");
$batting_row = new XhtmlRow(array($player, $how, $out_by, $bowled_by, $runs, $balls));
$batting_row->GetFirstCell()->SetCssClass("batsman");
$batting_table->AddRow($batting_row);
}
}
$batting_table->AddRow($this->CreateExtrasRow("batByes", "Byes", "extras", "numeric runs", $byes));
$batting_table->AddRow($this->CreateExtrasRow("batWides", "Wides", "extras", "numeric runs", $wides));
$batting_table->AddRow($this->CreateExtrasRow("batNoBalls", "No balls", "extras", "numeric runs", $no_balls));
$batting_table->AddRow($this->CreateExtrasRow("batBonus", "Bonus or penalty runs", "extras", "numeric runs", $bonus));
$batting_table->AddRow($this->CreateExtrasRow("batTotal", "Total", "totals", "numeric", $total));
$batting_table->AddRow($this->CreateWicketsRow($match, $wickets_taken));
$this->AddControl($batting_table);
$total_batsmen = new TextBox("batRows", $match->GetMaximumPlayersPerTeam(), $this->IsValidSubmit());
$total_batsmen->SetMode(TextBoxMode::Hidden());
$this->AddControl($total_batsmen);
$bowling_table = new XhtmlTable();
//.........这里部分代码省略.........
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:101,代码来源:scorecard-edit-control.class.php