Example #1
0
 /**
  * Updates an existing Couple model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $bnames = [];
     $gnames = [];
     $bsurname = [];
     $gsurname = [];
     $years = [2015];
     $clubs = ArrayHelper::map(Club::find()->all(), 'id', function ($club) {
         /* @var $club Club */
         return $club->name . ' (' . $club->leader . ')';
     }, 'city');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'bnames' => $bnames, 'bsurnames' => $bsurname, 'gnames' => $gnames, 'gsurnames' => $gsurname, 'years' => $years, 'clubs' => $clubs, 'tours' => $model->tour->concert->tours]);
     }
 }
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]);
     }
 }
Example #3
0
 /**
  * Lists all Club models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Club::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Example #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  *
  * @return mixed
  */
 public function destroy($id)
 {
     $canBeDeleted = empty(Club::find($id)->teams->toArray());
     if ($canBeDeleted) {
         Club::destroy($id);
         \Flash::success('Club deleted!');
     } else {
         \Flash::error('Cannot delete because they are existing teams in this club.');
     }
     return redirect('admin/data-management/clubs');
 }