Exemple #1
0
 /**
  * @return int
  */
 public function countCouples()
 {
     $tours = $this->getTours()->all();
     $ids = [];
     foreach ($tours as $t) {
         $ids[] = $t->id;
     }
     $size = Couple::find()->where(['tour_id' => $ids])->count();
     return $size;
 }
 /**
  * Регистрация на концерт
  * @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]);
     }
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCouples()
 {
     return $this->hasMany(Couple::className(), ['tour_id' => 'id']);
 }
Exemple #4
0
 /**
  * Finds the Couple model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Couple the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Couple::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }