예제 #1
0
 /**
  * Finds the Competition model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Competition the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Golfer::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #2
0
 /**
  * @return  Golfer Currently logged in user as Golfer
  */
 public static function me()
 {
     return Golfer::findOne(['user_id' => Yii::$app->user->id]);
 }
예제 #3
0
 public function actionGolferSearch($id, $target, $term = '')
 {
     $model = $this->findCompetition($id);
     $golfers = Golfer::find()->all();
     $availables = [];
     foreach ($golfers as $golfer) {
         $availables[$golfer->id] = $golfer->name;
     }
     $registrations = Registration::find()->where(['competition_id' => $id, 'status' => array(Registration::STATUS_PENDING, Registration::STATUS_REGISTERED)])->all();
     $registereds = [];
     foreach ($registrations as $registration) {
         $registereds[$registration->golfer_id] = $availables[$registration->golfer_id];
         unset($availables[$registration->golfer_id]);
     }
     $result = [];
     if (!empty($term)) {
         foreach (${$target} as $golfer) {
             if (strpos($golfer, $term) !== false) {
                 $id = Golfer::findOne(['name' => $golfer]);
                 $result[$id->id] = $golfer;
             }
         }
     } else {
         $result = ${$target};
     }
     return Html::renderSelectOptions('', $result);
 }