예제 #1
0
 /**
  * Build flight and place registration in it. Create flight if necessary.
  * @return flight_id updated or created
  */
 private function makeTeam($team_str)
 {
     $team_arr = explode('-', $team_str->id);
     // team-123
     $team = Team::findOne($team_arr[1]);
     if (!$team) {
         // need to create it
         $team = new Team();
         $team->name = $team_arr[1];
         $team->save();
         $team->refresh();
     }
     $name = '';
     foreach ($team_str->registrations as $registration_str) {
         $registration_arr = explode('-', $registration_str);
         // registration-456
         if ($registration = Registration::findOne($registration_arr[1])) {
             $registration->team_id = $team->id;
         }
         $registration->save();
         $name .= $registration->golfer->name . ' / ';
     }
     $name = rtrim($name, ' /');
     $team->name = substr($name, 0, 80);
     $team->handicap = $team_str->handicap;
     $team->save();
     return $team->id;
 }