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,7 +55,17 @@ | ||
| 55 | foreach ($model->getVariationModels() as $index => $lang){ | 55 | foreach ($model->getVariationModels() as $index => $lang){ |
| 56 | $lang->id = $index+1; | 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 | Yii::$app->session->setFlash('success', \Yii::t('core', 'Settings saved')); | 69 | Yii::$app->session->setFlash('success', \Yii::t('core', 'Settings saved')); |
| 60 | $mail->load(Yii::$app->request->post()); | 70 | $mail->load(Yii::$app->request->post()); |
| 61 | $mail->save(); | 71 | $mail->save(); |
| @@ -70,9 +80,31 @@ | @@ -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 | * Find site settings | 109 | * Find site settings |
| 78 | * | 110 | * |
backend/views/settings/_main_tab.php
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | use artbox\core\admin\widgets\ImageInput; | 3 | use artbox\core\admin\widgets\ImageInput; |
| 4 | use common\models\Settings; | 4 | use common\models\Settings; |
| 5 | + use kartik\file\FileInput; | ||
| 5 | use yii\bootstrap\ActiveForm; | 6 | use yii\bootstrap\ActiveForm; |
| 6 | use yii\web\View; | 7 | use yii\web\View; |
| 7 | 8 | ||
| @@ -10,6 +11,15 @@ | @@ -10,6 +11,15 @@ | ||
| 10 | * @var Settings $model | 11 | * @var Settings $model |
| 11 | * @var ActiveForm $form | 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 | echo '<div class="wrapp-blocks-edit-page">'; | 23 | echo '<div class="wrapp-blocks-edit-page">'; |
| 14 | echo $form->field($model, 'name') | 24 | echo $form->field($model, 'name') |
| 15 | ->textInput(); | 25 | ->textInput(); |
| @@ -17,14 +27,32 @@ | @@ -17,14 +27,32 @@ | ||
| 17 | 27 | ||
| 18 | echo '</div>'; | 28 | echo '</div>'; |
| 19 | echo '<div class="wrapp-blocks-edit-page">'; | 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 | echo '</div>'; | 56 | echo '</div>'; |
| 29 | echo '<div class="style">'; | 57 | echo '<div class="style">'; |
| 30 | foreach ($model->getVariationModels() as $index => $variationModel){ | 58 | foreach ($model->getVariationModels() as $index => $variationModel){ |
backend/views/settings/settings.php
| @@ -15,11 +15,8 @@ | @@ -15,11 +15,8 @@ | ||
| 15 | $this->params[ 'breadcrumbs' ][] = $this->title; | 15 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 16 | $languages = \artbox\core\models\Language::getActive(); | 16 | $languages = \artbox\core\models\Language::getActive(); |
| 17 | ?> | 17 | ?> |
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | <?php | 18 | <?php |
| 22 | - $form = ActiveForm::begin(); | 19 | + $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); |
| 23 | ?> | 20 | ?> |
| 24 | <div class="x_panel panel_settings"> | 21 | <div class="x_panel panel_settings"> |
| 25 | <div class="x_content"> | 22 | <div class="x_content"> |
common/models/Service.php
| @@ -149,4 +149,8 @@ class Service extends ActiveRecord | @@ -149,4 +149,8 @@ class Service extends ActiveRecord | ||
| 149 | { | 149 | { |
| 150 | return $this->hasMany(Service::className(), [ 'parent_id' => 'id' ]); | 150 | return $this->hasMany(Service::className(), [ 'parent_id' => 'id' ]); |
| 151 | } | 151 | } |
| 152 | + | ||
| 153 | + public function getPrices(){ | ||
| 154 | + return$this->hasMany(Price::className(), ['id' => 'service_id']); | ||
| 155 | + } | ||
| 152 | } | 156 | } |
common/models/Settings.php
| @@ -102,6 +102,7 @@ | @@ -102,6 +102,7 @@ | ||
| 102 | 'name', | 102 | 'name', |
| 103 | 'analytics_key', | 103 | 'analytics_key', |
| 104 | 'about', | 104 | 'about', |
| 105 | + 'logo' | ||
| 105 | ], | 106 | ], |
| 106 | 'string', | 107 | 'string', |
| 107 | ], | 108 | ], |
| @@ -122,20 +123,6 @@ | @@ -122,20 +123,6 @@ | ||
| 122 | [ | 123 | [ |
| 123 | 'logo', | 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 | 'filter', | 126 | 'filter', |
| 140 | 'filter' => function ($value) { | 127 | 'filter' => function ($value) { |
| 141 | if (empty( $value )) { | 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 | \ No newline at end of file | 45 | \ No newline at end of file |
frontend/views/layouts/main.php
| @@ -51,13 +51,6 @@ | @@ -51,13 +51,6 @@ | ||
| 51 | ] | 51 | ] |
| 52 | )->orderBy('sort') | 52 | )->orderBy('sort') |
| 53 | ->all(); | 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 | $this->registerMetaTag( | 55 | $this->registerMetaTag( |
| 63 | [ | 56 | [ |
| @@ -96,14 +89,20 @@ | @@ -96,14 +89,20 @@ | ||
| 96 | <div class="col-xs-7 col-sm-3 col-md-2 col-lg-2 logo-wrapp"> | 89 | <div class="col-xs-7 col-sm-3 col-md-2 col-lg-2 logo-wrapp"> |
| 97 | <a href="<?php echo \frontend\helpers\Url::home(); ?>"> | 90 | <a href="<?php echo \frontend\helpers\Url::home(); ?>"> |
| 98 | <?php | 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 | </a> | 106 | </a> |
| 108 | </div> | 107 | </div> |
| 109 | <div class="col-sm-9 col-md-10 col-lg-10 header-col"> | 108 | <div class="col-sm-9 col-md-10 col-lg-10 header-col"> |
| @@ -167,6 +166,9 @@ | @@ -167,6 +166,9 @@ | ||
| 167 | $items[] = [ | 166 | $items[] = [ |
| 168 | 'label' => \Yii::t('app', 'Цены'), | 167 | 'label' => \Yii::t('app', 'Цены'), |
| 169 | 'url' => '#', | 168 | 'url' => '#', |
| 169 | + 'options' => [ | ||
| 170 | + 'class' => 'active' | ||
| 171 | + ] | ||
| 170 | ]; | 172 | ]; |
| 171 | $items[] = [ | 173 | $items[] = [ |
| 172 | 'label' => \Yii::t('app', 'Пакетные предложения'), | 174 | 'label' => \Yii::t('app', 'Пакетные предложения'), |
| @@ -208,6 +210,9 @@ | @@ -208,6 +210,9 @@ | ||
| 208 | $itemsMobile[] = [ | 210 | $itemsMobile[] = [ |
| 209 | 'label' => \Yii::t('app', 'Цены'), | 211 | 'label' => \Yii::t('app', 'Цены'), |
| 210 | 'url' => '#', | 212 | 'url' => '#', |
| 213 | + 'options' => [ | ||
| 214 | + 'class' => 'active' | ||
| 215 | + ] | ||
| 211 | ]; | 216 | ]; |
| 212 | $itemsMobile[] = [ | 217 | $itemsMobile[] = [ |
| 213 | 'label' => \Yii::t('app', 'Пакетные предложения'), | 218 | 'label' => \Yii::t('app', 'Пакетные предложения'), |