Commit aedc35b5e430a3cbacf46d164292622f53850db5
1 parent
be1c0c19
- load scg to logo
Showing
7 changed files
with
140 additions
and
43 deletions
Show diff stats
backend/controllers/SettingsController.php
| ... | ... | @@ -55,7 +55,17 @@ |
| 55 | 55 | foreach ($model->getVariationModels() as $index => $lang){ |
| 56 | 56 | $lang->id = $index+1; |
| 57 | 57 | } |
| 58 | - $model->save(); | |
| 58 | + if ($model->save()){ | |
| 59 | + if (!empty($_FILES)){ | |
| 60 | + $name = $this->saveLogo($_FILES['logo']['name'], $_FILES[ 'logo' ][ 'tmp_name' ]); | |
| 61 | + if ($name){ | |
| 62 | + print_r($name); | |
| 63 | + $model->logo = $name; | |
| 64 | + $model->save(); | |
| 65 | + print_r($model->errors); die(); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + } | |
| 59 | 69 | Yii::$app->session->setFlash('success', \Yii::t('core', 'Settings saved')); |
| 60 | 70 | $mail->load(Yii::$app->request->post()); |
| 61 | 71 | $mail->save(); |
| ... | ... | @@ -70,9 +80,31 @@ |
| 70 | 80 | ] |
| 71 | 81 | ); |
| 72 | 82 | } |
| 83 | + | |
| 84 | + | |
| 85 | + public function saveLogo($name, $tmp) | |
| 86 | + { | |
| 73 | 87 | |
| 74 | - | |
| 75 | - | |
| 88 | + if (!file_exists(\Yii::getAlias('@storage/logo'))) { | |
| 89 | + mkdir(\Yii::getAlias('@storage/logo') , 0777); | |
| 90 | + }else{ | |
| 91 | + foreach (glob(\Yii::getAlias('@storage/logo/*')) as $file) | |
| 92 | + unlink($file); | |
| 93 | + | |
| 94 | + } | |
| 95 | + if (!preg_match("~^([a-zA-Z0-9)(_-]+)\.(jpg|jpeg|gif|png|svg)$~i", $name, $matches)) { | |
| 96 | + return false; | |
| 97 | + } | |
| 98 | + if (!empty($tmp)) { | |
| 99 | + copy( | |
| 100 | + $tmp, | |
| 101 | + \Yii::getAlias('@storage/logo/') . $name | |
| 102 | + ); | |
| 103 | + chmod(\Yii::getAlias('@storage/logo/') . $name, 0777); | |
| 104 | + return $name; | |
| 105 | + } | |
| 106 | + return false; | |
| 107 | + } | |
| 76 | 108 | /** |
| 77 | 109 | * Find site settings |
| 78 | 110 | * | ... | ... |
backend/views/settings/_main_tab.php
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | use artbox\core\admin\widgets\ImageInput; |
| 4 | 4 | use common\models\Settings; |
| 5 | + use kartik\file\FileInput; | |
| 5 | 6 | use yii\bootstrap\ActiveForm; |
| 6 | 7 | use yii\web\View; |
| 7 | 8 | |
| ... | ... | @@ -10,6 +11,15 @@ |
| 10 | 11 | * @var Settings $model |
| 11 | 12 | * @var ActiveForm $form |
| 12 | 13 | */ |
| 14 | + | |
| 15 | + if (!empty($model->logo)) { | |
| 16 | + $logo[] = '<img src="/storage/logo/' . $model->logo . '" class="file-preview-image kv-preview-data rotate-35921 is-portrait-gt4" style="width:200px;" title="' . $model->logo . '">'; | |
| 17 | + $config = ["url" => "delete-image", "key" => 0, 'extra' => ['image' => $model->logo]]; | |
| 18 | + | |
| 19 | + } else { | |
| 20 | + $logo = []; | |
| 21 | + $config = []; | |
| 22 | + } | |
| 13 | 23 | echo '<div class="wrapp-blocks-edit-page">'; |
| 14 | 24 | echo $form->field($model, 'name') |
| 15 | 25 | ->textInput(); |
| ... | ... | @@ -17,14 +27,32 @@ |
| 17 | 27 | |
| 18 | 28 | echo '</div>'; |
| 19 | 29 | echo '<div class="wrapp-blocks-edit-page">'; |
| 20 | - echo $form->field($model, 'logo') | |
| 21 | - ->widget( | |
| 22 | - ImageInput::className(), | |
| 23 | - [ | |
| 24 | - 'showPreview' => true, | |
| 25 | - 'showDeletePickedImageConfirm' => false, | |
| 26 | - ] | |
| 27 | - ); | |
| 30 | + echo FileInput::widget( | |
| 31 | + [ | |
| 32 | + 'name' => 'logo', | |
| 33 | + 'options' => [ | |
| 34 | + 'multiple' => false, | |
| 35 | + 'accept' => 'image/*', | |
| 36 | + ], | |
| 37 | + 'pluginOptions' => [ | |
| 38 | + 'maxFileCount' => 9, | |
| 39 | + 'showUpload' => false, | |
| 40 | + 'removeClass' => 'btn btn-danger', | |
| 41 | + 'removeIcon' => '<i class="glyphicon glyphicon-trash"></i> ', | |
| 42 | + 'initialPreview' => $logo, | |
| 43 | + 'overwriteInitial' => true, | |
| 44 | + 'initialPreviewConfig' => $config | |
| 45 | + ], | |
| 46 | + ] | |
| 47 | + ); | |
| 48 | + // echo $form->field($model, 'logo') | |
| 49 | +// ->widget( | |
| 50 | +// ImageInput::className(), | |
| 51 | +// [ | |
| 52 | +// 'showPreview' => true, | |
| 53 | +// 'showDeletePickedImageConfirm' => false, | |
| 54 | +// ] | |
| 55 | +// ); | |
| 28 | 56 | echo '</div>'; |
| 29 | 57 | echo '<div class="style">'; |
| 30 | 58 | foreach ($model->getVariationModels() as $index => $variationModel){ | ... | ... |
backend/views/settings/settings.php
| ... | ... | @@ -15,11 +15,8 @@ |
| 15 | 15 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 16 | 16 | $languages = \artbox\core\models\Language::getActive(); |
| 17 | 17 | ?> |
| 18 | - | |
| 19 | - | |
| 20 | - | |
| 21 | 18 | <?php |
| 22 | - $form = ActiveForm::begin(); | |
| 19 | + $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); | |
| 23 | 20 | ?> |
| 24 | 21 | <div class="x_panel panel_settings"> |
| 25 | 22 | <div class="x_content"> | ... | ... |
common/models/Service.php
common/models/Settings.php
| ... | ... | @@ -102,6 +102,7 @@ |
| 102 | 102 | 'name', |
| 103 | 103 | 'analytics_key', |
| 104 | 104 | 'about', |
| 105 | + 'logo' | |
| 105 | 106 | ], |
| 106 | 107 | 'string', |
| 107 | 108 | ], |
| ... | ... | @@ -122,20 +123,6 @@ |
| 122 | 123 | [ |
| 123 | 124 | 'logo', |
| 124 | 125 | ], |
| 125 | - 'integer', | |
| 126 | - ], | |
| 127 | - [ | |
| 128 | - [ | |
| 129 | - 'logo', | |
| 130 | - ], | |
| 131 | - 'exist', | |
| 132 | - 'targetClass' => ImageManager::className(), | |
| 133 | - 'targetAttribute' => 'id', | |
| 134 | - ], | |
| 135 | - [ | |
| 136 | - [ | |
| 137 | - 'logo', | |
| 138 | - ], | |
| 139 | 126 | 'filter', |
| 140 | 127 | 'filter' => function ($value) { |
| 141 | 128 | if (empty( $value )) { | ... | ... |
| 1 | +<?php | |
| 2 | + /** | |
| 3 | + * Created by PhpStorm. | |
| 4 | + * User: stes | |
| 5 | + * Date: 29.05.18 | |
| 6 | + * Time: 9:51 | |
| 7 | + */ | |
| 8 | + | |
| 9 | + namespace frontend\controllers; | |
| 10 | + | |
| 11 | + use common\models\Service; | |
| 12 | + use yii\web\Controller; | |
| 13 | + use yii\web\NotFoundHttpException; | |
| 14 | + | |
| 15 | + class ServiceController extends Controller | |
| 16 | + { | |
| 17 | + public function actionIndex(){ | |
| 18 | + | |
| 19 | + } | |
| 20 | + | |
| 21 | + public function actionView($id){ | |
| 22 | + $model = $this->findModel($id); | |
| 23 | + if ($model->parent_id == null){ | |
| 24 | + $others = Service::find()->where(['parent_id' => $model->id])->all(); | |
| 25 | + }else{ | |
| 26 | + $others = Service::find()->where(['parent_id' => $model->parent_id])->all(); | |
| 27 | + } | |
| 28 | + | |
| 29 | + return $this->render('view', [ | |
| 30 | + 'model' => $model, | |
| 31 | + 'others'=> $others | |
| 32 | + ]); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public function findModel($id){ | |
| 36 | + $model = Service::find() | |
| 37 | + ->where(['id' => $id, 'status' => true]) | |
| 38 | + ->with(['language.alias', 'image', 'prices'])->one(); | |
| 39 | + if (empty($model)){ | |
| 40 | + throw new NotFoundHttpException('Model not found'); | |
| 41 | + } | |
| 42 | + return $model; | |
| 43 | + } | |
| 44 | + } | |
| 0 | 45 | \ No newline at end of file | ... | ... |
frontend/views/layouts/main.php
| ... | ... | @@ -51,13 +51,6 @@ |
| 51 | 51 | ] |
| 52 | 52 | )->orderBy('sort') |
| 53 | 53 | ->all(); |
| 54 | - $logo = null; | |
| 55 | - if ($settings->logo) { | |
| 56 | - $logo_img = ImageManager::findOne($settings->logo); | |
| 57 | - if ($logo_img) { | |
| 58 | - $logo = $logo_img->getImagePathPrivate() ?? $logo; | |
| 59 | - } | |
| 60 | - } | |
| 61 | 54 | |
| 62 | 55 | $this->registerMetaTag( |
| 63 | 56 | [ |
| ... | ... | @@ -96,14 +89,20 @@ |
| 96 | 89 | <div class="col-xs-7 col-sm-3 col-md-2 col-lg-2 logo-wrapp"> |
| 97 | 90 | <a href="<?php echo \frontend\helpers\Url::home(); ?>"> |
| 98 | 91 | <?php |
| 99 | - echo ImageHelper::set($logo) | |
| 100 | - ->setHeight(44) | |
| 101 | - ->renderImage( | |
| 102 | - [ | |
| 103 | - 'alt' => $settings->name, | |
| 104 | - ] | |
| 105 | - ) | |
| 92 | + if ($settings->logo != null){ | |
| 93 | + echo '<img src="/storage/logo/'.$settings->logo.'" alt="">'; | |
| 94 | + }else{ | |
| 95 | + echo ImageHelper::set(null) | |
| 96 | + ->setHeight(44) | |
| 97 | + ->renderImage( | |
| 98 | + [ | |
| 99 | + 'alt' => $settings->name, | |
| 100 | + ] | |
| 101 | + ); | |
| 102 | + } | |
| 103 | + | |
| 106 | 104 | ?> |
| 105 | + | |
| 107 | 106 | </a> |
| 108 | 107 | </div> |
| 109 | 108 | <div class="col-sm-9 col-md-10 col-lg-10 header-col"> |
| ... | ... | @@ -167,6 +166,9 @@ |
| 167 | 166 | $items[] = [ |
| 168 | 167 | 'label' => \Yii::t('app', 'Цены'), |
| 169 | 168 | 'url' => '#', |
| 169 | + 'options' => [ | |
| 170 | + 'class' => 'active' | |
| 171 | + ] | |
| 170 | 172 | ]; |
| 171 | 173 | $items[] = [ |
| 172 | 174 | 'label' => \Yii::t('app', 'Пакетные предложения'), |
| ... | ... | @@ -208,6 +210,9 @@ |
| 208 | 210 | $itemsMobile[] = [ |
| 209 | 211 | 'label' => \Yii::t('app', 'Цены'), |
| 210 | 212 | 'url' => '#', |
| 213 | + 'options' => [ | |
| 214 | + 'class' => 'active' | |
| 215 | + ] | |
| 211 | 216 | ]; |
| 212 | 217 | $itemsMobile[] = [ |
| 213 | 218 | 'label' => \Yii::t('app', 'Пакетные предложения'), | ... | ... |