function OnPrePageLoad()
 {
     # set up page
     $this->SetOpenGraphType("sports_league");
     $this->SetPageTitle("League table for the " . $this->season->GetCompetitionName());
     require_once "search/competition-search-adapter.class.php";
     $adapter = new CompetitionSearchAdapter($this->competition);
     $this->SetPageDescription($adapter->GetSearchDescription());
     $this->SetContentConstraint(StoolballPage::ConstrainBox());
     $this->SetContentCssClass("season-table");
 }
 function OnPostback()
 {
     # Get the item info and store it
     $id = $this->manager->GetItemId($this->data_object);
     $this->manager->ReadById(array($id));
     $this->data_object = $this->manager->GetFirst();
     # Check whether cancel was clicked
     if (isset($_POST['cancel'])) {
         $this->Redirect($this->data_object->GetNavigateUrl());
     }
     # Check whether delete was clicked
     if (isset($_POST['delete'])) {
         # Only offer delete option if there's more than one season. Don't want to delete last season because
         # that leaves an empty competition which won't display. Instead, must delete whole competition with its one remaining season.
         # How many seasons in this competition?
         if (is_object($this->data_object) and $this->data_object->GetCompetition() instanceof Competition and $this->data_object->GetCompetition()->GetId()) {
             $this->manager->Clear();
             $this->manager->ReadByCompetitionId(array($this->data_object->GetCompetition()->GetId()));
             $this->seasons_in_competition = $this->manager->GetCount();
         }
         if ($this->seasons_in_competition > 1) {
             # Check again that the requester has permission to delete this item
             if ($this->has_permission) {
                 # Delete it
                 $this->manager->Delete(array($id));
                 # Update the competition in the search engine, because the latest season may have changed.
                 require_once 'stoolball/competition-manager.class.php';
                 require_once "search/competition-search-adapter.class.php";
                 $this->SearchIndexer()->DeleteFromIndexById("competition" . $this->data_object->GetCompetition()->GetId());
                 $competition_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
                 $competition_manager->ReadById(array($this->data_object->GetCompetition()->GetId()));
                 $competition = $competition_manager->GetFirst();
                 $adapter = new CompetitionSearchAdapter($competition);
                 $this->SearchIndexer()->Index($adapter->GetSearchableItem());
                 $this->SearchIndexer()->CommitChanges();
                 # Note success
                 $this->deleted = true;
             }
         }
     }
 }
 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 &#8211; <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());
     }
 }
 private function IndexCompetitions()
 {
     require_once 'stoolball/competition-manager.class.php';
     require_once 'search/competition-search-adapter.class.php';
     $this->SearchIndexer()->DeleteFromIndexByType("competition");
     $manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
     $manager->ReadAll();
     $results = $manager->GetItems();
     unset($manager);
     foreach ($results as $result) {
         $adapter = new CompetitionSearchAdapter($result);
         $this->SearchIndexer()->Index($adapter->GetSearchableItem());
     }
     $this->SearchIndexer()->CommitChanges();
 }
 function OnPrePageLoad()
 {
     $this->SetOpenGraphType("sports_league");
     $this->SetPageTitle($this->season->GetCompetitionName());
     require_once "search/competition-search-adapter.class.php";
     $adapter = new CompetitionSearchAdapter($this->competition);
     $this->SetPageDescription($adapter->GetSearchDescription());
     $this->SetContentConstraint(StoolballPage::ConstrainColumns());
 }