Example #1
0
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post())) {
         $photo = UploadedFile::getInstances($model, 'photo');
         $images = UploadedFile::getInstances($model, 'images');
         $model->url = $this->SlugHelperUrl($model->title);
         $model->created = date('Y-m-d H:i:s');
         if ($photo) {
             $photo[0]->saveAs('web/upload/article/' . Yii::$app->user->identity->id . '_' . time() . '.' . $photo[0]->extension);
             $model->photo = Yii::$app->user->identity->id . '_' . time() . '.' . $photo[0]->extension;
         } else {
             Yii::trace($photo->errors);
         }
         if ($images) {
             $images[0]->saveAs('web/upload/article/' . Yii::$app->user->identity->id . '_' . time() . '.' . $images[0]->extension);
             $model->images = Yii::$app->user->identity->id . '_im' . time() . '.' . $images[0]->extension;
         } else {
             Yii::trace($photo->errors);
         }
         if ($model->photo != '' && !file_exists(__DIR__ . '/../../../web/upload/300_174/300_174_' . $model->photo) && file_exists(__DIR__ . '/../../../web/upload/article/' . $model->photo)) {
             $thumb = new Imagick(__DIR__ . '/../../../web/upload/article/' . $model->photo);
             $thumb->resizeImage(300, 174, Imagick::FILTER_LANCZOS, 1);
             $thumb->writeImage(__DIR__ . '/../../../web/upload/300_174/300_174_' . $model->photo);
             $thumb->destroy();
         }
         $model->save();
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->layout = 'admin';
     $model = new Article();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['browse']);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all()]);
     }
 }
Example #4
0
 public function actionUpdate($id = null)
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post())) {
         $request = Yii::$app->request->post('Article');
         $id = $request['id'];
         if ($id) {
             $model = Article::findOne($id);
             $model->attributes = $request;
         }
         if ($model->save()) {
             $this->updateOrder('cid=' . $model->cid, '&langs=' . $model->langs);
             $files = \yii\web\UploadedFile::getInstances($model, 'upload_files');
             if (isset($files) && count($files) > 0) {
                 $mPath = \Yii::getAlias('@webroot') . '/images/article/news_' . $model->id;
                 if (!is_dir($mPath)) {
                     \yii\helpers\BaseFileHelper::createDirectory($mPath);
                 }
                 foreach ($files as $file) {
                     if ($request['cid'] == '12') {
                         $mPic = $file->baseName . '.' . $file->extension;
                     } else {
                         $mPic = 'nkc_' . substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $file->extension;
                     }
                     //Upload Images
                     if ($file->saveAs($mPath . '/' . $mPic)) {
                         $image = \Yii::$app->image->load($mPath . '/' . $mPic);
                         $image->resize(1024, 1024);
                         $image->save($mPath . '/' . $mPic);
                         //resize images thumb
                         $image = \Yii::$app->image->load($mPath . '/' . $mPic);
                         $image->resize(250, 250);
                         $mThumb = $mPath . '/thumb/';
                         if (!is_dir($mThumb)) {
                             \yii\helpers\BaseFileHelper::createDirectory($mThumb);
                         }
                         $image->save($mThumb . $mPic);
                     }
                 }
             }
             return $this->redirect(array('index'));
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Article::findOne($id);
     } else {
         $sess = Yii::$app->session->get('sessArticle');
         $model->langs = $sess['langs'];
         $model->cid = $sess['cid'];
     }
     return $this->render('update', ['model' => $model]);
 }
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     $tourtype = new Tourtype();
     $small = new FileUpload();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'tourtype' => $tourtype, 'small' => $small]);
     }
 }
Example #6
0
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post())) {
         $model->preview_input = UploadedFile::getInstance($model, 'preview_input');
         if (!empty($model->preview_input)) {
             $model->preview_picture = 'preview/' . $model->preview_input->baseName . '.' . $model->preview_input->extension;
         }
         if ($model->save()) {
             Yii::warning("Article changed. Attributes = " . print_r($model->attributes));
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     $uploader = new Uploader();
     if (Yii::$app->request->isPost) {
         $uploader->imageFile = UploadedFile::getInstance($uploader, 'imageFile');
         $model->user_id = Yii::$app->user->identity->id;
         $model->date = date("Y-m-d H:i:s");
         $model->image_tag = $uploader->imageFile->basename;
         $model->image_extension = $uploader->imageFile->extension;
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             if ($uploader->upload($model->id)) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Example #8
0
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     $model->user_id = Yii::$app->user->id;
     if (Yii::$app->user->can('createArticle', ['model' => $model])) {
         // Check permission before process acction
         if ($model->load(Yii::$app->request->post())) {
             $this->Uploads(false);
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             $model->ref = substr(Yii::$app->getSecurity()->generateRandomString(), 10);
         }
         return $this->render('create', ['model' => $model]);
     } else {
         throw new ForbiddenHttpException('ขอแสดงความเสียใจอย่างสุดซื้ง!, คุณไม่ได้รับอนุญาตให้เข้าใช้งาน');
     }
     /*if ($model->load(Yii::$app->request->post()) && $model->validate()) {
           $model->thumbnail = $model->uploadThumbnail($model,'thumbnail');
           $model->photos = $model->uploadMultipleImg($model,'photos');
           $model->files = $model->uploadMultipleFiles($model,'files');
           $model->save();
           return $this->redirect(['view', 'id' => $model->id]);
       } else {
           return $this->render('create', [
           'model' => $model,
           ]);
       }*/
     /*
     if ($model->load(Yii::$app->request->post()) && $model->save())
     {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     else
     {
         return $this->render('create', [
         'model' => $model,
         ]);
     }
     */
 }
Example #9
0
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post())) {
         $categories = new ArticleCategories();
         $model->psychologist_id = Yii::$app->user->id;
         $model->is_owner = 1;
         if ($model->save()) {
             $articleCategories = Yii::$app->request->post('categories');
             if ($categories->saveArticleCategories($model->id, $articleCategories)) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]);
         }
         /*if ($model->save()) {
               return $this->redirect(['view', 'id' => $model->id]);
           }*/
     } else {
         return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]);
     }
 }