diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php index 83fddc0..e7baab9 100755 --- a/backend/controllers/SettingsController.php +++ b/backend/controllers/SettingsController.php @@ -55,7 +55,17 @@ foreach ($model->getVariationModels() as $index => $lang){ $lang->id = $index+1; } - $model->save(); + if ($model->save()){ + if (!empty($_FILES)){ + $name = $this->saveLogo($_FILES['logo']['name'], $_FILES[ 'logo' ][ 'tmp_name' ]); + if ($name){ + print_r($name); + $model->logo = $name; + $model->save(); + print_r($model->errors); die(); + } + } + } Yii::$app->session->setFlash('success', \Yii::t('core', 'Settings saved')); $mail->load(Yii::$app->request->post()); $mail->save(); @@ -70,9 +80,31 @@ ] ); } + + + public function saveLogo($name, $tmp) + { - - + if (!file_exists(\Yii::getAlias('@storage/logo'))) { + mkdir(\Yii::getAlias('@storage/logo') , 0777); + }else{ + foreach (glob(\Yii::getAlias('@storage/logo/*')) as $file) + unlink($file); + + } + if (!preg_match("~^([a-zA-Z0-9)(_-]+)\.(jpg|jpeg|gif|png|svg)$~i", $name, $matches)) { + return false; + } + if (!empty($tmp)) { + copy( + $tmp, + \Yii::getAlias('@storage/logo/') . $name + ); + chmod(\Yii::getAlias('@storage/logo/') . $name, 0777); + return $name; + } + return false; + } /** * Find site settings * diff --git a/backend/views/settings/_main_tab.php b/backend/views/settings/_main_tab.php index 4325e70..d8e2fe2 100755 --- a/backend/views/settings/_main_tab.php +++ b/backend/views/settings/_main_tab.php @@ -2,6 +2,7 @@ use artbox\core\admin\widgets\ImageInput; use common\models\Settings; + use kartik\file\FileInput; use yii\bootstrap\ActiveForm; use yii\web\View; @@ -10,6 +11,15 @@ * @var Settings $model * @var ActiveForm $form */ + + if (!empty($model->logo)) { + $logo[] = ''; + $config = ["url" => "delete-image", "key" => 0, 'extra' => ['image' => $model->logo]]; + + } else { + $logo = []; + $config = []; + } echo '
'; echo $form->field($model, 'name') ->textInput(); @@ -17,14 +27,32 @@ echo '
'; echo '
'; - echo $form->field($model, 'logo') - ->widget( - ImageInput::className(), - [ - 'showPreview' => true, - 'showDeletePickedImageConfirm' => false, - ] - ); + echo FileInput::widget( + [ + 'name' => 'logo', + 'options' => [ + 'multiple' => false, + 'accept' => 'image/*', + ], + 'pluginOptions' => [ + 'maxFileCount' => 9, + 'showUpload' => false, + 'removeClass' => 'btn btn-danger', + 'removeIcon' => ' ', + 'initialPreview' => $logo, + 'overwriteInitial' => true, + 'initialPreviewConfig' => $config + ], + ] + ); + // echo $form->field($model, 'logo') +// ->widget( +// ImageInput::className(), +// [ +// 'showPreview' => true, +// 'showDeletePickedImageConfirm' => false, +// ] +// ); echo '
'; echo '
'; foreach ($model->getVariationModels() as $index => $variationModel){ diff --git a/backend/views/settings/settings.php b/backend/views/settings/settings.php index da07fd8..b71f9bf 100755 --- a/backend/views/settings/settings.php +++ b/backend/views/settings/settings.php @@ -15,11 +15,8 @@ $this->params[ 'breadcrumbs' ][] = $this->title; $languages = \artbox\core\models\Language::getActive(); ?> - - - ['enctype' => 'multipart/form-data']]); ?>
diff --git a/common/models/Service.php b/common/models/Service.php index fb9de29..bcba34b 100644 --- a/common/models/Service.php +++ b/common/models/Service.php @@ -149,4 +149,8 @@ class Service extends ActiveRecord { return $this->hasMany(Service::className(), [ 'parent_id' => 'id' ]); } + + public function getPrices(){ + return$this->hasMany(Price::className(), ['id' => 'service_id']); + } } diff --git a/common/models/Settings.php b/common/models/Settings.php index 09ef7d4..a04a03d 100755 --- a/common/models/Settings.php +++ b/common/models/Settings.php @@ -102,6 +102,7 @@ 'name', 'analytics_key', 'about', + 'logo' ], 'string', ], @@ -122,20 +123,6 @@ [ 'logo', ], - 'integer', - ], - [ - [ - 'logo', - ], - 'exist', - 'targetClass' => ImageManager::className(), - 'targetAttribute' => 'id', - ], - [ - [ - 'logo', - ], 'filter', 'filter' => function ($value) { if (empty( $value )) { diff --git a/frontend/controllers/ServiceController.php b/frontend/controllers/ServiceController.php new file mode 100644 index 0000000..ed311d8 --- /dev/null +++ b/frontend/controllers/ServiceController.php @@ -0,0 +1,44 @@ +findModel($id); + if ($model->parent_id == null){ + $others = Service::find()->where(['parent_id' => $model->id])->all(); + }else{ + $others = Service::find()->where(['parent_id' => $model->parent_id])->all(); + } + + return $this->render('view', [ + 'model' => $model, + 'others'=> $others + ]); + } + + public function findModel($id){ + $model = Service::find() + ->where(['id' => $id, 'status' => true]) + ->with(['language.alias', 'image', 'prices'])->one(); + if (empty($model)){ + throw new NotFoundHttpException('Model not found'); + } + return $model; + } + } \ No newline at end of file diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 1b97995..d08eb34 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -51,13 +51,6 @@ ] )->orderBy('sort') ->all(); - $logo = null; - if ($settings->logo) { - $logo_img = ImageManager::findOne($settings->logo); - if ($logo_img) { - $logo = $logo_img->getImagePathPrivate() ?? $logo; - } - } $this->registerMetaTag( [ @@ -96,14 +89,20 @@
@@ -167,6 +166,9 @@ $items[] = [ 'label' => \Yii::t('app', 'Цены'), 'url' => '#', + 'options' => [ + 'class' => 'active' + ] ]; $items[] = [ 'label' => \Yii::t('app', 'Пакетные предложения'), @@ -208,6 +210,9 @@ $itemsMobile[] = [ 'label' => \Yii::t('app', 'Цены'), 'url' => '#', + 'options' => [ + 'class' => 'active' + ] ]; $itemsMobile[] = [ 'label' => \Yii::t('app', 'Пакетные предложения'), -- libgit2 0.21.4