@@ -35,27 +35,23 @@ public function __construct()
35
35
/**
36
36
* Get the roles for a group by the user ID
37
37
*
38
- * @param Int $userId
39
- * @param String $moduleName
38
+ * @param Int $userId
39
+ * @param false| String $moduleName
40
40
* @return Array
41
41
*/
42
- public function getGroupRolesByUser ($ userId , $ moduleName = false )
42
+ public function getGroupRolesByUser (int $ userId , false | string $ moduleName = false ): array
43
43
{
44
- $ query = $ this ->db ->table ("acl_group_roles agr, acl_account_groups aag " )->select ("agr.role_name, agr.module " )
45
- ->where ("aag.account_id " , $ userId )
46
- ->where ("aag.group_id = agr.group_id " );
44
+ $ query = $ this ->db ->table ('acl_group_roles agr ' )
45
+ ->select ('agr.role_name, agr.module ' )
46
+ ->join ('acl_account_groups aag ' , 'aag.group_id = agr.group_id ' , 'inner ' )
47
+ ->where ('aag.account_id ' , $ userId );
47
48
48
49
if ($ moduleName ) {
49
50
$ query ->where ("agr.module " , $ moduleName );
50
51
}
51
52
52
- $ query = $ query ->get ();
53
53
54
- if ($ query ->getNumRows ()) {
55
- return $ query ->getResultArray ();
56
- } else {
57
- return false ;
58
- }
54
+ return $ query ->get ()->getResultArray () ?? [];
59
55
}
60
56
61
57
/**
@@ -65,7 +61,7 @@ public function getGroupRolesByUser($userId, $moduleName = false)
65
61
* @param int $default_group
66
62
* @return array
67
63
*/
68
- public function getAccountRolesPermissions (int $ userId = 0 , int $ default_group = 1 )
64
+ public function getAccountRolesPermissions (int $ userId = 0 , int $ default_group = 1 ): array
69
65
{
70
66
// Groups: Initialize
71
67
$ groups = (array )$ this ->getGroupsByUser ($ userId );
@@ -122,51 +118,41 @@ public function getAccountRolesPermissions(int $userId = 0, int $default_group =
122
118
/**
123
119
* Get the account-specific permissions
124
120
*
125
- * @param Int $userId
121
+ * @param Int $userId
126
122
* @return Array
127
123
*/
128
- public function getAccountPermissions ($ userId )
124
+ public function getAccountPermissions (int $ userId ): array
129
125
{
130
126
$ query = $ this ->db ->table ('acl_account_permissions ' )->select ("account_id, permission_name, module, value " )->where ("account_id " , $ userId )->get ();
131
127
132
- if ($ query ->getNumRows () > 0 ) {
133
- return $ query ->getResultArray ();
134
- } else {
135
- return false ;
136
- }
128
+ return $ query ->getResultArray () ?? [];
137
129
}
138
130
139
131
/**
140
132
* Get the account-specific roles
141
133
*
142
- * @param Int $userId
143
- * @param String $module
134
+ * @param Int $userId
135
+ * @param false| String $module
144
136
* @return Array
145
137
*/
146
- public function getAccountRoles ($ userId , $ module = false )
138
+ public function getAccountRoles (int $ userId , false | string $ module = false ): array
147
139
{
148
140
$ builder = $ this ->db ->table ('acl_account_roles ' )->select ("role_name " )->where ("account_id " , $ userId );
149
141
150
142
if ($ module ) {
151
143
$ builder ->where ("module " , $ module );
152
144
}
153
145
154
- $ query = $ builder ->get ();
155
-
156
- if ($ query ->getNumRows () > 0 ) {
157
- return $ query ->getResultArray ();
158
- } else {
159
- return false ;
160
- }
146
+ return $ builder ->get ()->getResultArray () ?? [];
161
147
}
162
148
163
149
/**
164
150
* Get the groups of the given user
165
151
*
166
- * @param $accountId
152
+ * @param false|int $accountId
167
153
* @return Array
168
154
*/
169
- public function getGroupsByUser ($ accountId = false )
155
+ public function getGroupsByUser (false | int $ accountId = false ): array
170
156
{
171
157
if (!$ accountId ) {
172
158
$ accountId = $ this ->user ->getId ();
@@ -183,7 +169,7 @@ public function getGroupsByUser($accountId = false)
183
169
return $ query ->getResultArray ();
184
170
} else {
185
171
// No group found; default to player
186
- return array ( $ this ->getGroup ($ this ->config ->item ('default_player_group ' ))) ;
172
+ return [ $ this ->getGroup ($ this ->config ->item ('default_player_group ' ))] ;
187
173
}
188
174
}
189
175
@@ -192,65 +178,55 @@ public function getGroupsByUser($accountId = false)
192
178
*
193
179
* @return Array
194
180
*/
195
- public function getGroups ()
181
+ public function getGroups (): array
196
182
{
197
183
$ query = $ this ->db ->table ('acl_groups ag ' )->select ('ag.id, ag.priority, ag.name, ag.color, ag.description ' )->get ();
198
184
199
185
if ($ query ->getNumRows () > 0 ) {
200
186
return $ query ->getResultArray ();
201
187
} else {
202
- return false ;
188
+ return [] ;
203
189
}
204
190
}
205
191
206
192
/**
207
193
* Get member count of a group
208
194
*
209
- * @param Int $groupId
195
+ * @param Int $groupId
210
196
* @return Int
211
197
*/
212
- public function getGroupMemberCount ($ id )
198
+ public function getGroupMemberCount (int $ groupId ): int
213
199
{
214
- $ query = $ this ->db ->query ("SELECT COUNT(*) `memberCount` FROM acl_account_groups WHERE group_id=? " , array ($ id ));
215
-
216
- if ($ query ->getNumRows () > 0 ) {
217
- $ result = $ query ->getResultArray ();
218
-
219
- return $ result [0 ]['memberCount ' ];
220
- } else {
221
- return 0 ;
222
- }
200
+ return (int ) $ this ->db ->table ('acl_account_groups ' )->where ('group_id ' , $ groupId )->countAllResults ();
223
201
}
224
202
225
- /*
203
+ /**
226
204
* Get the members of a group
227
205
* @param Int $groupId
228
206
* @return Array
229
207
*/
230
- public function getGroupMembers ($ id )
208
+ public function getGroupMembers (int $ groupId ): array
231
209
{
232
- $ query = $ this ->db ->query ("SELECT account_id FROM acl_account_groups WHERE group_id=? " , array ($ id ));
233
-
234
- if ($ query ->getNumRows ()) {
235
- $ result = $ query ->getResultArray ();
236
-
237
- foreach ($ result as $ k => $ v ) {
238
- $ result [$ k ]['username ' ] = $ this ->user ->getUsername ($ v ['account_id ' ]);
239
- }
240
-
241
- return $ result ;
242
- } else {
243
- return false ;
210
+ $ result = $ this ->db ->table ('acl_account_groups ' )
211
+ ->select ('account_id ' )
212
+ ->where ('group_id ' , $ groupId )
213
+ ->get ()
214
+ ->getResultArray ();
215
+
216
+ foreach ($ result as &$ row ) {
217
+ $ row ['username ' ] = $ this ->user ->getUsername ($ row ['account_id ' ]);
244
218
}
219
+
220
+ return $ result ?: [];
245
221
}
246
222
247
223
/**
248
224
* Get the group by the given id.
249
225
*
250
- * @param $groupId
251
- * @return Array
226
+ * @param int $groupId
227
+ * @return false|array
252
228
*/
253
- public function getGroup ($ groupId )
229
+ public function getGroup (int $ groupId ): false | array
254
230
{
255
231
$ query = $ this ->db ->table ('acl_groups ' )->select ('id, priority, name, color, description ' )->where ('id ' , $ groupId )->get ();
256
232
@@ -266,10 +242,10 @@ public function getGroup($groupId)
266
242
/**
267
243
* Get the group by the given name
268
244
*
269
- * @param $groupName
245
+ * @param string $groupName
270
246
* @return Boolean
271
247
*/
272
- public function getGroupByName ($ groupName )
248
+ public function getGroupByName (string $ groupName )
273
249
{
274
250
$ query = $ this ->db ->table ('acl_groups ' )->select ('id, priority, name, color, description ' )->where ('name ' , $ groupName )->get ();
275
251
@@ -285,39 +261,34 @@ public function getGroupByName($groupName)
285
261
/**
286
262
* Check if a group has a specific role
287
263
*
288
- * @param Int $id
289
- * @param String $name
290
- * @param String $module
291
- * @return Boolean
264
+ * @param Int $groupId
265
+ * @param String $name
266
+ * @param String $module
267
+ * @return int
292
268
*/
293
- public function groupHasRole ($ groupId , $ name , $ module )
269
+ public function groupHasRole (int $ groupId , string $ name , string $ module ): int
294
270
{
295
- $ query = $ this ->db ->query ("SELECT COUNT(*) `total` FROM acl_group_roles WHERE role_name=? AND module=? AND group_id=? " , array ($ name , $ module , $ groupId ));
296
-
297
- if ($ query ->getNumRows ()) {
298
- $ result = $ query ->getResultArray ();
299
-
300
- return $ result [0 ]['total ' ];
301
- } else {
302
- return false ;
303
- }
271
+ return (int ) $ this ->db ->table ('acl_group_roles ' )
272
+ ->where ('role_name ' , $ name )
273
+ ->where ('module ' , $ module )
274
+ ->where ('group_id ' , $ groupId )
275
+ ->countAllResults ();
304
276
}
305
277
306
278
/**
307
279
* Get the database roles for a module
308
280
*
309
- * @param String $moduleName
281
+ * @param String $moduleName
282
+ * @param int $groupId
310
283
* @return Array
311
284
*/
312
- public function getRolesByModule ($ moduleName , $ groupId )
285
+ public function getRolesByModule (string $ moduleName , int $ groupId ): array
313
286
{
314
- $ query = $ this ->db ->query ("SELECT * FROM acl_group_roles WHERE module = ? AND group_id = ? " , [$ moduleName , $ groupId ]);
315
-
316
- if ($ query ->getNumRows () > 0 ) {
317
- return $ query ->getResultArray ();
318
- } else {
319
- return false ;
320
- }
287
+ return $ this ->db ->table ('acl_group_roles ' )
288
+ ->where ('module ' , $ moduleName )
289
+ ->where ('group_id ' , $ groupId )
290
+ ->get ()
291
+ ->getResultArray () ?? [];
321
292
}
322
293
323
294
/**
@@ -326,7 +297,7 @@ public function getRolesByModule($moduleName, $groupId)
326
297
* @param $data
327
298
* @return int
328
299
*/
329
- public function createGroup ($ data )
300
+ public function createGroup ($ data ): int
330
301
{
331
302
$ this ->db ->table ('acl_groups ' )->insert ($ data );
332
303
@@ -338,7 +309,7 @@ public function createGroup($data)
338
309
*
339
310
* @param Int $groupId
340
311
*/
341
- public function deleteGroup ($ groupId )
312
+ public function deleteGroup (int $ groupId ): void
342
313
{
343
314
$ this ->db ->table ('acl_groups ' )->delete (['id ' => $ groupId ]);
344
315
}
@@ -349,7 +320,7 @@ public function deleteGroup($groupId)
349
320
* @param Int $groupId
350
321
* @param Int $accountId
351
322
*/
352
- public function assignGroupToUser ($ groupId , $ accountId )
323
+ public function assignGroupToUser (int $ groupId , int $ accountId ): void
353
324
{
354
325
$ data = [
355
326
"account_id " => $ accountId ,
@@ -365,7 +336,7 @@ public function assignGroupToUser($groupId, $accountId)
365
336
* @param Int $groupId
366
337
* @param Int $accountId
367
338
*/
368
- public function removeGroupFromUser ($ groupId , $ accountId )
339
+ public function removeGroupFromUser (int $ groupId , int $ accountId ): void
369
340
{
370
341
$ data = [
371
342
"account_id " => $ accountId ,
@@ -380,7 +351,7 @@ public function removeGroupFromUser($groupId, $accountId)
380
351
*
381
352
* @param Int $accountId
382
353
*/
383
- public function removeGroupsFromUser ($ accountId )
354
+ public function removeGroupsFromUser (int $ accountId ): void
384
355
{
385
356
$ data = [
386
357
"account_id " => $ accountId
@@ -394,7 +365,7 @@ public function removeGroupsFromUser($accountId)
394
365
*
395
366
* @param Int $accountId
396
367
*/
397
- public function removePermissionsFromUser ($ accountId )
368
+ public function removePermissionsFromUser (int $ accountId ): void
398
369
{
399
370
$ data = [
400
371
"account_id " => $ accountId
@@ -406,15 +377,15 @@ public function removePermissionsFromUser($accountId)
406
377
/**
407
378
* Assign a permission to a user
408
379
*
409
- * @param $accontId
380
+ * @param int $accountId
410
381
* @param String $permissionName
411
382
* @param string $moduleName
412
383
* @param $value
413
384
*/
414
- public function assignPermissionToUser ($ accontId , $ permissionName , $ moduleName , $ value )
385
+ public function assignPermissionToUser (int $ accountId , string $ permissionName , string $ moduleName , $ value ): void
415
386
{
416
387
$ data = [
417
- "account_id " => $ accontId ,
388
+ "account_id " => $ accountId ,
418
389
"permission_name " => $ permissionName ,
419
390
"module " => $ moduleName ,
420
391
"value " => $ value
@@ -430,7 +401,7 @@ public function assignPermissionToUser($accontId, $permissionName, $moduleName,
430
401
* @param String $name
431
402
* @param String $module
432
403
*/
433
- public function addRoleToGroup ($ groupId , $ name , $ module )
404
+ public function addRoleToGroup (int $ groupId , string $ name , string $ module ): void
434
405
{
435
406
$ data = [
436
407
'group_id ' => $ groupId ,
@@ -448,7 +419,7 @@ public function addRoleToGroup($groupId, $name, $module)
448
419
* @param String $name
449
420
* @param String $module
450
421
*/
451
- public function deleteRoleFromGroup ($ groupId , $ name , $ module )
422
+ public function deleteRoleFromGroup (int $ groupId , string $ name , string $ module ): void
452
423
{
453
424
$ this ->db ->table ('acl_group_roles ' )->delete (['group_id ' => $ groupId , 'role_name ' => $ name , 'module ' => $ module ]);
454
425
}
@@ -459,7 +430,7 @@ public function deleteRoleFromGroup($groupId, $name, $module)
459
430
* @param Int $id
460
431
* @param Array $data
461
432
*/
462
- public function saveGroup ($ id , $ data )
433
+ public function saveGroup (int $ id , array $ data ): void
463
434
{
464
435
$ this ->db ->table ('acl_groups ' )->where ('id ' , $ id )->update ($ data );
465
436
}
@@ -469,7 +440,7 @@ public function saveGroup($id, $data)
469
440
*
470
441
* @param Int $groupId
471
442
*/
472
- public function deleteAllRoleFromGroup ($ groupId )
443
+ public function deleteAllRoleFromGroup (int $ groupId ): void
473
444
{
474
445
$ this ->db ->table ('acl_group_roles ' )->delete (['group_id ' => $ groupId ]);
475
446
}
0 commit comments