1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Actions; |
4
|
|
|
|
5
|
|
|
use Nwidart\Modules\Facades\Module; |
6
|
|
|
|
7
|
|
|
use App\Models\User; |
8
|
|
|
use App\Traits\AllowTrait; |
9
|
|
|
|
10
|
|
|
class BuildAdminMenu |
11
|
|
|
{ |
12
|
|
|
use AllowTrait; |
13
|
|
|
|
14
|
|
|
protected $user; |
15
|
|
|
|
16
|
|
|
public function __construct(User $user) |
17
|
|
|
{ |
18
|
|
|
$this->user = $user; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Get the Admin links that the user has permission to access |
23
|
|
|
*/ |
24
|
|
|
public function execute() |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
$userMenu = $this->buildUserMenu(); |
28
|
|
|
$equipMenu = $this->buildEquipmentMenu(); |
29
|
|
|
$customerMenu = $this->buildCustomerMenu(); |
30
|
|
|
$techTipMenu = $this->buildTechTipMenu(); |
31
|
|
|
$moduleMenu = $this->buildModuleMenus(); |
32
|
|
|
$settingsMenu = $this->buildSettingsMenu(); |
33
|
|
|
$maintMenu = $this->buildMaintenanceMenu(); |
34
|
|
|
|
35
|
|
|
return array_merge($userMenu, $equipMenu, $customerMenu, $techTipMenu, $moduleMenu, $settingsMenu, $maintMenu); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get the navigation links for Users |
40
|
|
|
*/ |
41
|
|
|
protected function buildUserMenu() |
42
|
|
|
{ |
43
|
|
|
$userBuild = []; |
44
|
|
|
if($this->checkPermission($this->user, 'Manage Users')) |
45
|
|
|
{ |
46
|
|
|
$userBuild = [ |
47
|
|
|
[ |
48
|
|
|
'name' => 'Create New User', |
49
|
|
|
'icon' => 'fas fa-user-plus', |
50
|
|
|
'link' => route('admin.user.create'), |
51
|
|
|
], |
52
|
|
|
[ |
53
|
|
|
'name' => 'Modify User', |
54
|
|
|
'icon' => 'fas fa-user-edit', |
55
|
|
|
'link' => route('admin.user.index'), |
56
|
|
|
], |
57
|
|
|
[ |
58
|
|
|
'name' => 'Show Deactivated Users', |
59
|
|
|
'icon' => 'fas fa-store-alt-slash', |
60
|
|
|
'link' => route('admin.deactivated-users'), |
61
|
|
|
], |
62
|
|
|
[ |
63
|
|
|
'name' => 'Password Policy', |
64
|
|
|
'icon' => 'fas fa-user-lock', |
65
|
|
|
'link' => route('admin.password-policy'), |
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$roleBuild = []; |
71
|
|
|
if($this->checkPermission($this->user, 'Manage Permissions')) |
72
|
|
|
{ |
73
|
|
|
$roleBuild = [[ |
74
|
|
|
'name' => 'User Roles and Permissions', |
75
|
|
|
'icon' => 'fas fa-users-cog', |
76
|
|
|
'link' => route('admin.user-roles.index'), |
77
|
|
|
]]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return ['Users' => array_merge($userBuild, $roleBuild)]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the navigation links for Equipment and Equipment Categories |
85
|
|
|
*/ |
86
|
|
|
protected function buildEquipmentMenu() |
87
|
|
|
{ |
88
|
|
|
$nav = []; |
89
|
|
|
|
90
|
|
|
if($this->checkPermission($this->user, 'Manage Equipment')) |
91
|
|
|
{ |
92
|
|
|
$nav = [ |
93
|
|
|
'Manage Equipment' => [ |
94
|
|
|
[ |
95
|
|
|
'name' => 'Equipment Types & Categories', |
96
|
|
|
'icon' => 'fas fa-cogs', |
97
|
|
|
'link' => route('equipment.index'), |
98
|
|
|
], |
99
|
|
|
[ |
100
|
|
|
'name' => 'Equipment Data Types (for customers)', |
101
|
|
|
'icon' => 'fas fa-database', |
102
|
|
|
'link' => route('data-types.index'), |
103
|
|
|
], |
104
|
|
|
], |
105
|
|
|
]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $nav; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the navigation links for customers |
113
|
|
|
*/ |
114
|
|
|
protected function buildCustomerMenu() |
115
|
|
|
{ |
116
|
|
|
$nav = []; |
117
|
|
|
|
118
|
|
|
if($this->checkPermission($this->user, 'Manage Customers')) |
119
|
|
|
{ |
120
|
|
|
$nav = [ |
121
|
|
|
'Manage Customers' => [ |
122
|
|
|
[ |
123
|
|
|
'name' => 'Change Customer ID Number', |
124
|
|
|
'icon' => 'fas fa-fingerprint', |
125
|
|
|
'link' => route('admin.cust.change-id.index'), |
126
|
|
|
], |
127
|
|
|
[ |
128
|
|
|
'name' => 'View Deactivated Customers', |
129
|
|
|
'icon' => 'fas fa-ban', |
130
|
|
|
'link' => route('admin.cust.show-deactivated'), |
131
|
|
|
], |
132
|
|
|
[ |
133
|
|
|
'name' => 'Customer Uploaded File Types', |
134
|
|
|
'icon' => 'fas fa-file-alt', |
135
|
|
|
'link' => route('admin.cust.file-types.index'), |
136
|
|
|
], |
137
|
|
|
], |
138
|
|
|
]; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $nav; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Build Navigation menu for Tech Tips |
146
|
|
|
*/ |
147
|
|
|
protected function buildTechTipMenu() |
148
|
|
|
{ |
149
|
|
|
$nav = []; |
150
|
|
|
|
151
|
|
|
if($this->checkPermission($this->user, 'Manage Tech Tips')) |
152
|
|
|
{ |
153
|
|
|
$nav = [ |
154
|
|
|
'Manage Tech Tips' => [ |
155
|
|
|
[ |
156
|
|
|
'name' => 'Tech Tip Types', |
157
|
|
|
'icon' => 'fas fa-file-alt', |
158
|
|
|
'link' => route('admin.tips.tip-types.index'), |
159
|
|
|
], |
160
|
|
|
[ |
161
|
|
|
'name' => 'View Deleted Tech Tips', |
162
|
|
|
'icon' => 'fas fa-ban', |
163
|
|
|
'link' => route('admin.tips.deleted'), |
164
|
|
|
], |
165
|
|
|
[ |
166
|
|
|
'name' => 'View Flagged Comments', |
167
|
|
|
'icon' => 'far fa-flag', |
168
|
|
|
'link' => route('tips.comments.index'), |
169
|
|
|
], |
170
|
|
|
], |
171
|
|
|
]; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $nav; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Build Admin menu's for all of the installed Modules |
179
|
|
|
*/ |
180
|
|
|
protected function buildModuleMenus() |
181
|
|
|
{ |
182
|
|
|
$nav = []; |
183
|
|
|
$modules = Module::allEnabled(); |
184
|
|
|
|
185
|
|
|
foreach($modules as $module) |
186
|
|
|
{ |
187
|
|
|
$name = $module->getLowerName(); |
188
|
|
|
$navData = config($name.'.admin_nav'); |
189
|
|
|
$modNav = []; |
190
|
|
|
|
191
|
|
|
if($navData) |
192
|
|
|
{ |
193
|
|
|
foreach($navData as $n) |
194
|
|
|
{ |
195
|
|
|
$modNav[] = [ |
196
|
|
|
'name' => $n['name'], |
197
|
|
|
'link' => route($n['route']), |
198
|
|
|
'icon' => $n['icon'], |
199
|
|
|
]; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
// Split Camel Case name into normal name |
204
|
|
|
$nav[implode(' ',preg_split('/(?=[A-Z])/', $module->getName()))] = $modNav; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return $nav; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Build navigation menu for Application Settings |
212
|
|
|
*/ |
213
|
|
|
protected function buildSettingsMenu() |
214
|
|
|
{ |
215
|
|
|
$nav = []; |
216
|
|
|
|
217
|
|
|
if($this->checkPermission($this->user, 'App Settings')) |
218
|
|
|
{ |
219
|
|
|
$nav = [ |
220
|
|
|
'Manage Application Settings' => [ |
221
|
|
|
[ |
222
|
|
|
'name' => 'Application Logo', |
223
|
|
|
'icon' => 'fas fa-image', |
224
|
|
|
'link' => route('admin.get-logo'), |
225
|
|
|
], |
226
|
|
|
[ |
227
|
|
|
'name' => 'Application Configuration', |
228
|
|
|
'icon' => 'fas fa-server', |
229
|
|
|
'link' => route('admin.get-config'), |
230
|
|
|
], |
231
|
|
|
[ |
232
|
|
|
'name' => 'Email Settings', |
233
|
|
|
'icon' => 'fas fa-envelope', |
234
|
|
|
'link' => route('admin.get-email'), |
235
|
|
|
], |
236
|
|
|
], |
237
|
|
|
]; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
return $nav; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Build navigation menu for Application Maintenance |
245
|
|
|
*/ |
246
|
|
|
protected function buildMaintenanceMenu() |
247
|
|
|
{ |
248
|
|
|
$nav = []; |
249
|
|
|
|
250
|
|
|
if($this->checkPermission($this->user, 'App Settings')) |
251
|
|
|
{ |
252
|
|
|
$nav = [ |
253
|
|
|
'Application Maintenance' => [ |
254
|
|
|
[ |
255
|
|
|
'name' => 'Application Logs', |
256
|
|
|
'icon' => 'fas fa-bug', |
257
|
|
|
'link' => route('admin.logs.index'), |
258
|
|
|
], |
259
|
|
|
// TODO - Finish me!!! |
260
|
|
|
// [ |
261
|
|
|
// 'name' => 'Application Backups', |
262
|
|
|
// 'icon' => '', |
263
|
|
|
// 'link' => '#', |
264
|
|
|
// ], |
265
|
|
|
// [ |
266
|
|
|
// 'name' => 'Application Updates', |
267
|
|
|
// 'icon' => '', |
268
|
|
|
// 'link' => '#', |
269
|
|
|
// ], |
270
|
|
|
], |
271
|
|
|
]; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
return $nav; |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|