public function OnPostback() { # If there's no id, ensure no match object is created. Page will then display a "match not found" message. # There's a separate page for adding matches, even for admins. if (!$this->editor->GetDataObjectId()) { return; } # Get the submitted match $this->match = $this->editor->GetDataObject(); # Because this is a new request, we need to reverify whether this is the match owner 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(); $this->b_user_is_match_owner = ($check_match instanceof Match and AuthenticationManager::GetUser()->GetId() == $check_match->GetAddedBy()->GetId()); # Don't wan't to edit tournaments on this page, so even as admin make sure we're not trying to save one. # Can't change the match type, so find out what that is from the db too. $this->b_is_tournament = $check_match->GetMatchType() == MatchType::TOURNAMENT; # Check whether cancel was clicked if ($this->editor->CancelClicked()) { # If so, get the match's short URL and redirect $this->match_manager->ExpandMatchUrl($this->match); $this->Redirect($this->match->GetNavigateUrl()); } # save data if valid if ($this->IsValid() and !$this->b_is_tournament) { # Save player of match $this->match_manager->SaveHighlights($this->match); $this->match_manager->ExpandMatchUrl($this->match); # Add comment if provided if (trim($this->match->GetNewComment())) { require_once 'forums/topic-manager.class.php'; require_once 'forums/review-item.class.php'; require_once 'forums/subscription-manager.class.php'; $topic_manager = new TopicManager($this->GetSettings(), $this->GetDataConnection()); $item_to_comment_on = new ReviewItem($this->GetSettings()); $item_to_comment_on->SetType(ContentType::STOOLBALL_MATCH); $item_to_comment_on->SetId($this->match->GetId()); $item_to_comment_on->SetNavigateUrl("https://" . $this->GetSettings()->GetDomain() . $this->match->GetNavigateUrl()); $message = $topic_manager->SaveComment($item_to_comment_on, $this->match->GetNewComment()); # send subscription emails $subs_manager = new SubscriptionManager($this->GetSettings(), $this->GetDataConnection()); $subs_manager->SendCommentsSubscriptions($item_to_comment_on, $message); unset($subs_manager); } # Match may have been updated so send an email $this->match_manager->NotifyMatchModerator($this->match->GetId()); # Show user the match, so they can see update was applied $this->Redirect($this->match->GetNavigateUrl()); } }