示例#1
0
 public function run()
 {
     $images = GlImgs::find()->where(['groups_id' => $this->gl_groups_id])->orderBy('seq')->all();
     if (!$images) {
         return false;
     }
     foreach ($images as $i => $image) {
         $items_small[] = Html::a(Html::img($image->img_small, ['class' => '']), $image->img_large, ['rel' => 'gl-linead-' . $this->gl_groups_id]);
     }
     echo Slick::widget(['items' => $items_small, 'containerOptions' => count($items_small) > 4 ? ['class' => 'gallery-line-ad'] : ['class' => 'lonely-item gallery-line-ad'], 'clientOptions' => ['slidesToShow' => 4, 'slidesToScroll' => 1], 'itemOptions' => ['class' => 'lineAdItem well well-sm']]);
     echo FancyBox::widget(['target' => 'a[rel=gl-linead-' . $this->gl_groups_id . ']', 'helpers' => true, 'mouse' => true, 'config' => ['maxWidth' => '90%', 'maxHeight' => '90%', 'playSpeed' => 4000, 'padding' => 0, 'fitToView' => false, 'width' => '70%', 'height' => '70%', 'autoSize' => false, 'closeClick' => false, 'openEffect' => 'elastic', 'closeEffect' => 'elastic', 'prevEffect' => 'elastic', 'nextEffect' => 'elastic', 'closeBtn' => false, 'openOpacity' => true, 'helpers' => ['title' => ['type' => 'float'], 'buttons' => [], 'thumbs' => ['width' => 68, 'height' => 50], 'overlay' => ['css' => ['background' => 'rgba(0, 0, 0, 0.8)']]]]]);
     $view = $this->view;
     GalleryAdAsset::register($view);
 }
示例#2
0
 public function run()
 {
     echo Html::activeHiddenInput($this->model, $this->attribute, $this->options);
     $groups_id = $this->attribute;
     $items = array();
     if ($this->model->{$groups_id}) {
         foreach (GlImgs::find()->where(['groups_id' => $this->model->{$groups_id}])->orderBy(['seq' => SORT_ASC])->all() as $i => $image) {
             $items[] = ['content' => Html::tag('div', Html::button(null, ['class' => 'btn btn-default btn-xs glyphicon glyphicon-remove', 'onclick' => 'removeUploadImage("' . $this->pluginOptions['url'] . '", ' . $image->id . ', "' . $image->basename_src . '", ' . $image->groups_id . ')']), ['style' => 'background:url("' . $image->img_small . '") 50% 50% no-repeat;', 'class' => 'upload-img', 'data-imgs-id' => $image->id, 'id' => 'upload-img-' . $image->id])];
         }
     }
     $items[] = ['content' => '<span class="glyphicon glyphicon-plus"></span><br>Добавить фото' . Html::fileInput(null, null, ['multiple' => true, 'data-url' => $this->pluginOptions['url'], 'data-type' => $this->pluginOptions['type'], 'data-input-id' => strtolower($this->model->formName()) . '-' . $groups_id, 'onchange' => 'prepareUpload($(this))', 'id' => 'js-upload-action']), 'disabled' => true, 'options' => ['class' => 'js-upload', 'onclick' => 'openFileDiaolg()']];
     echo Html::beginTag('div', ['class' => 'upload-gallery-content']);
     echo Sortable::widget(['type' => 'grid', 'items' => $items, 'pluginEvents' => ['sortupdate' => 'function(data) {reSortGallery("' . $this->pluginOptions['url'] . '")}'], 'options' => ['class' => 'js-upload-gallery']]);
     echo Html::tag('div', 'Основное изображение', ['class' => 'js-upload-image-default']);
     echo Html::endTag('div');
     /*echo Html::tag('div', '<small>Вы можете прикрепить не более 5 фотографий</small>', [
           'class' => 'text-muted',
       ]);*/
     $view = $this->view;
     UploadGalleryAsset::register($view);
 }
