ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilClaimingPermissionHelper Class Reference

Claiming permission helper base class. More...

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

Public Member Functions

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

Static Public Member Functions

static getInstance ($a_user_id=null, $a_ref_id=null)
 Factory. More...
 

Protected Member Functions

 __construct ($a_user_id, $a_ref_id)
 Constructor. More...
 
 setUserId ($a_value)
 Set user id. More...
 
 getUserId ()
 Get user id. More...
 
 setRefId ($a_value)
 Set ref id. More...
 
 getRefId ()
 Get ref id. More...
 
 readContextIds ($a_context_type)
 Get all context ids for context type (from DB, is cached) More...
 
 buildPermissionMap ()
 Build map of context and actions. More...
 
 isValidContextAndAction ($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
 Check if given combination of context and action is valid. More...
 
 getValidContextIds ($a_context_type)
 Get context ids for context type (uses cache) More...
 
 checkPermission ($a_context_type, $a_context_id, $a_action_id, $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 ($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
 Check permission against plugins. More...
 

Protected Attributes

 $user_id
 
 $ref_id
 
 $map
 
 $context_ids
 
 $plugins
 

Static Protected Attributes

static $instances
 

Detailed Description

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
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters
int$a_user_id
int$a_ref_id
Returns
self

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

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

33  {
34  $this->setUserId($a_user_id);
35  $this->setRefId($a_ref_id);
36  $this->map = $this->buildPermissionMap();
37  $this->reset();
38  }
buildPermissionMap()
Build map of context and actions.
+ Here is the call graph for this function:

Member Function Documentation

◆ buildPermissionMap()

ilClaimingPermissionHelper::buildPermissionMap ( )
abstractprotected

Build map of context and actions.

Returns
array

Referenced by __construct(), and getRefId().

+ Here is the caller graph for this function:

◆ checkPermission()

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

Check permission (helper: rbac, plugins)

Parameters
int$a_context_type
int$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
bool

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

References $a_context_id, $a_context_type, checkPlugins(), and checkRBAC().

Referenced by hasPermission().

243  {
244  return ($this->checkRBAC() &&
245  $this->checkPlugins($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id));
246  }
$a_context_id
Definition: workflow.php:97
checkRBAC()
Check permission against RBAC.
checkPlugins($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check permission against plugins.
$a_context_type
Definition: workflow.php:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkPlugins()

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

Check permission against plugins.

Parameters
int$a_context_type
int$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
boolean

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

References $a_context_id, $a_context_type, $valid, array, and getActivePlugins().

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkPermission().

278  {
279  $valid = true;
280 
281  if (!is_array($this->plugins)) {
282  $this->plugins = (array) $this->getActivePlugins();
283  }
284 
285  foreach ($this->plugins as $plugin) {
286  if (!$plugin->checkPermission($this->getUserId(), $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
287  $valid = false;
288  break;
289  }
290  }
291 
292  return $valid;
293  }
$valid
$a_context_id
Definition: workflow.php:97
getActivePlugins()
Get active plugins (for current slot)
Create styles array
The data for the language used.
$a_context_type
Definition: workflow.php:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkRBAC()

ilClaimingPermissionHelper::checkRBAC ( )
protected

Check permission against RBAC.

Returns
bool

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

References getActivePlugins(), getRefId(), and getUserId().

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkPermission().

254  {
255  global $ilAccess;
256 
257  // we are currently only supporting write operations
258  return $ilAccess->checkAccessOfUser($this->getUserId(), "write", "", $this->getRefId());
259  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getActivePlugins()

ilClaimingPermissionHelper::getActivePlugins ( )
abstractprotected

Get active plugins (for current slot)

Returns
array ilPlugin

Referenced by checkPlugins(), and checkRBAC().

+ Here is the caller graph for this function:

◆ getInstance()

static ilClaimingPermissionHelper::getInstance (   $a_user_id = null,
  $a_ref_id = null 
)
static

Factory.

Parameters
int$a_user_id
int$a_ref_id
Returns
self

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

References $ilUser.

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

48  {
49  global $ilUser;
50 
51  if (!$a_user_id) {
52  $a_user_id = $ilUser->getId();
53  }
54  if (!$a_ref_id) {
55  $a_ref_id = (int) $_REQUEST["ref_id"];
56  }
57  if (!isset(self::$instances[$a_user_id][$a_ref_id])) {
58  self::$instances[$a_user_id][$a_ref_id] = new static($a_user_id, $a_ref_id);
59  }
60  return self::$instances[$a_user_id][$a_ref_id];
61  }
$ilUser
Definition: imgupload.php:18
+ Here is the caller graph for this function:

◆ getRefId()

ilClaimingPermissionHelper::getRefId ( )
protected

Get ref id.

Returns
int

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

References $a_context_type, $ref_id, buildPermissionMap(), and readContextIds().

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkRBAC().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserId()

ilClaimingPermissionHelper::getUserId ( )
protected

Get user id.

Returns
int

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

References $user_id.

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkRBAC().

+ Here is the caller graph for this function:

◆ getValidContextIds()

ilClaimingPermissionHelper::getValidContextIds (   $a_context_type)
protected

Get context ids for context type (uses cache)

See also
self::readContextIds()
Parameters
int$a_context_type
Returns
array

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

References $a_context_type, array, and readContextIds().

Referenced by isValidContextAndAction().

183  {
184  if (!array_key_exists($a_context_type, $this->context_ids)) {
185  $this->context_ids[$a_context_type] = $this->readContextIds($a_context_type);
186  }
187  return (array) $this->context_ids[$a_context_type];
188  }
readContextIds($a_context_type)
Get all context ids for context type (from DB, is cached)
Create styles array
The data for the language used.
$a_context_type
Definition: workflow.php:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPermission()

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

Check permission.

Parameters
int$a_context_type
int$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
bool

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

References $a_context_id, $a_context_type, checkPermission(), and isValidContextAndAction().

Referenced by hasPermissions(), and ilAdvancedMDFieldDefinition\importDefinitionFormPostValues().

200  {
201  if ($this->isValidContextAndAction($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
202  return $this->checkPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id);
203  }
204  // :TODO: exception?
205  }
checkPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check permission (helper: rbac, plugins)
$a_context_id
Definition: workflow.php:97
isValidContextAndAction($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check if given combination of context and action is valid.
$a_context_type
Definition: workflow.php:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPermissions()

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

Check permissions.

Parameters
int$a_context_type
int$a_context_id
array$a_action_ids
Returns
bool

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

References $a_context_id, $a_context_type, $res, array, and hasPermission().

Referenced by ilAdvancedMDFieldDefinition\addToFieldDefinitionForm().

216  {
217  $res = array();
218 
219  foreach ($a_action_ids as $action_id) {
220  if (is_array($action_id)) {
221  $action_sub_id = $action_id[1];
222  $action_id = $action_id[0];
223 
224  $res[$action_id][$action_sub_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id, $action_sub_id);
225  } else {
226  $res[$action_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id);
227  }
228  }
229 
230  return $res;
231  }
$a_context_id
Definition: workflow.php:97
hasPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check permission.
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
$a_context_type
Definition: workflow.php:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidContextAndAction()

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

Check if given combination of context and action is valid.

Parameters
int$a_context_type
mixed$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
boolean

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

References $a_context_id, $a_context_type, $valid, and getValidContextIds().

Referenced by hasPermission().

146  {
147  $valid = false;
148 
149  if (array_key_exists($a_context_type, $this->map)) {
150  if (!$a_action_sub_id) {
151  if (in_array($a_action_id, $this->map[$a_context_type]["actions"])) {
152  $valid = true;
153  }
154  } else {
155  if (array_key_exists($a_action_id, $this->map[$a_context_type]["subactions"]) &&
156  in_array($a_action_sub_id, $this->map[$a_context_type]["subactions"][$a_action_id])) {
157  $valid = true;
158  }
159  }
160  }
161 
162  if ($valid &&
163  $a_context_id &&
164  !in_array($a_context_id, $this->getValidContextIds($a_context_type))) {
165  $valid = false;
166  }
167 
168  if (DEVMODE && !$valid) {
169  trigger_error("INVALID permission context - " . $a_context_type . ":" . $a_context_id . ":" . $a_action_id . ":" . $a_action_sub_id, E_USER_WARNING);
170  }
171 
172  return $valid;
173  }
$valid
$a_context_id
Definition: workflow.php:97
$a_context_type
Definition: workflow.php:96
getValidContextIds($a_context_type)
Get context ids for context type (uses cache)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readContextIds()

ilClaimingPermissionHelper::readContextIds (   $a_context_type)
abstractprotected

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

See also
self::getValidContextIds()
Parameters
int$a_context_type
Returns
array

Referenced by getRefId(), and getValidContextIds().

+ Here is the caller graph for this function:

◆ reset()

ilClaimingPermissionHelper::reset ( )

Reset (internal caches)

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

References array.

Referenced by __construct().

67  {
68  $this->context_ids = array();
69  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ setRefId()

ilClaimingPermissionHelper::setRefId (   $a_value)
protected

Set ref id.

Parameters
int$a_value

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

Referenced by __construct().

100  {
101  $this->ref_id = (int) $a_value;
102  }
+ Here is the caller graph for this function:

◆ setUserId()

ilClaimingPermissionHelper::setUserId (   $a_value)
protected

Set user id.

Parameters
int$a_value

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

Referenced by __construct().

80  {
81  $this->user_id = (int) $a_value;
82  }
+ Here is the caller graph for this function:

Field Documentation

◆ $context_ids

ilClaimingPermissionHelper::$context_ids
protected

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

◆ $instances

ilClaimingPermissionHelper::$instances
staticprotected

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

◆ $map

ilClaimingPermissionHelper::$map
protected

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

◆ $plugins

ilClaimingPermissionHelper::$plugins
protected

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

◆ $ref_id

ilClaimingPermissionHelper::$ref_id
protected

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

Referenced by getRefId().

◆ $user_id

ilClaimingPermissionHelper::$user_id
protected

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

Referenced by getUserId().


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