/** * Creates the controls when the editor is in its season view * */ private function CreateSeasonControls(Match $match, XhtmlElement $match_box) { /* @var $season Season */ $css_class = 'TournamentEdit checkBoxList'; 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); $heading = 'Select seasons'; if ($this->show_step_number) { $heading .= ' – step 3 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")); # Preserve match title, because we need it to send the email when the seasons are saved $title = new TextBox($this->GetNamingPrefix() . 'Title', $match->GetTitle(), $this->IsValidSubmit()); $title->SetMode(TextBoxMode::Hidden()); $match_box->AddControl($title); # If the list of seasons includes ones in which the only match type is tournament, then # they're annual tournaments like Expo and Seaford. Although those tournaments can be listed # in other seasons (they're of interest to the league teams), we don't want other tournaments # listed on pages which are supposed to be just about those annual tournaments. So exclude them # from the collection of possible seasons. Next bit of code will add them back in for any # tournaments which actually are meant to be in those seasons. $seasons = $this->seasons->GetItems(); $len = count($seasons); for ($i = 0; $i < $len; $i++) { # Make sure only seasons which contain tournaments are listed. Necessary to include all match types # in the Seasons() collection from the database so that we can test what other match types seasons support. if (!$seasons[$i]->MatchTypes()->Contains(MatchType::TOURNAMENT)) { unset($seasons[$i]); continue; } if ($seasons[$i]->MatchTypes()->GetCount() == 1 and $seasons[$i]->MatchTypes()->GetFirst() == MatchType::TOURNAMENT) { unset($seasons[$i]); } } $this->seasons->SetItems($seasons); # If the list of possible seasons doesn't include the one(s) the match is already in, # or the ones the context team plays in, add those to the list of possibles $a_season_ids = array(); foreach ($this->seasons as $season) { $a_season_ids[] = $season->GetId(); } foreach ($match->Seasons() as $season) { if (!in_array($season->GetId(), $a_season_ids, true)) { $this->seasons->Insert($season); $a_season_ids[] = $season->GetId(); } } if (isset($this->context_team)) { $match_year = Date::Year($match->GetStartTime()); foreach ($this->context_team->Seasons() as $team_in_season) { /* @var $team_in_season TeamInSeason */ if (!in_array($team_in_season->GetSeasonId(), $a_season_ids, true) and ($team_in_season->GetSeason()->GetStartYear() == $match_year or $team_in_season->GetSeason()->GetEndYear() == $match_year)) { $this->seasons->Insert($team_in_season->GetSeason()); $a_season_ids[] = $team_in_season->GetSeasonId(); } } } require_once 'xhtml/forms/checkbox.class.php'; $seasons_list = ''; if ($this->seasons->GetCount()) { # Sort the seasons by name, because they've been messed up by the code above $this->seasons->SortByProperty('GetCompetitionName'); $match_box->AddControl(new XhtmlElement('p', 'Tick all the places we should list your tournament:')); $match_box->AddControl('<div class="radioButtonList">'); foreach ($this->seasons as $season) { # Select season if it's one of the seasons the match is already in $b_season_selected = false; foreach ($match->Seasons() as $match_season) { $b_season_selected = ($b_season_selected or $match_season->GetId() == $season->GetId()); } /* @var $season Season */ $box = new CheckBox($this->GetNamingPrefix() . 'Season' . $season->GetId(), $season->GetCompetitionName(), $season->GetId(), $b_season_selected, $this->IsValidSubmit()); $seasons_list .= $season->GetId() . ';'; $match_box->AddControl($box); } $match_box->AddControl('</div>'); # Remember all the season ids to make it much easier to find the data on postback $seasons = new TextBox($this->GetNamingPrefix() . 'Seasons', $seasons_list, $this->IsValidSubmit()); $seasons->SetMode(TextBoxMode::Hidden()); $match_box->AddControl($seasons); } else { $match_month = 'in ' . Date::MonthAndYear($match->GetStartTime()); $type = strtolower(PlayerType::Text($match->GetPlayerType())); $match_box->AddControl(new XhtmlElement('p', "Unfortunately we don't have details of any {$type} competitions {$match_month} to list your tournament in.")); $match_box->AddControl(new XhtmlElement('p', 'Please click \'Save tournament\' to continue.')); } }
/** * @return void * @param Season[] $a_input * @desc Sets the seasons of this competition */ function SetItems($a_input) { /* @var $o_season Season */ /* @var $o_latest Season */ if (is_array($a_input)) { $o_latest =& $this->GetLatestSeason(); $b_latest = is_object($o_latest); $i_seasons = count($a_input); for ($i = 0; $i < $i_seasons; $i++) { $o_season = $a_input[$i]; if ($o_season instanceof Season) { $o_season->SetCompetition($this); # Latest season often has richer info, so don't throw it away if ($b_latest and $o_season->GetId() == $o_latest->GetId()) { $o_season->Merge($o_latest); } } } } parent::SetItems($a_input); }