示例#3
0
 public function actionUpload()
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         switch (Yii::$app->request->post('action')) {
             case "addGroup":
                 $group = new GlGroups();
                 $type = GlTypes::findOne(['type' => Yii::$app->request->post('type')]);
                 $group->types_id = $type->id;
                 $group->save();
                 return ['success' => true, 'groups_id' => $group->id];
                 break;
             case "uploadImage":
                 $group = new GlGroups();
                 if (Yii::$app->request->post('groups_id')) {
                     $group = GlGroups::findOne(Yii::$app->request->post('groups_id'));
                     $type = GlTypes::findOne($group->types_id);
                 } else {
                 }
                 $file = $_FILES['input_file_name'];
                 if (GlImgs::findOne(['groups_id' => $group->id, 'basename_src' => $file['name']])) {
                     return ['success' => false, 'index' => Yii::$app->request->post('index'), 'error' => 'Вы уже загружали эту фотографию'];
                 }
                 $src_image = Yii::getAlias('@webroot') . self::TMP_PATH . '/' . $file['name'];
                 $dst_path = Yii::getAlias('@webroot') . $type->dir_dst;
                 move_uploaded_file($file['tmp_name'], $src_image);
                 $images = (new GlImgs())->convertImg($type->id, $src_image, $dst_path);
                 unlink($src_image);
                 $last_image = GlImgs::find()->where(['groups_id' => $group->id])->orderBy(['seq' => SORT_DESC])->one();
                 $image = new GlImgs();
                 $image->img_small = self::IMAGE_PATH . '/' . $type->type . '/' . $images['img_small'];
                 $image->img_large = self::IMAGE_PATH . '/' . $type->type . '/' . $images['img_large'];
                 $image->basename_src = $file['name'];
                 $image->seq = $last_image ? $last_image->seq + 1 : 1;
                 $image->groups_id = $group->id;
                 $image->save();
                 if (!$group->imgs_id) {
                     $group->imgs_id = $image->id;
                     $group->update();
                 }
                 return ['success' => true, 'index' => Yii::$app->request->post('index'), 'id' => $image->id, 'basename_src' => $image->basename_src, 'img_small' => $image->img_small];
                 break;
             case "deleteImage":
                 $f = fopen(Yii::getAlias('@webroot' . '/img/tmp/upload.log'), 'a');
                 $image = GlImgs::findOne(['id' => Yii::$app->request->post('id'), 'basename_src' => Yii::$app->request->post('basename_src')]);
                 if (!$image) {
                     return ['success' => false, 'error' => 'Файл не найден'];
                 }
                 $image->delete();
                 (new GlImgs())->reSort(Yii::$app->request->post('groups_id'));
                 $image = GlImgs::findOne(['groups_id' => Yii::$app->request->post('groups_id'), 'seq' => 1]);
                 $group = GlGroups::findOne(Yii::$app->request->post('groups_id'));
                 if (!$image) {
                     $group->delete();
                 }
                 if ($image && $group->imgs_id != $image->id) {
                     $group->imgs_id = $image->id;
                     $group->update();
                 }
                 fclose($f);
                 return ['success' => true, 'groups_id' => $image ? $group->id : false];
                 break;
             case "reSortGallery":
                 foreach (Yii::$app->request->post('images') as $imgs_id => $seq) {
                     $image = GlImgs::findOne($imgs_id);
                     $image->seq = $seq;
                     $image->save();
                     if ($seq == 1) {
                         $group = GlGroups::findOne($image->groups_id);
                         if ($group->imgs_id != $image->id) {
                             $group->imgs_id = $image->id;
                             $group->update();
                         }
                     }
                 }
                 return ['success' => true];
                 break;
         }
         return ['success' => false, 'error' => 'На сервер передан неверный параметр'];
     }
 }
示例#4
0
 private function addImage($links_id, $item)
 {
     $link_imgs_id = Links::findOne($links_id)->gl_imgs_id;
     $gl_groups = array();
     foreach ($item as $image_sxe) {
         $basename_src = basename(strval($image_sxe->{'ПутьКИзображению'}));
         if (!$basename_src) {
             continue;
         }
         preg_match('/_(.+)\\s\\[(.+)\\]/', $basename_src, $matches);
         if ($matches) {
             $type = $matches[1];
             $title = $matches[2];
         } else {
             $type = Yii::$app->params['defaultShGlType'];
             $title = '';
         }
         if (!GlImgs::findOne(['basename_src' => $basename_src])) {
             $gl_type = GlTypes::findOne(['type' => $type]);
             if (!isset($gl_groups[$type])) {
                 $gl_groups[$type] = GlGroups::findOne(['links_id' => $links_id, 'types_id' => $gl_type->id]);
                 if (!$gl_groups[$type]) {
                     $gl_group = new GlGroups();
                     $gl_group->types_id = GlTypes::findOne(['type' => $type])->id;
                     $gl_group->links_id = $links_id;
                     $gl_group->save();
                     $gl_groups[$type] = $gl_group;
                 }
             }
             $src_image = pathinfo($this->import_file)['dirname'] . '/' . strval($image_sxe->{'ПутьКИзображению'});
             $dst_path = Yii::getAlias('@frontend') . '/web' . $gl_type->dir_dst;
             $images = (new GlImgs())->convertImg($gl_type->id, addslashes($src_image), $dst_path);
             $gl_img = new GlImgs();
             $gl_img->groups_id = $gl_groups[$type]->id;
             $gl_img->img_small = $gl_type->dir_dst . '/' . $images['img_small'];
             $gl_img->img_large = $gl_type->dir_dst . '/' . $images['img_large'];
             $gl_img->basename_src = $basename_src;
             $gl_img->title = $title;
             $gl_img->seq = GlImgs::findLastSequence($gl_groups[$type]->id) + 1;
             $gl_img->save();
             if (!$link_imgs_id) {
                 $link = Links::findOne($links_id);
                 $link->gl_imgs_id = $gl_img->id;
                 $link->save();
                 $link_imgs_id = $gl_img->id;
                 $gl_groups[$type]->imgs_id = $gl_img->id;
                 $gl_groups[$type]->save();
             }
             if ($image_sxe->{'ОсновноеИзображение'} == 1 && $link_imgs_id != $gl_img->id) {
                 $link = Links::findOne($links_id);
                 $link->gl_imgs_id = $gl_img->id;
                 $link->save();
                 $link_imgs_id = $gl_img->id;
                 $gl_groups[$type]->imgs_id = $gl_img->id;
                 $gl_groups[$type]->save();
             }
         }
     }
 }