Completed
Push — master ( dda193...70e6ba )
by wen
23:11
created

PermissionsTableSeeder::storePermission()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
1
<?php
2
3
use Illuminate\Database\Seeder;
4
5
class PermissionsTableSeeder extends Seeder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    public function run()
8
    {
9
        //$this->dashboard();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
10
        //$this->system();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
11
        //$this->users();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
12
13
        $this->storePermission('view_admin', '访问后台');
14
        $this->storePermission('manage_log', '管理操作日志');
15
        $this->storePermission('view_user', '查看用户');
16
        $this->storePermission('create_user', '创建用户');
17
        $this->storePermission('update_user', '编辑用户');
18
        $this->storePermission('delete_user', '删除用户');
19
    }
20
21
    private function dashboard()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
22
    {
23
        $dashboard = $this->insertPerm('admin.dashboard', '控制台', 0, 1,
24
            'fa-dashboard');
25
        $this->insertPerm('admin.menu', '左侧菜单数据', $dashboard->id);
26
        $this->insertPerm('admin.permissions', 'Ajax获取用户权限', $dashboard->id);
27
    }
28
29
    private function system()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
30
    {
31
        $system = $this->insertPerm('#', '系统管理', 0, 1, 'fa-edit');
32
33
        $log = $this->insertPerm('admin.system.log', '操作日志', $system->id, 1);
34
        $this->insertPerm('admin.system.log.list', 'Ajax获取操作日志列表', $log->id);
35
36
        $menu = $this->insertPerm('admin.system.menu', '后台菜单', $system->id, 1,
37
            'fa-link');
38
        $this->insertPerm('admin.system.menu.list', '菜单列表数据', $menu->id);
39
        $this->insertPerm('admin.system.menu.store', '保存菜单', $menu->id);
40
        $this->insertPerm('admin.system.menu.update', '更新菜单', $menu->id);
41
        $this->insertPerm('admin.system.menu.destroy', '删除菜单', $menu->id);
42
        $this->insertPerm('admin.system.menu.batch.destroy', '批量删除菜单',
43
            $menu->id);
44
    }
45
46
    private function users()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
47
    {
48
        $users = $this->insertPerm('#', '用户管理', 0, 1, 'fa-users');
49
50
        $user = $this->insertPerm('admin.users.user', '用户', $users->id, 1,
51
            'fa-user');
52
        $this->insertPerm('admin.users.user.list', 'Ajax获取用户列表数据', $user->id);
53
        $this->insertPerm('admin.users.user.store', '保存用户', $user->id);
54
55
        $updateUser = $this->insertPerm('admin.users.user.update', '更新用户',
56
            $user->id);
57
        $this->insertPerm('admin.users.user.role.all', 'Ajax获取所有角色数据',
58
            $updateUser->id, 0, '', '用于创建和编辑用户');
59
60
        $this->insertPerm('admin.users.user.destroy', '删除管理员', $user->id);
61
62
        $role = $this->insertPerm('admin.users.role', '角色', $users->id, 1,
63
            'fa-user-plus');
64
        $this->insertPerm('admin.users.role.list', '角色列表数据', $role->id);
65
66
67
        $createRole = $this->insertPerm('admin.users.role.create', '创建角色',
68
            $role->id);
69
        $this->insertPerm('admin.users.role.store', '保存角色', $createRole->id);
70
71
        $roleEdit = $this->insertPerm('admin.users.role.edit', '编辑角色',
72
            $role->id);
73
        $this->insertPerm('admin.users.role.get', 'Ajax获取角色信息', $roleEdit->id,
74
            0,
75
            '', '用于编辑角色时获取数据');
76
        $this->insertPerm('admin.users.role.perms.list', 'Ajax获取权限列表',
77
            $roleEdit->id, 0, '', '用于编辑角色时获取数据');
78
        $this->insertPerm('admin.users.role.update', '更新角色', $roleEdit->id);
79
80
        $this->insertPerm('admin.users.role.destroy', '删除角色', $role->id);
81
        $this->insertPerm('admin.users.role.batch.destroy', '批量删除角色',
82
            $role->id);
83
    }
84
85
    private function insertPerm(
86
        $name,
87
        $displayName,
88
        $pid,
89
        $isMenu = 0,
90
        $icon = '',
91
        $description = ''
92
    ) {
93
        $permissionModelName = config('admin.permission');
94
        $permission          = new $permissionModelName();
95
96
        $permission->pid          = $pid;
97
        $permission->icon         = $icon;
98
        $permission->display_name = $displayName;
99
        $permission->name         = $name;
100
        $permission->is_menu      = $isMenu;
101
        $permission->sort         = 1;
102
        $permission->description  = $description;
103
        $permission->save();
104
105
        return $permission;
106
    }
107
108
    private function storePermission($name, $displayName, $description = '')
109
    {
110
        $permissionModelName = config('admin.permission');
111
        $permission          = new $permissionModelName();
112
113
        $permission->display_name = $displayName;
114
        $permission->name         = $name;
115
        $permission->description  = $description;
116
        $permission->save();
117
118
        return $permission;
119
    }
120
}
121