Example #1
0
 public function afterUpdate()
 {
     try {
         if ($this->seoText->load(Yii::$app->request->post())) {
             $this->seoText->setAttributes(['_image' => UploadedFile::getInstance($this->seoText, '_image')]);
             // if(!$this->seoText->isEmpty()){
             if ($this->seoText->save()) {
                 if ($this->seoText->_image) {
                     $old = $this->seoText->ogImage;
                     $photo = new Photo();
                     $photo->class = get_class($this->seoText);
                     $photo->item_id = $this->seoText->seotext_id;
                     $photo->image = $this->seoText->_image;
                     if ($photo->image && $photo->validate(['image'])) {
                         $photo->image = Image::upload($photo->image, 'photos', Photo::PHOTO_MAX_WIDTH);
                         if ($photo->image) {
                             if ($photo->save()) {
                                 $old->delete();
                             } else {
                                 @unlink(Yii::getAlias('@webroot') . str_replace(Url::base(true), '', $photo->image));
                             }
                         } else {
                         }
                     }
                 }
             }
         }
     } catch (UnknownMethodException $e) {
     }
 }
Example #2
0
 public function actionImage($id, $maxWidth, $thumbWidth, $thumbHeight = null, $thumbCrop = true)
 {
     $success = null;
     if ($photo = Photo::findOne($id)) {
         $oldImage = $photo->image;
         $oldThumb = $photo->thumb;
         $photo->image = UploadedFile::getInstance($photo, 'image');
         if ($photo->image && $photo->validate(['image'])) {
             $photo->image = Image::upload($photo->image, 'photos', $maxWidth);
             if ($photo->image) {
                 $photo->thumb = Image::createThumbnail($photo->image, $thumbWidth, $thumbHeight, $thumbCrop);
                 if ($photo->save()) {
                     @unlink(Yii::getAlias('@webroot') . $oldImage);
                     @unlink(Yii::getAlias('@webroot') . $oldThumb);
                     $success = ['message' => Yii::t('easyii', 'Photo uploaded'), 'photo' => ['thumb' => $photo->thumb, 'image' => $photo->image]];
                 } else {
                     @unlink(Yii::getAlias('@webroot') . $photo->image);
                     @unlink(Yii::getAlias('@webroot') . $photo->thumb);
                     $this->error = Yii::t('easyii', 'Update error. {0}', $photo->formatErrors());
                 }
             } else {
                 $this->error = Yii::t('easyii', 'File upload error. Check uploads folder for write permissions');
             }
         } else {
             $this->error = Yii::t('easyii', 'File is incorrect');
         }
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse($success);
 }
 public function actionEdit($id)
 {
     if (!($model = Item::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['articleThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'sections');
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/sections', 'Article updated'));
                 return $this->redirect(['/admin/' . $this->module->id . '/items/edit', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
Example #4
0
 public function actionEdit($id)
 {
     $model = Carousel::findOne($id);
     if ($model === null) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if ($fileInstanse = UploadedFile::getInstance($model, 'image')) {
                 $model->image = $fileInstanse;
                 if ($model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'carousel');
                 } else {
                     $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                     return $this->refresh();
                 }
             } else {
                 $model->image = $model->oldAttributes['image'];
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/carousel', 'Carousel updated'));
             } else {
                 $this->flash('error', Yii::t('easyii/carousel', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
Example #5
0
 public function actionEdit($id)
 {
     if (!($model = Category::findOne($id))) {
         return $this->redirect(['/admin/catalog']);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['categoryThumb']) {
                 $model->thumb = UploadedFile::getInstance($model, 'thumb');
                 if ($model->thumb && $model->validate(['thumb'])) {
                     $model->thumb = Image::upload($model->thumb, 'catalog', $this->module->settings['categoryThumbWidth'], $this->module->settings['categoryThumbHeight'], $this->module->settings['categoryThumbCrop']);
                 } else {
                     $model->thumb = $model->oldAttributes['thumb'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/catalog', 'Category updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
Example #6
0
 public function actionImage($id)
 {
     $success = null;
     if ($photo = Photo::findOne($id)) {
         $oldImage = $photo->image;
         $photo->image = UploadedFile::getInstance($photo, 'image');
         if ($photo->image && $photo->validate(['image'])) {
             $photo->image = Image::upload($photo->image, 'photos', Photo::PHOTO_MAX_WIDTH);
             if ($photo->image) {
                 if ($photo->save()) {
                     @unlink(Yii::getAlias('@webroot') . $oldImage);
                     $success = ['message' => Yii::t('easyii', 'Photo uploaded'), 'photo' => ['image' => $photo->image, 'thumb' => Image::thumb($photo->image, Photo::PHOTO_THUMB_WIDTH, Photo::PHOTO_THUMB_HEIGHT)]];
                 } else {
                     @unlink(Yii::getAlias('@webroot') . $photo->image);
                     $this->error = Yii::t('easyii', 'Update error. {0}', $photo->formatErrors());
                 }
             } else {
                 $this->error = Yii::t('easyii', 'File upload error. Check uploads folder for write permissions');
             }
         } else {
             $this->error = Yii::t('easyii', 'File is incorrect');
         }
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse($success);
 }
Example #7
0
 public function actionUpload($dir = '')
 {
     $fileInstance = UploadedFile::getInstanceByName('file');
     if ($fileInstance) {
         $file = Image::upload($fileInstance, $dir);
         if ($file) {
             return $this->getResponse($file);
         }
     }
     return ['error' => 'Unable to save image file'];
 }
Example #8
0
 /**
  * Create form
  *
  * @param null $parent
  * @return array|string|\yii\web\Response
  * @throws \yii\web\HttpException
  */
 public function actionCreate($parent = null)
 {
     $class = $this->categoryClass;
     $model = new $class();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['categoryThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, $this->moduleName);
                 } else {
                     $model->image = '';
                 }
             }
             $model->status = $class::STATUS_ON;
             $parent = (int) Yii::$app->request->post('parent', null);
             if ($parent > 0 && ($parentCategory = $class::findOne($parent))) {
                 $model->order_num = $parentCategory->order_num;
                 $model->appendTo($parentCategory);
             } else {
                 $model->attachBehavior('sortable', SortableModel::className());
                 $model->makeRoot();
             }
             if (!$model->hasErrors()) {
                 $this->flash('success', Yii::t('easyii', 'Category created'));
                 return $this->redirect(['/admin/' . $this->moduleName, 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'parent' => $parent]);
     }
 }
 public function actionUpdate($id)
 {
     if (!($model = Item::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['articleThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'article');
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 foreach ($model->itemCategories as $itemCategory) {
                     $itemCategory->delete();
                 }
                 foreach ($model->categoryIds as $order => $category) {
                     $itemCategory = new ItemCategory(['item_id' => $model->primaryKey, 'category_id' => $category, 'order' => $order]);
                     $itemCategory->save();
                 }
                 $this->flash('success', Yii::t('easyii', 'Article updated'));
                 return $this->redirect(['update', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Example #10
0
 /**
  * Edit form
  *
  * @param $id
  * @return array|string|\yii\web\Response
  * @throws \yii\web\HttpException
  */
 public function actionEdit($id)
 {
     return;
     $class = $this->categoryClass;
     if (!($model = $class::findOne($id))) {
         return $this->redirect(['/admin/' . $this->moduleName]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['categoryThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, $this->moduleName);
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii', 'Category updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('@easyii/views/category/edit', ['model' => $model]);
     }
 }
Example #11
0
 public function actionEdit($id)
 {
     if (!($item = Item::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     $model = new ItemForm(['item' => $item, 'category' => $item->category]);
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['itemThumb']) {
                 $model->item->image = UploadedFile::getInstance($model, 'image');
                 if ($model->item->image && $model->item->validate(['image'])) {
                     $model->item->image = Image::upload($model->item->image, 'catalog');
                 } else {
                     $model->item->image = '';
                 }
             }
             if ($model->item->save()) {
                 $this->flash('success', Yii::t('easyii/catalog', 'Item created'));
                 return $this->redirect(['/admin/' . $this->module->id . '/items/edit/', 'id' => $model->item->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->item->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
 public function actionEdit($id)
 {
     if (!($model = Item::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             $model->data = Yii::$app->request->post('Data');
             if (isset($_FILES) && $this->module->settings['itemThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'customers');
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 //Delete old Data
                 $model->deleteSelectedServices();
                 $products = Yii::$app->request->post('products');
                 if ($products) {
                     foreach ($products as $item) {
                         $CustomerData = new CustomerItems();
                         $CustomerData->item_id = $item;
                         $CustomerData->customer_id = $model->item_id;
                         $CustomerData->save();
                     }
                 }
                 $this->flash('success', Yii::t('easyii/customers', 'Item updated'));
                 return $this->redirect(['/admin/' . $this->module->id . '/items/edit', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         //get selected values
         $selected = $model->getSelectedServices();
         return $this->render('edit', ['model' => $model, 'selectedData' => $selected, 'dataForm' => $this->generateForm($model->category->fields, $model->data)]);
     }
 }