diff --git a/backend/bootstrap/SetUp.php b/backend/bootstrap/SetUp.php index 7d75215..8b211aa 100644 --- a/backend/bootstrap/SetUp.php +++ b/backend/bootstrap/SetUp.php @@ -16,45 +16,59 @@ class SetUp implements BootstrapInterface $container = \Yii::$container; // init presets - $presetsPath = \Yii::getAlias('@core/components/ckeditor/presets'); - // basic - $app->params['ckeditor']['basic']['toolbar'] = require $presetsPath . '/basic/toolbar.php'; - $app->params['ckeditor']['basic']['plugins'] = require $presetsPath . '/basic/plugins.php'; - // editor - $app->params['ckeditor']['editor']['toolbar'] = require $presetsPath . '/editor/toolbar.php'; - $app->params['ckeditor']['editor']['plugins'] = require $presetsPath . '/editor/plugins.php'; - // debeloper - $app->params['ckeditor']['developer']['toolbar'] = require $presetsPath . '/developer/toolbar.php'; - $app->params['ckeditor']['developer']['plugins'] = require $presetsPath . '/developer/plugins.php'; - - // set preset example - /*$form->field($model, 'content')->widget(CKEditor::class, [ - 'editorOptions' => \zertex\elfinder\ElFinder::ckeditorOptions('elfinder',[ - 'toolbar' => Yii::$app->params['ckeditor']['editor']['toolbar'], - 'extraPlugins' => Yii::$app->params['ckeditor']['editor']['plugins'], - ]) - ])*/ + $presetsPath = \Yii::getAlias('@core/components/ckeditor/presets'); + // basic + $app->params['ckeditor']['basic']['toolbar'] = require $presetsPath . '/basic/toolbar.php'; + $app->params['ckeditor']['basic']['plugins'] = require $presetsPath . '/basic/plugins.php'; + // editor + $app->params['ckeditor']['editor']['toolbar'] = require $presetsPath . '/editor/toolbar.php'; + $app->params['ckeditor']['editor']['plugins'] = require $presetsPath . '/editor/plugins.php'; + // debeloper + $app->params['ckeditor']['developer']['toolbar'] = require $presetsPath . '/developer/toolbar.php'; + $app->params['ckeditor']['developer']['plugins'] = require $presetsPath . '/developer/plugins.php'; + + // set preset example + /*$form->field($model, 'content')->widget(CKEditor::class, [ + 'editorOptions' => \zertex\elfinder\ElFinder::ckeditorOptions('elfinder',[ + 'toolbar' => Yii::$app->params['ckeditor']['editor']['toolbar'], + 'extraPlugins' => Yii::$app->params['ckeditor']['editor']['plugins'], + ]) + ])*/ $container->set(CKEditor::class, [ 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ - 'toolbar' => $app->params['ckeditor']['editor']['toolbar'], - 'extraPlugins' => $app->params['ckeditor']['editor']['plugins'], - 'language' => $app->language, + 'toolbar' => $app->params['ckeditor']['editor']['toolbar'], + 'extraPlugins' => $app->params['ckeditor']['editor']['plugins'], + 'language' => $app->language, ]), ]); // load settings - $settings = ArrayHelper::map(Settings::find()->andWhere(['active' => 1])->all(), 'key', 'value', 'section'); - $app->params['settings'] = $settings; - - // Connect backend modules - - // Add finish UrlRules - $app->getUrlManager()->addRules([ - '<_c:[\w\-]+>' => '<_c>/index', - '<_c:[\w\-]+>/' => '<_c>/view', - '<_c:[\w\-]+>/<_a:[\w-]+>' => '<_c>/<_a>', - '<_c:[\w\-]+>//<_a:[\w\-]+>' => '<_c>/<_a>', - ]); + $settings = Settings::find()->with('translations')->andWhere(['active' => 1])->all(); + //$settings = Settings::find()->andWhere(['active' => 1])->all(); + //$settings_array = []; + /*foreach ($settings as $setting) { + if (!isset($settings_array[$setting->section])) { + $settings_array[$setting->section] = []; + } + //$settings_array[$setting->section][$setting->key] = $setting->translation->value; + }*/ + + $settings_array = $settings ? ArrayHelper::map($settings, 'key', function ($el) { + return $el->translation->value; + }, 'section') : []; + + //$settings = ArrayHelper::map(Settings::find()->andWhere(['active' => 1])->all(), 'key', 'value', 'section'); + $app->params['settings'] = $settings_array; + + // Connect backend modules + + // Add finish UrlRules + $app->getUrlManager()->addRules([ + '<_c:[\w\-]+>' => '<_c>/index', + '<_c:[\w\-]+>/' => '<_c>/view', + '<_c:[\w\-]+>/<_a:[\w-]+>' => '<_c>/<_a>', + '<_c:[\w\-]+>//<_a:[\w\-]+>' => '<_c>/<_a>', + ]); } -} \ No newline at end of file +} diff --git a/backend/controllers/settings/ListController.php b/backend/controllers/settings/ListController.php index 4c454fa..7e1a5fe 100644 --- a/backend/controllers/settings/ListController.php +++ b/backend/controllers/settings/ListController.php @@ -64,9 +64,10 @@ class ListController extends Controller ]; } - public function actionIndex() + public function actionIndex($section = 'site') { $searchModel = new SettingsSearch(); + $searchModel->section = $section; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render( @@ -74,16 +75,17 @@ class ListController extends Controller [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, + 'section' => $section, ] ); } - public function actionView($id) + public function actionView($section, $key) { return $this->render( 'view', [ - 'model' => $this->findModel($id), + 'model' => $this->findModel($section, $key), ] ); } @@ -95,7 +97,7 @@ class ListController extends Controller try { $settings = $this->_service->create($form); - return $this->redirect(['view', 'id' => $settings->id]); + return $this->redirect(['view', 'section' => $settings->section, 'key' => $settings->key]); } catch (\DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); @@ -112,16 +114,16 @@ class ListController extends Controller ); } - public function actionUpdate($id) + public function actionUpdate($section, $key) { - $settings = $this->findModel($id); + $settings = $this->findModel($section, $key); $form = new SettingsForm($settings); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_service->edit($settings->id, $form); + $this->_service->edit($settings->section, $settings->key, $form); - return $this->redirect(['view', 'id' => $settings->id]); + return $this->redirect(['view', 'section' => $settings->section, 'key' => $settings->key]); } catch (\DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); @@ -137,19 +139,19 @@ class ListController extends Controller ); } - public function actionDelete($id) + public function actionDelete($section, $key) { - $this->_service->remove($id); + $this->_service->remove($section, $key); return $this->redirect(['index']); } - protected function findModel($id) + protected function findModel($section, $key) { - if (($model = Settings::findOne($id)) !== null) { + if (($model = Settings::find()->andWhere(['section' => $section])->andWhere(['key' => $key])->one()) !== null) { return $model; } else { - throw new NotFoundHttpException('The requested page does not exist.'); + throw new NotFoundHttpException('The requested setting does not exist.'); } } } diff --git a/backend/forms/SettingsSearch.php b/backend/forms/SettingsSearch.php index 42f101f..c552768 100644 --- a/backend/forms/SettingsSearch.php +++ b/backend/forms/SettingsSearch.php @@ -6,61 +6,68 @@ namespace backend\forms; - use core\entities\Settings; use yii\base\Model; use yii\data\ActiveDataProvider; class SettingsSearch extends Settings { - public $id; - public $type; - public $section; - public $key; - public $value; - public $active; + public $id; + public $type; + public $section; + public $key; + public $value; + public $active; + + public function rules() + { + return [ + [['id'], 'integer'], + [['active'], 'boolean'], + [['type', 'section', 'key', 'value'], 'safe'], + ]; + } + + /** + * @return array + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } - public function rules() - { - return [ - [['id'], 'integer'], - [['active'], 'boolean'], - [['type', 'section', 'key', 'value'], 'safe'], - ]; - } - /** - * @return array - */ - public function scenarios() - { - // bypass scenarios() implementation in the parent class - return Model::scenarios(); - } - /** - * @param $params - * @return ActiveDataProvider - */ - public function search($params) - { - $query = Settings::find(); - $dataProvider = new ActiveDataProvider( - [ - 'query' => $query, - ] - ); - if (!($this->load($params) && $this->validate())) { - return $dataProvider; - } - $query->andFilterWhere( - [ - 'id' => $this->id, - 'active' => $this->active, - 'section' => $this->section, - ] - ); - $query->andFilterWhere(['like', 'key', $this->key]) - ->andFilterWhere(['like', 'value', $this->value]); - return $dataProvider; - } + /** + * @param $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Settings::find(); + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + ] + ); + if (!($this->load($params) && $this->validate())) { + $query->andFilterWhere( + [ + 'section' => $this->section, + ] + ); + return $dataProvider; + } + $query->andFilterWhere( + [ + 'id' => $this->id, + 'active' => $this->active, + 'section' => $this->section, + ] + ); + $query->andFilterWhere(['like', 'key', $this->key]) + ->andFilterWhere(['like', 'value', $this->value]); -} \ No newline at end of file + return $dataProvider; + } +} diff --git a/backend/messages/ru/main.php b/backend/messages/ru/main.php index 08dd5d0..48b4d07 100644 --- a/backend/messages/ru/main.php +++ b/backend/messages/ru/main.php @@ -1,42 +1,44 @@ 'Меню', - 'Title' => 'Заголовок', - 'Description' => 'Описание', - 'Keywords' => 'Ключевые слова', - 'Sign out' => 'Выход', - 'Profile' => 'Профиль', - 'Error' => 'Ошибка', - 'Return to back or login page please.' => 'Вернитесь назад или авторизуйтесь снова.', - '{attribute} "{value}" already exists for this section.' => '{attribute} "{value}" уже есть в этом разделе.', - '"{attribute}" must be a valid JSON object' => '"{attribute}" должен быть в формате Json', - 'Please select correct type' => 'Укажите правильный тип', - 'Settings' => 'Настройки', - 'Type' => 'Тип', - 'Section' => 'Раздел', - 'Key' => 'Ключ', - 'Value' => 'Значение', - 'Active' => 'Активная', - 'Created At' => 'Создано', - 'Updated At' => 'Обновлено', - 'On' => 'Включить', - 'Off' => 'Выключить', - 'Updating Setting' => 'Редактирование параметра', - 'Editing' => 'Редактирование', - 'Change at your own risk' => 'Редактируйте на свой страх и риск', - 'Online' => 'В сети', - 'Search results' => 'Поиск', - 'Search...' => 'Поиск...', - 'Name' => 'Название', - 'Title attribute' => 'Атрибут тега Title', - 'Url' => 'Ссылка', - 'Sign in to start your session' => 'Вход в панель управления', - 'You have {count} notifications' => 'Новых уведомлений: {count}', - 'Modules' => 'Модули', - 'Find modules' => 'Поиск модулей', - 'Enable' => 'Включить', - 'Disable' => 'Отключить', - 'Settings List' => 'Все настройки', - 'Create Setting' => 'Новый параметр', - 'Interface Language' => 'Язык интерфейса', -]; \ No newline at end of file + 'Menu' => 'Меню', + 'Title' => 'Заголовок', + 'Description' => 'Описание', + 'Keywords' => 'Ключевые слова', + 'Sign out' => 'Выход', + 'Profile' => 'Профиль', + 'Error' => 'Ошибка', + 'Return to back or login page please.' => 'Вернитесь назад или авторизуйтесь снова.', + '{attribute} "{value}" already exists for this section.' => '{attribute} "{value}" уже есть в этом разделе.', + '"{attribute}" must be a valid JSON object' => '"{attribute}" должен быть в формате Json', + 'Please select correct type' => 'Укажите правильный тип', + 'Settings' => 'Настройки', + 'Type' => 'Тип', + 'Section' => 'Раздел', + 'Key' => 'Ключ', + 'Value' => 'Значение', + 'Active' => 'Активная', + 'Created At' => 'Создано', + 'Updated At' => 'Обновлено', + 'On' => 'Включить', + 'Off' => 'Выключить', + 'Updating Setting' => 'Редактирование параметра', + 'Editing' => 'Редактирование', + 'Change at your own risk' => 'Редактируйте на свой страх и риск', + 'Online' => 'В сети', + 'Search results' => 'Поиск', + 'Search...' => 'Поиск...', + 'Name' => 'Название', + 'Title attribute' => 'Атрибут тега Title', + 'Url' => 'Ссылка', + 'Sign in to start your session' => 'Вход в панель управления', + 'You have {count} notifications' => 'Новых уведомлений: {count}', + 'Modules' => 'Модули', + 'Find modules' => 'Поиск модулей', + 'Enable' => 'Включить', + 'Disable' => 'Отключить', + 'Settings List' => 'Все настройки', + 'Create Setting' => 'Новый параметр', + 'Interface Language' => 'Язык интерфейса', + 'design' => 'Оформление', + 'site' => 'Сайт', +]; diff --git a/backend/views/layouts/header.php b/backend/views/layouts/header.php index 4d3113c..1b02af1 100644 --- a/backend/views/layouts/header.php +++ b/backend/views/layouts/header.php @@ -1,6 +1,6 @@ - '.(isset(Yii::$app->params['settings']['site']['short_name']) ? Yii::$app->params['settings']['site']['short_name'] : 'APP').'' . (isset(Yii::$app->params['settings']['site']['name']) ? Yii::$app->params['settings']['site']['name'] : Yii::$app->name) . '', Yii::$app->homeUrl, ['class' => 'logo']) ?> + ' . (isset(Yii::$app->params['settings']['site']['short_name']) ? Yii::$app->params['settings']['site']['short_name'] : 'APP') . '' . (isset(Yii::$app->params['settings']['site']['name']) ? Yii::$app->params['settings']['site']['name'] : Yii::$app->name) . '', Yii::$app->homeUrl, ['class' => 'logo']) ?>