ILIAS  release_8 Revision v8.24
ilClaimingPermissionHelper Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilClaimingPermissionHelper:
+ Collaboration diagram for ilClaimingPermissionHelper:

Public Member Functions

 reset ()
 Reset (internal caches) More...
 
 hasPermission (int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
 Check permission. More...
 
 hasPermissions (int $a_context_type, string $a_context_id, array $a_action_ids)
 Check permissions. More...
 
 getAllowedObjectTypes ()
 

Static Public Member Functions

static getInstance (int $a_user_id, int $a_ref_id)
 

Protected Member Functions

 __construct (int $a_user_id, int $a_ref_id)
 
 setUserId (int $a_value)
 
 getUserId ()
 
 setRefId (int $a_value)
 
 getRefId ()
 
 readContextIds (int $a_context_type)
 Get all context ids for context type (from DB, is cached) More...
 
 buildPermissionMap ()
 Build map of context and actions. More...
 
 isValidContextAndAction (int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
 Check if given combination of context and action is valid. More...
 
 getValidContextIds (int $a_context_type)
 Get context ids for context type (uses cache) More...
 
 checkPermission (int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
 Check permission (helper: rbac, plugins) More...
 
 checkRBAC ()
 Check permission against RBAC. More...
 
 getActivePlugins ()
 Get active plugins (for current slot) More...
 
 checkPlugins (int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
 Check permission against plugins. More...
 

Protected Attributes

int $user_id = 0
 
int $ref_id = 0
 
array $map = []
 
array $context_ids = []
 
array $plugins = null
 

Static Protected Attributes

static array $instances = []
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Claiming permission helper base class

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 25 of file class.ilClaimingPermissionHelper.php.

Constructor & Destructor Documentation

◆ __construct()

ilClaimingPermissionHelper::__construct ( int  $a_user_id,
int  $a_ref_id 
)
protected

Definition at line 35 of file class.ilClaimingPermissionHelper.php.

36 {
37 $this->setUserId($a_user_id);
38 $this->setRefId($a_ref_id);
39 $this->map = $this->buildPermissionMap();
40 $this->reset();
41 }
buildPermissionMap()
Build map of context and actions.

References buildPermissionMap(), reset(), setRefId(), and setUserId().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildPermissionMap()

ilClaimingPermissionHelper::buildPermissionMap ( )
abstractprotected

Build map of context and actions.

Reimplemented in ilAdvancedMDPermissionHelper, and ilUDFPermissionHelper.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ checkPermission()

ilClaimingPermissionHelper::checkPermission ( int  $a_context_type,
string  $a_context_id,
int  $a_action_id,
?int  $a_action_sub_id = null 
)
protected

Check permission (helper: rbac, plugins)

Reimplemented in ilAdvancedMDPermissionHelper.

Definition at line 188 of file class.ilClaimingPermissionHelper.php.

193 : bool {
194 return ($this->checkRBAC() &&
195 $this->checkPlugins($a_context_type, (string) $a_context_id, $a_action_id, $a_action_sub_id));
196 }
checkRBAC()
Check permission against RBAC.
checkPlugins(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission against plugins.

◆ checkPlugins()

ilClaimingPermissionHelper::checkPlugins ( int  $a_context_type,
string  $a_context_id,
int  $a_action_id,
?int  $a_action_sub_id = null 
)
protected

Check permission against plugins.

Definition at line 218 of file class.ilClaimingPermissionHelper.php.

223 : bool {
224 $valid = true;
225
226 if (!is_array($this->plugins)) {
227 $this->plugins = iterator_to_array($this->getActivePlugins());
228 }
229
230 foreach ($this->plugins as $plugin) {
231 $a_action_sub_id = is_null($a_action_sub_id)
233 : $a_action_sub_id;
234 if (!$plugin->checkPermission($this->getUserId(), $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
235 $valid = false;
236 break;
237 }
238 }
239
240 return $valid;
241 }
getActivePlugins()
Get active plugins (for current slot)
$valid

◆ checkRBAC()

ilClaimingPermissionHelper::checkRBAC ( )
protected

Check permission against RBAC.

Definition at line 201 of file class.ilClaimingPermissionHelper.php.

201 : bool
202 {
203 global $DIC;
204 $ilAccess = $DIC->access();
205
206 // we are currently only supporting write operations
207 return $ilAccess->checkAccessOfUser($this->getUserId(), "write", "", $this->getRefId());
208 }
global $DIC
Definition: feed.php:28

References $DIC.

◆ getActivePlugins()

ilClaimingPermissionHelper::getActivePlugins ( )
abstractprotected

Get active plugins (for current slot)

Reimplemented in ilAdvancedMDPermissionHelper, and ilUDFPermissionHelper.

◆ getAllowedObjectTypes()

ilClaimingPermissionHelper::getAllowedObjectTypes ( )
Returns
array of object type strings

Definition at line 246 of file class.ilClaimingPermissionHelper.php.

246 : array
247 {
248 $accepted_types = ['cat','crs','sess','grp','iass', 'exc'];
249
250 $obj_def = new ilObjectDefinition();
251 $adv_md_types = $obj_def->getAdvancedMetaDataTypes();
252
253 $valid_accepted_types = array();
254 foreach ($adv_md_types as $value) {
255 if (in_array($value['obj_type'], $accepted_types) || in_array($value['sub_type'], $accepted_types)) {
256 array_push($valid_accepted_types, $value['obj_type']);
257 }
258 }
259
260 return $valid_accepted_types;
261 }
parses the objects.xml it handles the xml-description of all ilias objects

Referenced by ilAdvancedMDPermissionHelper\readContextIds().

+ Here is the caller graph for this function:

◆ getInstance()

static ilClaimingPermissionHelper::getInstance ( int  $a_user_id,
int  $a_ref_id 
)
static

Definition at line 43 of file class.ilClaimingPermissionHelper.php.

43 : self
44 {
45 if (!isset(self::$instances[$a_user_id][$a_ref_id])) {
46 self::$instances[$a_user_id][$a_ref_id] = new static($a_user_id, $a_ref_id);
47 }
48 return self::$instances[$a_user_id][$a_ref_id];
49 }

Referenced by ilAdvancedMDSettingsGUI\__construct(), and ilCustomUserFieldsGUI\__construct().

+ Here is the caller graph for this function:

◆ getRefId()

ilClaimingPermissionHelper::getRefId ( )
protected

Definition at line 77 of file class.ilClaimingPermissionHelper.php.

References $ref_id.

Referenced by ilUDFPermissionHelper\readContextIds().

+ Here is the caller graph for this function:

◆ getUserId()

ilClaimingPermissionHelper::getUserId ( )
protected

Definition at line 67 of file class.ilClaimingPermissionHelper.php.

References $user_id.

◆ getValidContextIds()

ilClaimingPermissionHelper::getValidContextIds ( int  $a_context_type)
protected

Get context ids for context type (uses cache)

See also
self::readContextIds()

Definition at line 140 of file class.ilClaimingPermissionHelper.php.

140 : array
141 {
142 if (!array_key_exists($a_context_type, $this->context_ids)) {
143 $this->context_ids[$a_context_type] = $this->readContextIds($a_context_type);
144 }
145 return (array) $this->context_ids[$a_context_type];
146 }
readContextIds(int $a_context_type)
Get all context ids for context type (from DB, is cached)

◆ hasPermission()

ilClaimingPermissionHelper::hasPermission ( int  $a_context_type,
string  $a_context_id,
int  $a_action_id,
?int  $a_action_sub_id = null 
)

Check permission.

Definition at line 151 of file class.ilClaimingPermissionHelper.php.

156 : bool {
157 if ($this->isValidContextAndAction($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
158 return $this->checkPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id);
159 }
160 // :TODO: exception?
161 return false;
162 }
isValidContextAndAction(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check if given combination of context and action is valid.
checkPermission(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission (helper: rbac, plugins)

◆ hasPermissions()

ilClaimingPermissionHelper::hasPermissions ( int  $a_context_type,
string  $a_context_id,
array  $a_action_ids 
)

Check permissions.

Definition at line 167 of file class.ilClaimingPermissionHelper.php.

167 : array
168 {
169 $res = array();
170
171 foreach ($a_action_ids as $action_id) {
172 if (is_array($action_id)) {
173 $action_sub_id = $action_id[1];
174 $action_id = $action_id[0];
175
176 $res[$action_id][$action_sub_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id, $action_sub_id);
177 } else {
178 $res[$action_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id);
179 }
180 }
181
182 return $res;
183 }
hasPermission(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission.
$res
Definition: ltiservices.php:69

References $res.

◆ isValidContextAndAction()

ilClaimingPermissionHelper::isValidContextAndAction ( int  $a_context_type,
string  $a_context_id,
int  $a_action_id,
?int  $a_action_sub_id = null 
)
protected

Check if given combination of context and action is valid.

Definition at line 101 of file class.ilClaimingPermissionHelper.php.

106 : bool {
107 $valid = false;
108
109 if (array_key_exists($a_context_type, $this->map)) {
110 if (!$a_action_sub_id) {
111 if (in_array($a_action_id, $this->map[$a_context_type]["actions"])) {
112 $valid = true;
113 }
114 } else {
115 if (array_key_exists($a_action_id, $this->map[$a_context_type]["subactions"]) &&
116 in_array($a_action_sub_id, $this->map[$a_context_type]["subactions"][$a_action_id])) {
117 $valid = true;
118 }
119 }
120 }
121
122 if ($valid &&
123 $a_context_id &&
124 !in_array($a_context_id, $this->getValidContextIds($a_context_type))) {
125 $valid = false;
126 }
127
128 if (DEVMODE && !$valid) {
129 trigger_error("INVALID permission context - " . $a_context_type . ":" . $a_context_id . ":" . $a_action_id . ":" . $a_action_sub_id, E_USER_WARNING);
130 }
131
132 return $valid;
133 }
getValidContextIds(int $a_context_type)
Get context ids for context type (uses cache)

References $valid.

◆ readContextIds()

ilClaimingPermissionHelper::readContextIds ( int  $a_context_type)
abstractprotected

Get all context ids for context type (from DB, is cached)

Reimplemented in ilAdvancedMDPermissionHelper, and ilUDFPermissionHelper.

◆ reset()

ilClaimingPermissionHelper::reset ( )

Reset (internal caches)

Definition at line 54 of file class.ilClaimingPermissionHelper.php.

54 : void
55 {
56 $this->context_ids = array();
57 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRefId()

ilClaimingPermissionHelper::setRefId ( int  $a_value)
protected

Definition at line 72 of file class.ilClaimingPermissionHelper.php.

72 : void
73 {
74 $this->ref_id = $a_value;
75 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUserId()

ilClaimingPermissionHelper::setUserId ( int  $a_value)
protected

Definition at line 62 of file class.ilClaimingPermissionHelper.php.

62 : void
63 {
64 $this->user_id = $a_value;
65 }

Referenced by __construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $context_ids

array ilClaimingPermissionHelper::$context_ids = []
protected

Definition at line 30 of file class.ilClaimingPermissionHelper.php.

◆ $instances

array ilClaimingPermissionHelper::$instances = []
staticprotected

Definition at line 33 of file class.ilClaimingPermissionHelper.php.

◆ $map

array ilClaimingPermissionHelper::$map = []
protected

Definition at line 29 of file class.ilClaimingPermissionHelper.php.

◆ $plugins

array ilClaimingPermissionHelper::$plugins = null
protected

Definition at line 32 of file class.ilClaimingPermissionHelper.php.

◆ $ref_id

int ilClaimingPermissionHelper::$ref_id = 0
protected

Definition at line 28 of file class.ilClaimingPermissionHelper.php.

Referenced by getRefId().

◆ $user_id

int ilClaimingPermissionHelper::$user_id = 0
protected

Definition at line 27 of file class.ilClaimingPermissionHelper.php.

Referenced by getUserId().


The documentation for this class was generated from the following file: