/**
  * Helper to build basic info about a match from raw data
  *
  * @param Match $match
  * @param DataRow $row
  */
 private function BuildMatchSummary(Match $match, $row)
 {
     $match->SetId($row->match_id);
     if (isset($row->start_time)) {
         $match->SetStartTime($row->start_time);
     }
     if (isset($row->start_time_known)) {
         $match->SetIsStartTimeKnown($row->start_time_known);
     }
     if (isset($row->match_type)) {
         $match->SetMatchType($row->match_type);
     }
     if (isset($row->player_type_id)) {
         $match->SetPlayerType($row->player_type_id);
     }
     if (isset($row->qualification)) {
         $match->SetQualificationType($row->qualification);
     }
     if (isset($row->players_per_team)) {
         $match->SetMaximumPlayersPerTeam($row->players_per_team);
     }
     if (isset($row->max_tournament_teams)) {
         $match->SetMaximumTeamsInTournament($row->max_tournament_teams);
     }
     if (isset($row->tournament_spaces)) {
         $match->SetSpacesLeftInTournament($row->tournament_spaces);
     }
     if (isset($row->overs_per_innings)) {
         $match->SetOvers($row->overs_per_innings);
     }
     if (isset($row->match_title)) {
         $match->SetTitle($row->match_title);
     }
     if (isset($row->custom_title)) {
         $match->SetUseCustomTitle($row->custom_title);
     }
     if (isset($row->home_bat_first) and !is_null($row->home_bat_first)) {
         $match->Result()->SetHomeBattedFirst($row->home_bat_first);
     }
     if (isset($row->won_toss) and !is_null($row->won_toss)) {
         $match->Result()->SetTossWonBy($row->won_toss);
     }
     if (isset($row->home_runs)) {
         $match->Result()->SetHomeRuns($row->home_runs);
     }
     if (isset($row->home_wickets)) {
         $match->Result()->SetHomeWickets($row->home_wickets);
     }
     if (isset($row->away_runs)) {
         $match->Result()->SetAwayRuns($row->away_runs);
     }
     if (isset($row->away_wickets)) {
         $match->Result()->SetAwayWickets($row->away_wickets);
     }
     if (isset($row->home_points)) {
         $match->Result()->SetHomePoints($row->home_points);
     }
     if (isset($row->away_points)) {
         $match->Result()->SetAwayPoints($row->away_points);
     }
     if (isset($row->player_of_match_id)) {
         $player = new Player($this->GetSettings());
         $player->SetId($row->player_of_match_id);
         $player->SetName($row->player_of_match);
         $player->SetShortUrl($row->player_of_match_url);
         $player->Team()->SetId($row->player_of_match_team_id);
         $match->Result()->SetPlayerOfTheMatch($player);
     }
     if (isset($row->player_of_match_home_id)) {
         $player = new Player($this->GetSettings());
         $player->SetId($row->player_of_match_home_id);
         $player->SetName($row->player_of_match_home);
         $player->SetShortUrl($row->player_of_match_home_url);
         $player->Team()->SetId($row->player_of_match_home_team_id);
         $match->Result()->SetPlayerOfTheMatchHome($player);
     }
     if (isset($row->player_of_match_away_id)) {
         $player = new Player($this->GetSettings());
         $player->SetId($row->player_of_match_away_id);
         $player->SetName($row->player_of_match_away);
         $player->SetShortUrl($row->player_of_match_away_url);
         $player->Team()->SetId($row->player_of_match_away_team_id);
         $match->Result()->SetPlayerOfTheMatchAway($player);
     }
     if (isset($row->match_notes)) {
         $match->SetNotes($row->match_notes);
     }
     if (isset($row->short_url)) {
         $match->SetShortUrl($row->short_url);
     }
     if (isset($row->update_search) and $row->update_search == 1) {
         $match->SetSearchUpdateRequired();
     }
     if (isset($row->added_by) and is_numeric($row->added_by)) {
         $match->SetAddedBy(new User($row->added_by));
     }
     if (isset($row->match_result_id)) {
         $match->Result()->SetResultType($row->match_result_id);
     }
     if (isset($row->date_changed)) {
         $match->SetLastAudit(new AuditData($row->modified_by_id, $row->known_as, $row->date_changed));
     }
 }
 /**
  * Builds a match object containing the result information posted by the control
  *
  */
 public function BuildPostedDataObject()
 {
     $match = new Match($this->GetSettings());
     $match->SetMatchType(MatchType::TOURNAMENT);
     # Get match id
     $s_key = $this->GetNamingPrefix() . 'item';
     if (isset($_POST[$s_key])) {
         $s_id = $_POST[$s_key];
         if (strlen($s_id)) {
             $match->SetId($s_id);
         }
     }
     # Get the title
     $s_key = $this->GetNamingPrefix() . 'Title';
     if (isset($_POST[$s_key])) {
         $match->SetTitle(strip_tags($_POST[$s_key]));
     }
     # Get the qualification type
     $s_key = $this->GetNamingPrefix() . 'Qualify';
     if (isset($_POST[$s_key])) {
         $match->SetQualificationType($_POST[$s_key]);
     }
     # Get the player type
     $s_key = $this->GetNamingPrefix() . 'PlayerType';
     if (isset($_POST[$s_key])) {
         $match->SetPlayerType($_POST[$s_key]);
     }
     $s_key = $this->GetNamingPrefix() . "Players";
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key])) {
         $match->SetMaximumPlayersPerTeam($_POST[$s_key]);
     }
     # Get the number of overs
     $s_key = $this->GetNamingPrefix() . "Overs";
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key])) {
         $match->SetOvers($_POST[$s_key]);
     }
     # Get the short URL
     $s_key = $this->GetNamingPrefix() . 'ShortUrl';
     if (isset($_POST[$s_key])) {
         $match->SetShortUrl($_POST[$s_key]);
     }
     # Get the start date
     $s_key = $this->GetNamingPrefix() . 'Start';
     $match->SetStartTime(DateControl::GetPostedTimestampUtc($s_key));
     $match->SetIsStartTimeKnown(DateControl::GetIsTimePosted($s_key));
     # Get the initial team
     $team = new Team($this->GetSettings());
     $s_key = $this->GetNamingPrefix() . 'ContextTeam';
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key])) {
         $team->SetId($_POST[$s_key]);
         $match->AddAwayTeam($team);
     }
     # Get the ground
     $s_key = $this->GetNamingPrefix() . 'Ground';
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key])) {
         $o_ground = new Ground($this->GetSettings());
         $o_ground->SetId($_POST[$s_key]);
         $match->SetGround($o_ground);
     }
     # Get the notes
     $s_key = $this->GetNamingPrefix() . 'Notes';
     if (isset($_POST[$s_key])) {
         $match->SetNotes($_POST[$s_key]);
     }
     $this->SetDataObject($match);
 }
 /**
  * Builds a match object containing the result information posted by the control
  *
  */
 public function BuildPostedDataObject()
 {
     $o_match = new Match($this->GetSettings());
     # Get match id
     $s_key = $this->GetNamingPrefix() . 'item';
     if (isset($_POST[$s_key])) {
         $s_id = $_POST[$s_key];
         if (strlen($s_id)) {
             $o_match->SetId($s_id);
         }
     }
     # Get the short URL
     $s_key = $this->GetNamingPrefix() . 'ShortUrl';
     if (isset($_POST[$s_key])) {
         $o_match->SetShortUrl($_POST[$s_key]);
     }
     # Get the start date
     $s_key = $this->GetNamingPrefix() . 'Start';
     $o_match->SetStartTime(DateControl::GetPostedTimestampUtc($s_key));
     $o_match->SetIsStartTimeKnown(DateControl::GetIsTimePosted($s_key));
     # Get the home team
     # Test for (int)$_POST[$s_key] deliberately excludes "Not known" value, which is 0
     $o_home = new Team($this->GetSettings());
     $s_key = $this->GetNamingPrefix() . 'Home';
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key]) and (int) $_POST[$s_key]) {
         $o_home->SetId($_POST[$s_key]);
         $o_match->SetHomeTeam($o_home);
     }
     # Get the away team
     # Test for (int)$_POST[$s_key] deliberately excludes "Not known" value, which is 0
     $o_away = new Team($this->GetSettings());
     $s_key = $this->GetNamingPrefix() . 'Away';
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key]) and (int) $_POST[$s_key]) {
         $o_away->SetId($_POST[$s_key]);
         $o_match->SetAwayTeam($o_away);
     }
     # Get the ground
     $s_key = $this->GetNamingPrefix() . 'Ground';
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key])) {
         $o_ground = new Ground($this->GetSettings());
         $o_ground->SetId($_POST[$s_key]);
         $o_match->SetGround($o_ground);
     }
     # Get the notes
     $s_key = $this->GetNamingPrefix() . 'Notes';
     if (isset($_POST[$s_key])) {
         $o_match->SetNotes($_POST[$s_key]);
     }
     # Get the match type
     $s_key = $this->GetNamingPrefix() . 'MatchType';
     if (isset($_POST[$s_key]) and is_numeric($_POST[$s_key])) {
         $o_match->SetMatchType($_POST[$s_key]);
     }
     # Get the tournament
     if ($o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         $s_key = $this->GetNamingPrefix() . 'Tournament';
         if (isset($_POST[$s_key]) and is_numeric($_POST[$s_key])) {
             $tournament = new Match($this->GetSettings());
             $tournament->SetMatchType(MatchType::TOURNAMENT);
             $tournament->SetId($_POST[$s_key]);
             $o_match->SetTournament($tournament);
         }
     }
     # Get the season
     $s_key = $this->GetNamingPrefix() . 'Season';
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key])) {
         $o_season = new Season($this->GetSettings());
         $o_season->SetId($_POST[$s_key]);
         $o_match->Seasons()->Add($o_season);
     }
     $this->SetDataObject($o_match);
 }