forked from mdmsoft/yii2-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
92 lines (80 loc) · 2.27 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace mdm\admin;
use Yii;
use mdm\admin\components\AccessControl;
use yii\helpers\ArrayHelper;
use yii\helpers\Inflector;
/**
* Description of Module
*
* @author MDMunir
*/
class Module extends \yii\base\Module
{
public $defaultRoute = 'assigment';
/**
*
* @var array
*/
public $items = [];
/**
*
* @var array
*/
public $menus;
/**
*
* @var string
*/
public $mainLayout = '@mdm/admin/views/layouts/main.php';
protected function getCoreItems()
{
$config = components\Configs::instance();
return [
'assigment' => [
'class' => 'mdm\admin\items\AssigmentController'
],
'role' => [
'class' => 'mdm\admin\items\RoleController'
],
'permission' => [
'class' => 'mdm\admin\items\PermissionController'
],
'route' => [
'class' => 'mdm\admin\items\RouteController'
],
'rule' => [
'class' => 'mdm\admin\items\RuleController'
],
'menu' => [
'class' => 'mdm\admin\items\MenuController',
'visible' => $config->db !== null && $config->db->schema->getTableSchema('{{%menu}}') !== null
],
];
}
private function normalizeController()
{
$controllers = [];
$this->menus = [];
$mid = '/' . $this->getUniqueId() . '/';
$items = ArrayHelper::merge($this->getCoreItems(), $this->items);
foreach ($items as $id => $config) {
$label = Inflector::humanize($id);
$visible = true;
if (is_array($config)) {
$label = ArrayHelper::remove($config, 'label', $label);
$visible = ArrayHelper::remove($config, 'visible', true);
}
if ($visible) {
$this->menus[] = ['label' => $label, 'url' => [$mid . $id]];
$controllers[$id] = $config;
}
}
$this->controllerMap = ArrayHelper::merge($this->controllerMap, $controllers);
}
public function createController($route)
{
$this->normalizeController();
return parent::createController($route);
}
}