function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Match id", "Title", "Start time", "Latitude", "Longitude", "Website", "Description");
     require_once 'stoolball/match-manager.class.php';
     require_once "search/match-search-adapter.class.php";
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager->FilterByDateStart(gmdate("U"));
     $match_manager->ReadByMatchId();
     while ($match_manager->MoveNext()) {
         $match = $match_manager->GetItem();
         $adapter = new MatchSearchAdapter($match);
         /* @var $match Match */
         # Add this match to the data array
         $data[] = array($match->GetId(), $match->GetTitle(), $match->GetStartTime(), $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLatitude() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLongitude() : "", "https://" . $this->GetSettings()->GetDomain() . $match->GetNavigateUrl(), $adapter->GetSearchDescription());
     }
     unset($match_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
 private function AddActivitiesToFeed(SimpleXMLElement $feed, array $matches, array $teams_indexed_by_id, $valid_api_key)
 {
     require_once "search/match-search-adapter.class.php";
     $dont_just_turn_up = "\n\nIf you'd like to play, contact one of the clubs playing and ask how you can get involved. If you simply turn up on the day you'll be able to watch but " . "may not get to play.";
     $activities = $feed->addChild("activities");
     foreach ($matches as $match) {
         $activity = $activities->addChild("activity");
         /* @var $match Match */
         /* @var $activity SimpleXMLElement */
         $activity->addAttribute("external_id", $match->GetLinkedDataUri());
         $activity->addAttribute("external_partner_id", $this->GetSettings()->GetOrganisationLinkedDataUri());
         if ($match->GetGroundId()) {
             $activity->addAttribute("external_location_id", $match->GetGround()->GetLinkedDataUri());
         }
         $activity->addChild("title", Html::Encode($match->GetTitle()));
         $adapter = new MatchSearchAdapter($match);
         $description = $adapter->GetSearchDescription();
         $description = "Stoolball " . strtolower(substr($description, 0, 1)) . substr($description, 1);
         $cancelled = in_array($match->Result()->GetResultType(), array(MatchResult::ABANDONED, MatchResult::CANCELLED, MatchResult::POSTPONED, MatchResult::AWAY_WIN_BY_FORFEIT, MatchResult::HOME_WIN_BY_FORFEIT));
         if ($cancelled) {
             $description = "CANCELLED. " . $description;
         }
         $activity->addChild("short_description", $description);
         $activity->addChild("description", $description . $dont_just_turn_up);
         $activity->addChild("is_free", 0);
         $activity->addChild("requires_registration", 1);
         if ($match->GetMatchType() == MatchType::TOURNAMENT) {
             $activity->addChild("cost_information", "Most stoolball tournaments cost £1 per player for the whole day.");
         } else {
             $activity->addChild("cost_information", "Most teams charge a small annual and/or match fee.");
         }
         $activity->addChild("url", "https://" . $this->GetSettings()->GetDomain() . $match->GetNavigateUrl());
         $occurrences = $activity->addChild("occurrences");
         $times = $occurrences->addChild("times");
         $times->addChild("start_time", date('c', $match->GetStartTime()));
         if ($match->GetMatchType() == MatchType::TOURNAMENT) {
             $approx_duration_hours = 6;
         } else {
             $approx_duration_hours = 2;
         }
         $times->addChild("finish_time", date('c', $match->GetStartTime() + 60 * 60 * $approx_duration_hours));
         $times->addChild("cancelled", $cancelled ? "1" : "0");
         $category = $activity->addChild("category");
         $category->addAttribute("value", "8");
         $suitable = $activity->addChild("suitable_for");
         $suitable->addChild("any_age", 0);
         $suitable->addChild("s0-4", 0);
         $suitable->addChild("s5-6", 0);
         $suitable->addChild("s7-10", 0);
         $suitable->addChild("s11-13", 1);
         $suitable->addChild("s14-15", 1);
         $suitable->addChild("s16-17", 1);
         $suitable->addChild("s18", 1);
         $activity->addChild("family_friendly", 1);
         $activity->addChild("activity_type", "EVENT");
         if ($valid_api_key) {
             $contact = $activity->addChild("contact");
             if ($match->GetMatchType() == MatchType::TOURNAMENT) {
                 $contact->addChild("contact_email", $match->GetContactEmail());
                 $contact->addChild("contact_phone", $match->GetContactPhone());
             } else {
                 $home_team = $teams_indexed_by_id[$match->GetHomeTeamId()];
                 /* @var $home_team Team */
                 $contact->addChild("contact_email", $home_team->GetContactEmail());
                 $contact->addChild("contact_phone", $home_team->GetContactPhone());
             }
         }
         $photo = $activity->addChild("photo");
         $photo->addChild("photo_url", "https://www.stoolball.org.uk/images/bbc-getinspired-feed/photo" . substr($match->GetId(), strlen($match->GetId()) - 1) . ".jpg");
         $photo->addChild("photo_description", "Photo of a stoolball match in progress");
     }
 }
 private function IndexMatches()
 {
     require_once "data/process-manager.class.php";
     $this->process = new ProcessManager("matches", 200);
     if ($this->process->ReadyToDeleteAll()) {
         $this->SearchIndexer()->DeleteFromIndexByType("match");
     }
     $match = $this->GetSettings()->GetTable('Match');
     $match_batch = $this->GetDataConnection()->query("SELECT match_id FROM {$match} ORDER BY start_time, match_id" . $this->process->GetQueryLimit());
     $match_ids = array();
     while ($row = $match_batch->fetch()) {
         $match_ids[] = $row->match_id;
     }
     if (count($match_ids)) {
         require_once 'stoolball/match-manager.class.php';
         require_once 'search/match-search-adapter.class.php';
         $manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
         $manager->ReadByMatchId($match_ids);
         $results = $manager->GetItems();
         unset($manager);
         foreach ($results as $match) {
             $adapter = new MatchSearchAdapter($match);
             $this->SearchIndexer()->Index($adapter->GetSearchableItem());
             $this->process->OneMoreDone();
         }
         $this->SearchIndexer()->CommitChanges();
     }
 }
 function OnPrePageLoad()
 {
     $this->SetOpenGraphType("sport");
     $match_or_tournament = $this->match->GetMatchType() == MatchType::TOURNAMENT ? 'tournament' : 'match';
     $match_title = $this->match->GetTitle();
     if ($this->match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         $match_title .= " in the " . $this->match->GetTournament()->GetTitle();
     }
     $this->SetPageTitle($match_title . ' - ' . $this->match->GetStartTimeFormatted() . ' - stoolball ' . $match_or_tournament);
     $this->SetContentConstraint(StoolballPage::ConstrainColumns());
     require_once "search/match-search-adapter.class.php";
     $adapter = new MatchSearchAdapter($this->match);
     $this->SetPageDescription($adapter->GetSearchDescription());
     $this->LoadClientScript("match.js", true);
 }