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); }
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); }
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' => 'На сервер передан неверный параметр']; } }