function OnPostback() { # get object $this->tournament = $this->editor->GetDataObject(); if ($this->editor->GetDataObjectId()) { # Because this is a new request we need to reverify security details before letting anything happen. # Can't trust that info from a postback so MUST go to the database to check it. $this->match_manager->ReadByMatchId(array($this->editor->GetDataObjectId())); $check_match = $this->match_manager->GetFirst(); if ($check_match instanceof Match) { # This page is only for tournaments, so check that against the db $this->b_is_tournament = $check_match->GetMatchType() == MatchType::TOURNAMENT; /* The editor requires the teams in the tournament to populate the dropdown and to come up with a * match title, and it doesn't have them when recreating the tournament from the postback data. * Since we have $check_match available from the database anyway, get the teams from there. */ foreach ($check_match->GetAwayTeams() as $team) { $this->tournament->AddAwayTeam($team); } } } else { # Error for there being no match id on postback, $this->b_is_tournament = false; } # Check whether cancel was clicked if ($this->editor->CancelClicked()) { $this->match_manager->ExpandMatchUrl($this->tournament); $this->Redirect($this->tournament->GetNavigateUrl()); } # save data if valid if ($this->IsValid()) { # Confirm match is being saved as a tournament $this->b_is_tournament = $this->b_is_tournament and $this->tournament->GetMatchType() == MatchType::TOURNAMENT; # Check that the requester has permission to update this match if ($this->b_is_tournament) { # Save the matches in the tournament $this->match_manager->SaveMatchesInTournament($this->tournament); $this->match_manager->NotifyMatchModerator($this->tournament->GetId()); $this->match_manager->ExpandMatchUrl($this->tournament); http_response_code(303); $this->Redirect($this->tournament->GetNavigateUrl()); } } }