/** * Sets up controls for page 4 of the wizard * @param Match $match * @return void */ private function CreateHighlightsControls(Match $match) { $b_got_teams = !(is_null($match->GetHomeTeam()) || is_null($match->GetAwayTeam())); // Move CSS class to div element $match_outer_1 = new XhtmlElement('div'); $match_outer_1->SetCssClass('matchResultEdit panel'); $match_outer_2 = new XhtmlElement('div'); $match_box = new XhtmlElement('div'); $this->AddControl($match_outer_1); $match_outer_1->AddControl($match_outer_2); $match_outer_2->AddControl($match_box); $o_title_inner_1 = new XhtmlElement('span', "Match highlights"); $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1); $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2); $o_heading = new XhtmlElement('h2', $o_title_inner_3); $match_box->AddControl($o_heading); # Who's playing? $o_home_name = new TextBox($this->GetNamingPrefix() . 'Home'); $o_away_name = new TextBox($this->GetNamingPrefix() . 'Away'); $o_home_name->SetMode(TextBoxMode::Hidden()); $o_away_name->SetMode(TextBoxMode::Hidden()); if (!is_null($match->GetHomeTeam())) { $o_home_name->SetText($match->GetHomeTeam()->GetId() . MatchHighlightsEditControl::DATA_SEPARATOR . $match->GetHomeTeam()->GetName()); } if (!is_null($match->GetAwayTeam())) { $o_away_name->SetText($match->GetAwayTeam()->GetId() . MatchHighlightsEditControl::DATA_SEPARATOR . $match->GetAwayTeam()->GetName()); } $this->AddControl($o_home_name); $this->AddControl($o_away_name); # When? (for validator message only) $when = new TextBox($this->GetNamingPrefix() . 'Date', $match->GetStartTime()); $when->SetMode(TextBoxMode::Hidden()); $this->AddControl($when); # Who won? $o_winner = new XhtmlSelect($this->GetNamingPrefix() . 'Result'); $o_winner->AddControl(new XhtmlOption("Don't know", '')); $result_types = array(MatchResult::HOME_WIN, MatchResult::AWAY_WIN, MatchResult::TIE, MatchResult::ABANDONED); foreach ($result_types as $result_type) { if ($b_got_teams) { $o_winner->AddControl(new XhtmlOption($this->NameTeams(MatchResult::Text($result_type), $match->GetHomeTeam(), $match->GetAwayTeam()), $result_type)); } else { $o_winner->AddControl(new XhtmlOption(MatchResult::Text($result_type), $result_type)); } } if ($this->IsValidSubmit()) { if ($match->Result()->GetResultType() == MatchResult::UNKNOWN and !is_null($match->Result()->GetHomeRuns()) and !is_null($match->Result()->GetAwayRuns())) { # If match result is not known but we can guess from the entered scores, select it if ($match->Result()->GetHomeRuns() > $match->Result()->GetAwayRuns()) { $o_winner->SelectOption(MatchResult::HOME_WIN); } else { if ($match->Result()->GetHomeRuns() < $match->Result()->GetAwayRuns()) { $o_winner->SelectOption(MatchResult::AWAY_WIN); } else { if ($match->Result()->GetHomeRuns() == $match->Result()->GetAwayRuns()) { $o_winner->SelectOption(MatchResult::TIE); } } } } else { $o_winner->SelectOption($match->Result()->GetResultType()); } } $o_win_part = new FormPart('Who won?', $o_winner); $match_box->AddControl($o_win_part); # Get current player of match $player = $match->Result()->GetPlayerOfTheMatch(); $home_player = $match->Result()->GetPlayerOfTheMatchHome(); $away_player = $match->Result()->GetPlayerOfTheMatchAway(); $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE; if ($player instanceof Player) { $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL; } else { if ($home_player instanceof Player or $away_player instanceof Player) { $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY; } } # Choose from different types of player of the match require_once 'xhtml/forms/radio-button.class.php'; $pom_container = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Player of the match', 'formLabel')); $pom_container->SetCssClass('formPart'); $pom_options = new XhtmlElement('div', null, 'formControl radioButtonList'); $pom_options->SetXhtmlId($this->GetNamingPrefix() . "PlayerOptions"); $pom_container->AddControl($pom_options); $match_box->AddControl($pom_container); $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $this->GetNamingPrefix() . 'POM', "none chosen", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $this->IsValidSubmit())); $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $this->GetNamingPrefix() . 'POM', "yes, one chosen", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $this->IsValidSubmit())); $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $this->GetNamingPrefix() . 'POM', "yes, one from each team", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $this->IsValidSubmit())); # Controls for entering a single player of the match $player_name = new TextBox($this->GetNamingPrefix() . 'Player', $player instanceof Player ? $player->GetName() : '', $this->IsValidSubmit()); $player_name->SetMaxLength(100); $player_name->AddCssClass("player"); $player_name->AddCssClass("team" . $match->GetHomeTeamId()); $player_name->AddCssClass("team" . $match->GetAwayTeamId()); $player_name->AddAttribute("autocomplete", "off"); $player_box = new XhtmlElement("div", $player_name); $player_team = new XhtmlSelect($this->GetNamingPrefix() . "PlayerTeam", " playing for", $this->IsValidSubmit()); $player_team->SetCssClass("playerTeam"); # for JS $player_team->AddControl(new XhtmlOption("Don't know", "")); $player_team->AddControl(new XhtmlOption($match->GetHomeTeam()->GetName(), $match->GetHomeTeamId())); $player_team->AddControl(new XhtmlOption($match->GetAwayTeam()->GetName(), $match->GetAwayTeamId())); if ($player instanceof Player) { $player_team->SelectOption($player->Team()->GetId()); } $player_box->AddControl($player_team); $player_part = new FormPart("Player's name", $player_box); $player_part->SetXhtmlId($this->GetNamingPrefix() . "OnePlayer"); $player_part->GetLabel()->AddAttribute("for", $player_name->GetXhtmlId()); $match_box->AddControl($player_part); # Controls for entering home and away players of the match $home_box = new TextBox($this->GetNamingPrefix() . 'PlayerHome', $home_player instanceof Player ? $home_player->GetName() : '', $this->IsValidSubmit()); $home_box->SetMaxLength(100); $home_box->AddCssClass("player"); $home_box->AddCssClass("team" . $match->GetHomeTeamId()); $home_box->AddAttribute("autocomplete", "off"); $home_part = new FormPart($this->NameTeams('Home player', $match->GetHomeTeam(), $match->GetAwayTeam()), $home_box); $home_part->SetCssClass("formPart multiPlayer"); $match_box->AddControl($home_part); $away_box = new TextBox($this->GetNamingPrefix() . 'PlayerAway', $away_player instanceof Player ? $away_player->GetName() : '', $this->IsValidSubmit()); $away_box->SetMaxLength(100); $away_box->AddCssClass("player"); $away_box->AddCssClass("team" . $match->GetAwayTeamId()); $away_box->AddAttribute("autocomplete", "off"); $away_part = new FormPart($this->NameTeams('Away player', $match->GetHomeTeam(), $match->GetAwayTeam()), $away_box); $away_part->SetCssClass("formPart multiPlayer"); $match_box->AddControl($away_part); # Any comments? $comments = new TextBox($this->GetNamingPrefix() . 'Comments', '', $this->IsValidSubmit()); $comments->SetMode(TextBoxMode::MultiLine()); $comments->AddAttribute('class', 'matchReport'); $comments_label = new XhtmlElement('label'); $comments_label->AddAttribute('for', $comments->GetXhtmlId()); $comments_label->AddCssClass('matchReport'); $comments_label->AddControl('Add a match report:'); $match_box->AddControl($comments_label); $match_box->AddControl($comments); if ($match->GetLastAudit() != null) { require_once "data/audit-control.class.php"; $match_box->AddControl(new AuditControl($match->GetLastAudit(), "match")); } $this->SetButtonText('Save match'); }