Exemple #1
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]);
     }
 }
Exemple #2
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]);
     }
 }
 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);
 }
 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]);
     }
 }
Exemple #6
0
 /**
  * Creates thumb from model->image attribute with specified width and height.
  * @param int|null $width
  * @param int|null $height
  * @param bool $crop if false image will be resize instead of cropping
  * @return string
  */
 public function thumb($width = null, $height = null, $crop = true)
 {
     if ($this->image && ($width || $height)) {
         return Image::thumb($this->image, $width, $height, $crop);
     }
     return '';
 }
Exemple #7
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) {
     }
 }
 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'];
 }
Exemple #9
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]);
     }
 }
 public function actionLogo()
 {
     $model = Setting::find()->where(['name' => 'logo'])->one();
     if ($model === null || $model->visibility < (IS_ROOT ? Setting::VISIBLE_ROOT : Setting::VISIBLE_ALL)) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/settings']);
     }
     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($_POST['Setting']['value'])) {
                 $model->value = UploadedFile::getInstance($model, 'value');
                 if ($model->value) {
                     $model->value = Image::uploadLogo($model->value, 'logo', false);
                 } else {
                     $model->value = '';
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii', 'Setting updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('logo', ['model' => $model]);
     }
 }
Exemple #12
0
<?php

use yii\easyii\helpers\Image;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
$form = ActiveForm::begin(['enableAjaxValidation' => false, 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form ']]);
?>

    <?php 
if ($model->value) {
    ?>
        <p><img src="<?php 
    echo Image::thumb($model->value, 240);
    ?>
"></p>
        <p>
            <a href="<?php 
    echo Url::to(['/admin/settings/clear-image', 'id' => $model->primaryKey]);
    ?>
" class="text-danger confirm-delete" title="<?php 
    echo Yii::t('easyii', 'Remove logo');
    ?>
">
                <i class="glyphicon glyphicon-remove"></i> <?php 
    echo Yii::t('easyii', 'Remove logo');
    ?>
            </a>
         </p>
    <?php 
} else {
Exemple #13
0
use yii\widgets\ActiveForm;
use yii\easyii\widgets\Redactor;
use yii\easyii\widgets\SeoForm;
$module = $this->context->module->id;
$form = ActiveForm::begin(['enableAjaxValidation' => true, 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form']]);
echo $form->field($model, 'title');
?>

<?php 
if ($this->context->module->settings['articleThumb']) {
    ?>
    <?php 
    if ($model->image) {
        ?>
        <img src="<?php 
        echo Image::thumb($model->image, 240);
        ?>
">
        <a href="<?php 
        echo Url::to(['/admin/' . $module . '/items/clear-image', 'id' => $model->primaryKey]);
        ?>
" class="text-danger confirm-delete" title="<?php 
        echo Yii::t('easyii', 'Clear image');
        ?>
"><?php 
        echo Yii::t('easyii', 'Clear image');
        ?>
</a>
    <?php 
    }
    ?>
Exemple #14
0
 public function getCrop($width, $height)
 {
     return \yii\easyii\helpers\Image::thumb($this->model->image, $width, $height);
 }
Exemple #15
0
echo Yii::t('easyii', 'Image');
?>
</th>
        <th><?php 
echo Yii::t('easyii', 'Description');
?>
</th>
        <th width="150"></th>
    </tr>
    </thead>
    <tbody>
    <?php 
foreach ($photos as $photo) {
    ?>
        <?php 
    echo str_replace(['{{photo_id}}', '{{photo_thumb}}', '{{photo_image}}', '{{photo_description}}'], [$photo->primaryKey, Image::thumb($photo->image, Photo::PHOTO_THUMB_WIDTH, Photo::PHOTO_THUMB_HEIGHT), $photo->image, $photo->description], $photoTemplate);
    ?>
    <?php 
}
?>
    </tbody>
</table>
<p class="empty" style="display: <?php 
echo count($photos) ? 'none' : 'block';
?>
;"><?php 
echo Yii::t('easyii', 'No photos uploaded yet');
?>
.</p>

<?php 
 /**
  * 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]);
     }
 }
Exemple #17
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)]);
     }
 }
Exemple #19
0
use yii\easyii\modules\gallery\api\Gallery;
use yii\easyii\modules\page\api\Page;
use yii\helpers\Html;
use yii\helpers\Url;
$page = Page::get('page-gallery');
$this->title = $page->seo('title', $page->model->title);
$this->params['breadcrumbs'][] = $page->model->title;
?>
<h1><?php 
echo $page->seo('h1', $page->title);
?>
</h1>
<br/>

<?php 
foreach (Gallery::cats() as $album) {
    ?>
    <a class="center-block" href="<?php 
    echo Url::to(['gallery/view', 'slug' => $album->slug]);
    ?>
">
        <?php 
    echo Html::img(Image::thumb($album->image, 160, 120));
    ?>
<br/><?php 
    echo $album->title;
    ?>
    </a>
    <br/>
<?php 
}