예제 #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;
 }
예제 #2
0
 /**
  * Approve invitation
  */
 public function actionApprove($id)
 {
     $model = Registration::findOne($id);
     $model->status = Registration::STATUS_REGISTERED;
     $model->save();
     Yii::$app->session->setFlash('success', Yii::t('igolf', 'You registered to competition "{0}".', $model->competition->name));
     return $this->render('view', ['model' => $model, 'competition' => $model->competition]);
 }
예제 #3
0
 /**
  * Finds the Registration model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Registration the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Registration::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 /**
  * Deregister golfer from event
  * 
  * @var  Golfer $golfer Golfer to register
  * @return Deregistration status
  */
 public function deregister($golfer)
 {
     if ($model = Registration::findOne(['golfer_id' => $golfer->id, 'competition_id' => $this->id])) {
         return $model->cancel();
     }
     return false;
 }
예제 #5
0
 /**
  * Build flight and place registration in it. Create flight if necessary.
  * @return flight_id updated or created
  */
 private function makeFlight($flight_str, $competition)
 {
     $competition_date = substr($competition->start_date, 0, 10);
     $flight_arr = explode('-', $flight_str->id);
     // flight-123
     $flight = Flight::findOne($flight_arr[1]);
     if (!$flight) {
         // need to create it
         $flight = new Flight();
     } else {
         // remove existings
         $flight->cleanRegistrations();
     }
     $flight->position = $flight_str->position;
     Yii::trace($competition_date . ' ' . $flight_str->start_time . ':00', 'FlightController::makeFlight');
     $flight->start_time = $competition_date . ' ' . $flight_str->start_time . ':00';
     $flight->save();
     // add currents
     if ($competition->isTeamCompetition()) {
         foreach ($flight_str->registrations as $registration_str) {
             $registration_arr = explode('-', $registration_str);
             // registration-456
             $team = Team::findOne($registration_arr[1]);
             if ($team) {
                 foreach ($team->getRegistrations()->each() as $registration) {
                     $registration->flight_id = $flight->id;
                     $registration->save();
                 }
             }
         }
     } else {
         foreach ($flight_str->registrations as $registration_str) {
             $registration_arr = explode('-', $registration_str);
             // registration-456
             $registration = Registration::findOne($registration_arr[1]);
             if ($registration) {
                 $registration->flight_id = $flight->id;
                 $registration->save();
             }
         }
     }
     return $flight->id;
 }