/**
  * 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 = Competition::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Deregister currently logged user from competition
  * @param  [type] $competition_type Season, Tournament, or Match.
  * @param  [type] $competition_id   Identifier of competition
  * @return [type]                   Action to do after. Set flash on success/error.
  */
 public function actionDeregister($id)
 {
     if (!($me = Golfer::me())) {
         Yii::$app->session->setFlash('error', 'You need to be a registered golfer of this site to register to matches.');
     } else {
         $model = Competition::findOne($id);
         if ($model->deregister($me)) {
             Yii::$app->session->setFlash('success', Yii::t('igolf', 'You deregistered from competition "{0}".', $model->name));
         } else {
             Yii::$app->session->setFlash('error', Yii::t('igolf', 'You cannot deregister from competition "{0}".', $model->name));
         }
     }
     return $this->redirect(Yii::$app->request->getReferrer());
 }
Exemple #3
0
 /**
  * find a document instance and returns it property typed.
  *
  * @return app\models\{Document,Bid,Order,Bill} the document
  */
 public static function findCompetition($id)
 {
     $model = Competition::findOne($id);
     if ($model) {
         switch ($model->competition_type) {
             case self::TYPE_MATCH:
                 return Match::findOne($id);
                 break;
             case self::TYPE_TOURNAMENT:
                 return Tournament::findOne($id);
                 break;
             case self::TYPE_SEASON:
                 return Season::findOne($id);
                 break;
         }
     }
     return null;
 }