Example #1
0
 /**
  * Creates a new Couple model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Couple();
     $bnames = [];
     $gnames = [];
     $bsurname = [];
     $gsurname = [];
     $years = [2015];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'bnames' => $bnames, 'bsurnames' => $bsurname, 'gnames' => $gnames, 'gsurnames' => $gsurname, 'years' => $years]);
     }
 }
Example #2
0
 /**
  * Регистрация на концерт
  * @param $id integer идентификатор концерта
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionIndex($id)
 {
     $model = $this->findConcert($id);
     if (false === $model) {
         throw new NotFoundHttpException("Этого конкурса не существует или он уже прошел.");
     } else {
         $couple = new Couple();
         $bnames = Couple::getBoysNames();
         $bsurnames = Couple::getBoysSurnames();
         $gnames = Couple::getGirlsNames();
         $gsurnames = Couple::getGirlsSurnames();
         $tours = $model->getTours()->all();
         $clubs = ArrayHelper::map(Club::find()->all(), 'id', function ($club) {
             /* @var $club Club */
             return $club->name . ' (' . $club->leader . ')';
         }, 'city');
         if (count($clubs) == 0) {
             throw new NotFoundHttpException("Отсутствуют клубы для регистрации");
         }
         if (count($tours) == 0) {
             throw new NotFoundHttpException("Туры на этот концерт еще не добавлены");
         }
         if ($couple->load(\Yii::$app->request->post()) && $couple->validate()) {
             if ($couple->save()) {
                 $c = new Couple();
                 $c->bname = $couple->bname;
                 $c->bsurname = $couple->bsurname;
                 $c->gname = $couple->gname;
                 $c->gsurname = $couple->gsurname;
                 $c->byear = $couple->byear;
                 $c->gyear = $couple->gyear;
                 $c->club_id = $couple->club_id;
                 $couple = $c;
                 \Yii::$app->session->addFlash('success', 'Пара успешно зарегистрирована');
             } else {
                 \Yii::$app->session->addFlash('warning', 'Пара не зарегистрирована. Проверьте правильность информации');
             }
         }
         return $this->render('reg', ['model' => $couple, 'bnames' => $bnames, 'bsurnames' => $bsurnames, 'gnames' => $gnames, 'gsurnames' => $gsurnames, 'years' => $this->getYears(1998, 2015), 'tours' => $tours, 'concert' => $model, 'clubs' => $clubs]);
     }
 }