1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Smartfaq; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Module: SmartFAQ |
7
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
8
|
|
|
* Credits: Mithrandir |
9
|
|
|
* Licence: GNU |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use XoopsModules\Smartfaq; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class PermissionHandler |
16
|
|
|
*/ |
17
|
|
|
class PermissionHandler extends \XoopsObjectHandler |
18
|
|
|
{ |
19
|
|
|
/* |
20
|
|
|
* Returns permissions for a certain type |
21
|
|
|
* |
22
|
|
|
* @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
23
|
|
|
* @param int $id id of the item (forum, topic or possibly post) to get permissions for |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $type |
30
|
|
|
* @param null $id |
|
|
|
|
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function getPermissions($type = 'category', $id = null) |
34
|
|
|
{ |
35
|
|
|
global $xoopsUser; |
36
|
|
|
static $permissions; |
37
|
|
|
|
38
|
|
|
if (!isset($permissions[$type]) || (null !== $id && !isset($permissions[$type][$id]))) { |
39
|
|
|
$smartModule = Smartfaq\Utility::getModuleInfo(); |
40
|
|
|
//Get group permissions handler |
41
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
42
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
43
|
|
|
//Get user's groups |
44
|
|
|
$groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
45
|
|
|
|
46
|
|
|
switch ($type) { |
47
|
|
|
case 'category': |
48
|
|
|
$gperm_name = 'category_read'; |
49
|
|
|
break; |
50
|
|
|
case 'item': |
51
|
|
|
$gperm_name = 'item_read'; |
52
|
|
|
break; |
53
|
|
|
case 'moderation': |
54
|
|
|
$gperm_name = 'category_moderation'; |
55
|
|
|
$groups = \is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
//Get all allowed item ids in this module and for this user's groups |
59
|
|
|
$userpermissions = $grouppermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
|
|
|
60
|
|
|
$permissions[$type] = $userpermissions; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
//Return the permission array |
64
|
|
|
return $permissions[$type] ?? []; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|