Exemple #1
0
 /**
  * Creates a new Club model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Club();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionCreateClub()
 {
     User::redirectOnHomepageIfGuest($this);
     $model = new Club();
     $image = new UploadImage();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $tmp = [];
         for ($i = 1; $i <= 8; ++$i) {
             $tmp[] = $i;
         }
         $tmp[] = 13;
         $model->date = date('Y-m-d H:i:s');
         $model->photo_count = 0;
         $model->id_author = Yii::$app->user->getId();
         $model->user_count = 1;
         $model->rating = 1 + mt_rand() % 100000000.0 / 10000000000000.0;
         $cl = Yii::$app->request->post('Club');
         $model->close_comments = isset($cl['close_comments']) ? 1 : 0;
         if (!$model->style) {
             $model->style = 1;
         }
         if (!$model->background) {
             $model->background = 1;
         }
         //якщо пробували підмінити деякі дані
         if (!in_array($model->type, [1, 2]) || !in_array($model->background, $tmp) || !Category::isSetCategory($model->id_level_1)) {
             return $this->redirect('/');
         }
         // збереження табнейла
         $image->file = UploadedFile::getInstance($image, 'file');
         if ($image->file && $image->validate()) {
             $model->img_src = md5(uniqid(mt_rand())) . '.' . $image->file->extension;
             $image->savePhotoThumbnail($model->img_src);
         } else {
             $model->img_src = '';
             //                \Yii::$app->getSession()->setFlash('notify', 'при збереженні табнейла сталася помилка');
         }
         if ($model->save()) {
             Club::addNewUser($model->id, Yii::$app->user->getId(), 1);
             return $this->redirect('/club' . $model->id);
             \Yii::$app->getSession()->setFlash('notify', 'Клуб успішно створено!');
         } else {
             echo '<pre>';
             print_r($model);
             echo '</pre>';
             die;
         }
     }
     $colors = Yii::$app->params['club_colors'];
     $all_categories = Category::getAllTranslatedCategory();
     return $this->render('settings', ['action' => 'Створення клубу', 'model' => $model, 'colors' => $colors, 'image' => $image, 'all_categories' => $all_categories]);
 }