コード例 #1
0
ファイル: TeamController.php プロジェクト: kleitz/golfleague
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Creates a new Team model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Team();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #3
0
 /**
  * Creates a new Team model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($event_id = null)
 {
     $model = new Team();
     $model->event_id = $event_id;
     $events = Event::findAll(['active' => true]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'events' => $events]);
     }
 }
コード例 #4
0
 public function copyToEvent($event_id)
 {
     $old_event = $this->event;
     $new_event = Event::findOne($event_id);
     $time_diff = $new_event->start - $old_event->start - floor(($new_event->start - $old_event->start) / (60 * 60 * 24));
     $new_team = new Team();
     $new_team->attributes = $this->attributes;
     $new_team->name = "Copy of " . $this->name;
     $new_team->event_id = $event_id;
     $new_team->save();
     //Copy shifts
     $old_shifts = $this->shifts;
     foreach ($old_shifts as $old_shift) {
         $new_shift = new Shift();
         $new_shift->attributes = $old_shift->attributes;
         $new_shift->team_id = $new_team->id;
         $new_shift->start_time += $time_diff;
         $new_shift->save();
     }
     return $new_team->id;
 }
コード例 #5
0
 public function makeCopy($new_start)
 {
     $new_start += $this->start % (60 * 60 * 24);
     $new_end = $new_start + ($this->end - $this->start);
     $time_diff = $new_start - $this->start - floor(($new_start - $this->start) / (60 * 60 * 24));
     var_dump($time_diff);
     //Clone event
     $new_event = new Event();
     $new_event->attributes = $this->attributes;
     $new_event->formStart = date(self::DATE_FORMAT, $new_start);
     $new_event->formEnd = date(self::DATE_FORMAT, $new_end);
     $new_event->name = "Copy of " . $this->name;
     $new_event->save();
     //Clone teams
     $old_teams = $this->teams;
     foreach ($old_teams as $old_team) {
         $new_team = new Team();
         $new_team->attributes = $old_team->attributes;
         $new_team->event_id = $new_event->id;
         $new_team->save();
         //Clone shifts
         $old_shifts = $old_team->shifts;
         foreach ($old_shifts as $old_shift) {
             $new_shift = new Shift();
             $new_shift->attributes = $old_shift->attributes;
             $new_shift->team_id = $new_team->id;
             $new_shift->start_time += $time_diff;
             $new_shift->save();
         }
     }
     return $new_event->id;
 }