diff --git a/backend/controllers/AdminMenuController.php b/backend/controllers/AdminMenuController.php index 28fbba4..c8b6466 100644 --- a/backend/controllers/AdminMenuController.php +++ b/backend/controllers/AdminMenuController.php @@ -14,6 +14,8 @@ use yii\filters\VerbFilter; */ class AdminMenuController extends Controller { + public $layout = 'settings'; + public function behaviors() { return [ @@ -117,4 +119,5 @@ class AdminMenuController extends Controller throw new NotFoundHttpException('The requested page does not exist.'); } } + } diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php new file mode 100644 index 0000000..31de354 --- /dev/null +++ b/backend/controllers/SettingsController.php @@ -0,0 +1,38 @@ + [ + 'class' => 'yii\web\ErrorAction', + ], + ]; + } + + public function actionIndex() + { + return $this->render('index'); + } + +} diff --git a/backend/models/AdminMenu.php b/backend/models/AdminMenu.php index 9755591..316afd3 100644 --- a/backend/models/AdminMenu.php +++ b/backend/models/AdminMenu.php @@ -23,6 +23,8 @@ use Yii; */ class AdminMenu extends \yii\db\ActiveRecord { + + public $parentt; /** * @inheritdoc */ @@ -39,7 +41,7 @@ class AdminMenu extends \yii\db\ActiveRecord return [ [['parent_id', 'active', 'hide_min', 'sort'], 'integer'], [['name'], 'required'], - [['name', 'path', 'params'], 'string'] + [['name', 'path', 'params','parentt'], 'string'] ]; } @@ -57,6 +59,7 @@ class AdminMenu extends \yii\db\ActiveRecord 'name' => Yii::t('app', 'Name'), 'path' => Yii::t('app', 'Path'), 'params' => Yii::t('app', 'Params'), + 'parentt' => Yii::t('app', 'Parent item') ]; } @@ -98,17 +101,17 @@ class AdminMenu extends \yii\db\ActiveRecord $roots = self::find()->where(['parent_id' => NULL])->with(['adminMenus'])->all(); foreach($roots as $root) { if($root->adminMenus) { - $result[] = ['label' => $root->name, 'id' => $root->id, 'options' => ['class' => 'header']]; + $result[] = ['label' => Yii::t('app', $root->name), 'id' => $root->id, 'options' => ['class' => 'header']]; foreach($root->adminMenus as $submenu) { if($submenu->adminMenus) { $items = []; foreach($submenu->adminMenus as $item) { - $items[] = ['label' => $item->name, 'id' => $item->id, 'icon' => 'fa fa-circle-o', 'url' => array_merge([$item->path], \common\models\Tools::parseUrlParams($item->params))]; + $items[] = ['label' => Yii::t('app', $item->name), 'id' => $item->id, 'icon' => 'fa fa-circle-o', 'url' => array_merge([$item->path], \common\models\Tools::parseUrlParams($item->params))]; } - $result[] = ['label' => $submenu->name, 'id' => $submenu->id, 'icon' => 'fa fa-circle-o', 'url' => '#', 'items' => $items]; + $result[] = ['label' => Yii::t('app', $submenu->name), 'id' => $submenu->id, 'icon' => 'fa fa-circle-o', 'url' => '#', 'items' => $items]; unset($items); } else { - $result[] = ['label' => $submenu->name, 'id' => $submenu->id, 'icon' => 'fa fa-circle-o', 'url' => array_merge([$submenu->path], \common\models\Tools::parseUrlParams($submenu->params))]; + $result[] = ['label' => Yii::t('app', $submenu->name), 'id' => $submenu->id, 'icon' => 'fa fa-circle-o', 'url' => array_merge([$submenu->path], \common\models\Tools::parseUrlParams($submenu->params))]; } } } @@ -124,14 +127,26 @@ class AdminMenu extends \yii\db\ActiveRecord if($root->adminMenus) { $items = []; foreach($root->adminMenus as $submenu) { - $items[] = ['label' => $submenu->name, 'id' => $submenu->id]; + $items[] = ['label' => Yii::t('app', $submenu->name), 'id' => $submenu->id]; } - $result[] = ['label' => $root->name, 'id' => $root->id, 'items' => $items]; + $result[] = ['label' => Yii::t('app', $root->name), 'id' => $root->id, 'items' => $items]; unset($items); } else { - $result[] = ['label' => $root->name, 'id' => $root->id]; + $result[] = ['label' => Yii::t('app', $root->name), 'id' => $root->id]; } } return $result; } + + public function beforeSave($insert) + { + if (parent::beforeSave($insert)) { + if(!$this->parent_id) { + $this->parent_id = NULL; + } + return true; + } else { + return false; + } + } } diff --git a/backend/models/AdminMenuSearch.php b/backend/models/AdminMenuSearch.php index 5df3b63..534efda 100644 --- a/backend/models/AdminMenuSearch.php +++ b/backend/models/AdminMenuSearch.php @@ -12,6 +12,8 @@ use backend\models\AdminMenu; */ class AdminMenuSearch extends AdminMenu { + + /** * @inheritdoc */ @@ -19,7 +21,7 @@ class AdminMenuSearch extends AdminMenu { return [ [['id', 'parent_id', 'active', 'hide_min', 'sort'], 'integer'], - [['name', 'path', 'params'], 'safe'], + [['name', 'path', 'params','parentt'], 'safe'], ]; } @@ -45,6 +47,24 @@ class AdminMenuSearch extends AdminMenu $dataProvider = new ActiveDataProvider([ 'query' => $query, + 'pagination' => [ + 'pageSize' => 5 + ], + 'sort' => [ + 'attributes' => [ + 'id', + 'name', + 'path', + 'params', + 'active', + 'hide_min', + 'parentt' => [ + 'asc' => ['name' => SORT_ASC], + 'desc' => ['name' => SORT_DESC], + 'default' => SORT_DESC + ] + ] + ] ]); $this->load($params); @@ -60,12 +80,14 @@ class AdminMenuSearch extends AdminMenu 'parent_id' => $this->parent_id, 'active' => $this->active, 'hide_min' => $this->hide_min, - 'sort' => $this->sort, + 'sort' => $this->sort ]); + $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'path', $this->path]) - ->andFilterWhere(['like', 'params', $this->params]); + ->andFilterWhere(['like', 'params', $this->params]) + ->andFilterWhere(['in', 'parent_id', $this->find()->select(['id'])->andFilterWhere(['like', 'name', $this->parentt])->column()]); return $dataProvider; } diff --git a/backend/views/admin-menu/_form.php b/backend/views/admin-menu/_form.php index 1d96cd5..8bfa3fa 100644 --- a/backend/views/admin-menu/_form.php +++ b/backend/views/admin-menu/_form.php @@ -16,22 +16,6 @@ use yii\widgets\ActiveForm; = $form->field($model, 'name')->textInput() ?> -
= Yii::t('app', 'parent_id') ?>
-