/**
  * Re-build from data posted by this control a single data object which this control is editing
  *
  * @param int $i_counter
  * @param int $i_id
  */
 protected function BuildPostedItem($i_counter = null, $i_id = null)
 {
     $s_key = $this->GetNamingPrefix() . 'Team' . $i_counter;
     $team = new Team($this->GetSettings());
     if (isset($_POST[$s_key]) and is_numeric($_POST[$s_key])) {
         $team->SetId($_POST[$s_key]);
     }
     $s_key = $this->GetNamingPrefix() . 'TeamValue' . $i_counter;
     if (isset($_POST[$s_key])) {
         $team->SetName($_POST[$s_key]);
     }
     # Infer player type from name
     if (stristr($team->GetName(), "ladies")) {
         $team->SetPlayerType(PlayerType::LADIES);
     } else {
         if (stristr($team->GetName(), "mixed")) {
             $team->SetPlayerType(PlayerType::MIXED);
         } else {
             if (stristr($team->GetName(), "Junior mixed")) {
                 $team->SetPlayerType(PlayerType::JUNIOR_MIXED);
             } else {
                 if (stristr($team->GetName(), "junior") or stristr($team->GetName(), "girls")) {
                     $team->SetPlayerType(PlayerType::GIRLS);
                 }
             }
         }
     }
     if ($team->GetId() or $team->GetName()) {
         $this->DataObjects()->Add($team);
     } else {
         $this->IgnorePostedItem($i_counter);
     }
 }
 /**
  * (non-PHPdoc)
  * @see data/validation/DataValidator#Test($s_input, $a_keys)
  */
 public function Test($a_data, $a_keys)
 {
     /* Only way to be sure of testing name against what it will be matched against is to use the code that transforms it when saving */
     $team = new Team($this->GetSiteSettings());
     $team->SetName($a_data[$a_keys[1]]);
     $team->SetPlayerType($a_data[$a_keys[2]]);
     $team_manager = new TeamManager($this->GetSiteSettings(), $this->GetDataConnection());
     $team = $team_manager->MatchExistingTeam($team);
     unset($team_manager);
     $current_id = isset($a_data[$a_keys[0]]) ? $a_data[$a_keys[0]] : null;
     return !$team->GetId() or $team->GetId() == $current_id;
 }
 /**
  * @return void
  * @desc Re-build from data posted by this control the data object this control is editing
  */
 function BuildPostedDataObject()
 {
     $team = new Team($this->GetSettings());
     if (isset($_POST['item'])) {
         $team->SetId($_POST['item']);
     }
     if (isset($_POST['name'])) {
         $team->SetName($_POST['name']);
     }
     $team->SetWebsiteUrl($_POST['websiteUrl']);
     $team->SetIsActive(isset($_POST['playing']));
     $team->SetIntro(ucfirst(trim($_POST['intro'])));
     $team->SetPlayingTimes($_POST['times']);
     $team->SetCost($_POST['yearCost']);
     $team->SetContact($_POST['contact']);
     $team->SetPrivateContact($_POST['private']);
     $ground = new Ground($this->GetSettings());
     $ground->SetId($_POST['ground']);
     $team->SetGround($ground);
     if (isset($_POST['team_type'])) {
         $team->SetTeamType($_POST['team_type']);
         if ($team->GetTeamType() == Team::SCHOOL_YEARS) {
             $team->SetSchoolYears(array(1 => isset($_POST['year1']), 2 => isset($_POST['year2']), 3 => isset($_POST['year3']), 4 => isset($_POST['year4']), 5 => isset($_POST['year5']), 6 => isset($_POST['year6']), 7 => isset($_POST['year7']), 8 => isset($_POST['year8']), 9 => isset($_POST['year9']), 10 => isset($_POST['year10']), 11 => isset($_POST['year11']), 12 => isset($_POST['year12'])));
         }
     }
     if ($this->is_admin) {
         $team->SetShortUrl($_POST[$this->GetNamingPrefix() . 'ShortUrl']);
         $team->SetPlayerType($_POST['playerType']);
         if (isset($_POST['club']) and is_numeric($_POST['club'])) {
             $club = new Club($this->GetSettings());
             $club->SetId($_POST['club']);
             $team->SetClub($club);
         }
     }
     $this->SetDataObject($team);
 }
 /**
  * Populates the collection of business objects from raw data
  *
  * @return bool
  * @param MySqlRawData $o_result
  */
 protected function BuildItems(MySqlRawData $o_result)
 {
     # use CollectionBuilder to handle duplicates
     $o_ground_builder = new CollectionBuilder();
     $o_ground = null;
     while ($row = $o_result->fetch()) {
         # check whether this is a new ground
         if (!$o_ground_builder->IsDone($row->ground_id)) {
             # store any exisiting ground
             if ($o_ground != null) {
                 $this->Add($o_ground);
             }
             # create the new ground
             $o_ground = new Ground($this->o_settings);
             $o_ground->SetId($row->ground_id);
             $o_ground->SetDirections($row->directions);
             $o_ground->SetParking($row->parking);
             $o_ground->SetFacilities($row->facilities);
             $o_ground->SetShortUrl($row->short_url);
             $o_ground->SetDateUpdated($row->date_changed);
             if (isset($row->update_search) and $row->update_search == 1) {
                 $o_ground->SetSearchUpdateRequired();
             }
             $o_address = $o_ground->GetAddress();
             $o_address->SetSaon($row->saon);
             $o_address->SetPaon($row->paon);
             $o_address->SetStreetDescriptor($row->street_descriptor);
             $o_address->SetLocality($row->locality);
             $o_address->SetTown($row->town);
             $o_address->SetAdministrativeArea($row->administrative_area);
             $o_address->SetPostcode($row->postcode);
             if (isset($row->latitude)) {
                 $o_address->SetGeoLocation($row->latitude, $row->longitude, $row->geo_precision);
             }
             $o_ground->SetAddress($o_address);
         }
         if (isset($row->team_name)) {
             $team = new Team($this->GetSettings());
             $team->SetName($row->team_name);
             $team->SetShortUrl($row->team_short_url);
             $team->SetPlayerType($row->player_type_id);
             $o_ground->Teams()->Add($team);
         }
     }
     # store final ground
     if ($o_ground != null) {
         $this->Add($o_ground);
     }
 }
 /**
  * Finds an existing team or saves a new team and returns the id
  * @param Match $tournament
  * @param Team $team
  * @return int
  */
 public function SaveOrMatchTournamentTeam(Match $tournament, Team $team)
 {
     if (is_null($team->GetPlayerType())) {
         $team->SetPlayerType($tournament->GetPlayerType());
     }
     $team = $this->MatchExistingTeam($team);
     if (!$team->GetId()) {
         $team->SetShortUrlPrefix($tournament->GetShortUrl());
         $team = $this->MatchExistingTeam($team);
     }
     if (!$team->GetId()) {
         $team->SetTeamType(Team::ONCE);
         $team->SetGround($tournament->GetGround());
         $this->SaveTeam($team);
     }
     return $team->GetId();
 }