Test Failed
Push — dev6 ( fbdc57...e936d8 )
by Ron
17:43
created

BuildAdminMenu::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Actions;
4
5
use App\Models\User;
6
use App\Traits\AllowTrait;
7
8
class BuildAdminMenu
9
{
10
    use AllowTrait;
11
12
    protected $user;
13
14
    public function __construct(User $user)
15
    {
16
        $this->user = $user;
17
    }
18
19
    /**
20
     * Get the Admin links that the user has permission to access
21
     */
22
    public function execute()
23
    {
24
25
        $userMenu     = $this->buildUserMenu();
26
        $customerMenu = $this->buildCustomerMenu();
27
        $techTipMenu  = $this->buildTechTipMenu();
28
29
        return array_merge($userMenu, $customerMenu, $techTipMenu);
30
    }
31
32
    /**
33
     * Get the navigation links for Users
34
     */
35
    protected function buildUserMenu()
36
    {
37
        $userBuild = [];
38
        if($this->checkPermission($this->user, 'Manage Users'))
39
        {
40
            $userBuild = [
41
                [
42
                    'name' => 'Create New User',
43
                    'icon' => 'fas fa-user-plus',
44
                    'link' => route('admin.user.create'),
45
                ],
46
                [
47
                    'name' => 'Modify User',
48
                    'icon' => 'fas fa-user-edit',
49
                    'link' => route('admin.user.index'),
50
                ],
51
                [
52
                    'name' => 'Show Deactivated Users',
53
                    'icon' => 'fas fa-store-alt-slash',
54
                    'link' => route('admin.deactivated-users'),
55
                ],
56
            ];
57
        }
58
59
        $roleBuild = [];
60
        if($this->checkPermission($this->user, 'Manage Permissions'))
61
        {
62
            $roleBuild = [[
63
                'name' => 'User Roles and Permissions',
64
                'icon' => 'fas fa-users-cog',
65
                'link' => route('admin.user-roles.index'),
66
            ]];
67
        }
68
69
        return ['Users' => array_merge($userBuild, $roleBuild)];
70
    }
71
72
73
    /**
74
     * Get the navigation links for customers
75
     */
76
    protected function buildCustomerMenu()
77
    {
78
        $nav = [];
79
80
        if($this->checkPermission($this->user, 'Manage Customers'))
81
        {
82
            $nav = [
83
                'Manage Customers' => [
84
                    [
85
                        'name' => 'Change Customer ID Number',
86
                        'icon' => 'fas fa-fingerprint',
87
                        'link' => route('admin.cust.change-id.index'),
88
                    ],
89
                    [
90
                        'name' => 'View Deactivated Customers',
91
                        'icon' => 'fas fa-ban',
92
                        'link' => route('admin.cust.show-deactivated'),
93
                    ],
94
                    [
95
                        'name' => 'Customer Uploaded File Types',
96
                        'icon' => 'fas fa-file-alt',
97
                        'link' => route('admin.cust.file-types.index'),
98
                    ],
99
                ],
100
            ];
101
        }
102
103
        return $nav;
104
    }
105
106
    /**
107
     * Build Navigation menu for Tech Tips
108
     */
109
    protected function buildTechTipMenu()
110
    {
111
        $nav = [];
112
113
        if($this->checkPermission($this->user, 'Manage Tech Tips'))
114
        {
115
            $nav = [
116
                'Manage Tech Tips' => [
117
                    [
118
                        'name' => 'Tech Tip Types',
119
                        'icon' => 'fas fa-file-alt',
120
                        'link' => route('admin.tips.tip-types.index'),
121
                    ],
122
                    [
123
                        'name' => 'View Deactivated Tech Tips',
124
                        'icon' => 'fas fa-ban',
125
                        'link' => '#',
126
                    ],
127
                    [
128
                        'name' => 'View Flagged Comments',
129
                        'icon' => 'far fa-flag',
130
                        'link' => '#',
131
                    ],
132
                ],
133
            ];
134
        }
135
136
        return $nav;
137
    }
138
}
139