function OnPostback() { $this->season = $this->edit->GetDataObject(); if (!$this->season->GetId()) { $existing_season_id = $this->season_manager->CheckIfSeasonExists($this->season->GetCompetition()->GetId(), $this->season->GetStartYear(), $this->season->GetEndYear()); if ($existing_season_id) { require_once 'data/validation/required-field-validator.class.php'; $season = new Season($this->GetSettings()); $season->SetId($existing_season_id); $validator = new RequiredFieldValidator('This_Validator_Will_Fail', "The season you're adding already exists – <a href=\"" . $season->GetNavigateUrl() . "\">edit season</a>"); $validator->SetValidIfNotFound(false); $this->edit->AddValidator($validator); } } # Get the competition. This is used to build the page title and, when saving, the short URL. # It is also re-indexed in search below. $this->competition_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $this->competition_manager->ReadById(array($this->season->GetCompetition()->GetId())); $this->season->SetCompetition($this->competition_manager->GetFirst()); unset($this->competition_manager); # save data if valid if ($this->IsValid()) { $b_saved_new = !(bool) $this->season->GetId(); $id = $this->season_manager->SaveSeason($this->season); $this->season->SetId($id); # Add the competition to the search engine. Re-request so we have team names as well as IDs. require_once "search/competition-search-adapter.class.php"; $this->SearchIndexer()->DeleteFromIndexById("competition" . $this->season->GetCompetition()->GetId()); $adapter = new CompetitionSearchAdapter($this->season->GetCompetition()); $this->SearchIndexer()->Index($adapter->GetSearchableItem()); $this->SearchIndexer()->CommitChanges(); # If just saved a new season, redirect to load this page from scratch # (When just loading data on this page, didn't load correctly into aggregated editors) if ($b_saved_new) { $this->Redirect($this->season->GetEditSeasonUrl()); } $this->Redirect($this->season->GetNavigateUrl()); } }