ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilSettingsPermissionGUI Class Reference

UI class for handling permissions that can be configured having the write permission for an object. More...

+ Collaboration diagram for ilSettingsPermissionGUI:

Public Member Functions

 __construct (object $a_gui_obj)
 
 determineRoles ()
 Determine roles. More...
 
 setRoleRequiredPermissions (array $a_val)
 Set role required permissions (this permissions are required for a role to be listed) More...
 
 getRoleRequiredPermissions ()
 Get role required permissions. More...
 
 setRoleProhibitedPermissions (array $a_val)
 Set role prohibited permissions (this permissions are prohibited for a role to be listed) More...
 
 getRoleProhibitedPermissions ()
 Get role prohibited permissions. More...
 
 setPermissions (array $a_val)
 Set permissions. More...
 
 getPermissions ()
 Get permissions. More...
 
 executeCommand ()
 Execute command. More...
 
 showForm ()
 Show form. More...
 
 initPermissionForm ()
 Init permission form. More...
 
 save ()
 Save form. More...
 

Protected Attributes

array $permissions = []
 
array $base_permissions = []
 
array $base_permissions_by_op = []
 
array $role_required_permissions = []
 
array $role_prohibited_permissions = []
 
array $base_roles = []
 
ilRbacReview $review
 
ilRbacAdmin $admin
 
ilGlobalTemplateInterface $tpl
 
ilLanguage $lng
 
ilCtrl $ctrl
 

Private Attributes

object $obj
 

Detailed Description

UI class for handling permissions that can be configured having the write permission for an object.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilSettingsPermissionGUI::__construct ( object  $a_gui_obj)

Definition at line 45 of file class.ilSettingsPermissionGUI.php.

References $DIC, ilRbacReview\_getOperationList(), ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

46  {
47  global $DIC;
48 
49  $this->lng = $DIC->language();
50  $this->lng->loadLanguageModule("rbac");
51  $this->ctrl = $DIC->ctrl();
52  $this->obj = $a_gui_obj->getObject();
53  $this->review = $DIC->rbac()->review();
54  $this->admin = $DIC->rbac()->admin();
55  $this->tpl = $DIC->ui()->mainTemplate();
56 
57  foreach (ilRbacReview::_getOperationList($this->obj->getType()) as $p) {
58  $this->base_permissions[$p["ops_id"]] = $p["operation"];
59  $this->base_permissions_by_op[$p["operation"]] = $p["ops_id"];
60  }
61 
62  $this->base_roles = $this->review->getParentRoleIds($this->obj->getRefId());
63  }
static _getOperationList(string $a_type='')
get operation list by object type
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ determineRoles()

ilSettingsPermissionGUI::determineRoles ( )

Determine roles.

Definition at line 68 of file class.ilSettingsPermissionGUI.php.

References $r, getRoleProhibitedPermissions(), getRoleRequiredPermissions(), and ILIAS\Repository\int().

Referenced by initPermissionForm(), and save().

68  : array
69  {
70  $roles = [];
71  foreach ($this->base_roles as $k => $r) {
72  $ops = $this->review->getActiveOperationsOfRole($this->obj->getRefId(), (int) $r["rol_id"]);
73  $use = true;
74  foreach ($this->getRoleRequiredPermissions() as $o) {
75  if (!in_array($o, $ops)) {
76  $use = false;
77  }
78  }
79  foreach ($this->getRoleProhibitedPermissions() as $o) {
80  if (in_array($o, $ops)) {
81  $use = false;
82  }
83  }
84  if ($use) {
85  $roles[$k] = $r;
86  }
87  }
88  return $roles;
89  }
getRoleProhibitedPermissions()
Get role prohibited permissions.
getRoleRequiredPermissions()
Get role required permissions.
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilSettingsPermissionGUI::executeCommand ( )

Execute command.

Definition at line 165 of file class.ilSettingsPermissionGUI.php.

References ILIAS\Repository\ctrl().

165  : void
166  {
167  $cmd = $this->ctrl->getCmd("showForm");
168  if (in_array($cmd, ["showForm", "save"])) {
169  $this->$cmd();
170  }
171  }
+ Here is the call graph for this function:

◆ getPermissions()

ilSettingsPermissionGUI::getPermissions ( )

Get permissions.

Returns
array array of operations (string) that should be offered

Definition at line 157 of file class.ilSettingsPermissionGUI.php.

References $permissions.

Referenced by initPermissionForm(), and save().

157  : array
158  {
159  return $this->permissions;
160  }
+ Here is the caller graph for this function:

◆ getRoleProhibitedPermissions()

ilSettingsPermissionGUI::getRoleProhibitedPermissions ( )

Get role prohibited permissions.

Returns
array permissions prohibited to be listed

Definition at line 133 of file class.ilSettingsPermissionGUI.php.

References $role_prohibited_permissions.

Referenced by determineRoles().

133  : array
134  {
136  }
+ Here is the caller graph for this function:

◆ getRoleRequiredPermissions()

ilSettingsPermissionGUI::getRoleRequiredPermissions ( )

Get role required permissions.

Returns
array permissions required to be listed

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

References $role_required_permissions.

Referenced by determineRoles().

109  : array
110  {
112  }
+ Here is the caller graph for this function:

◆ initPermissionForm()

ilSettingsPermissionGUI::initPermissionForm ( )

Init permission form.

Definition at line 185 of file class.ilSettingsPermissionGUI.php.

References $r, ilObjRole\_getTranslation(), ILIAS\Repository\ctrl(), determineRoles(), getPermissions(), ILIAS\Repository\int(), and ILIAS\Repository\lng().

Referenced by save(), and showForm().

186  {
187  $form = new ilPropertyFormGUI();
188  $roles = $this->determineRoles();
189  $ops = [];
190  foreach ($roles as $r) {
191  $ops[(int) $r["rol_id"]] = $this->review->getActiveOperationsOfRole($this->obj->getRefId(), (int) $r["rol_id"]);
192  }
193 
194  // for each permission, collect all roles that have the permission activated
195  $perm_roles = [];
196  foreach ($ops as $r => $o2) {
197  foreach ($o2 as $o) {
198  $perm_roles[$o][] = $r;
199  }
200  }
201 
202  // for each permission
203  foreach ($this->getPermissions() as $p) {
204  // roles
205  $cb = new ilCheckboxGroupInputGUI($this->lng->txt($p), $p);
206  reset($roles);
207  foreach ($roles as $k => $r) {
208  $option = new ilCheckboxOption(ilObjRole::_getTranslation($r["title"]), (string) $k);
209  $cb->addOption($option);
210  }
211  if (isset($perm_roles[$this->base_permissions_by_op[$p]])) {
212  $cb->setValue($perm_roles[$this->base_permissions_by_op[$p]]);
213  }
214  $form->addItem($cb);
215  }
216 
217  $form->addCommandButton("save", $this->lng->txt("save"));
218 
219  $form->setTitle($this->lng->txt("rbac_permissions"));
220  $form->setFormAction($this->ctrl->getFormAction($this));
221  return $form;
222  }
This class represents an option in a checkbox group.
static _getTranslation(string $a_role_title)
This class represents a property in a property form.
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilSettingsPermissionGUI::save ( )

Save form.

Definition at line 227 of file class.ilSettingsPermissionGUI.php.

References $r, ILIAS\Repository\ctrl(), determineRoles(), getPermissions(), initPermissionForm(), and ILIAS\Repository\lng().

227  : void
228  {
229  $form = $this->initPermissionForm();
230  if ($form->checkInput()) {
231  foreach ($this->determineRoles() as $r) {
232  // get active operations for role
233  $ops = $this->review->getActiveOperationsOfRole($this->obj->getRefId(), $r["rol_id"]);
234 
235  // revode all permissions for the role
236  $this->admin->revokePermission($this->obj->getRefId(), $r["rol_id"]);
237 
238  // for all permissions of the form...
239  foreach ($this->getPermissions() as $p) {
240  $roles = $form->getInput($p);
241  if (!is_array($roles)) {
242  $roles = [];
243  }
244  $o = $this->base_permissions_by_op[$p];
245 
246  // ... if in original operations, but not checked, remove it from operations
247  if (in_array($o, $ops) && !in_array($r["rol_id"], $roles)) {
248  if (($key = array_search($o, $ops)) !== false) {
249  unset($ops[$key]);
250  }
251  }
252 
253  // ...if not in original operations, but checked, add to operations
254  if (!in_array($o, $ops) && in_array($r["rol_id"], $roles)) {
255  $ops[] = $o;
256  }
257  }
258  // now grant resulting permissions
259  $this->admin->grantPermission(
260  $r["rol_id"],
261  array_unique($ops),
262  $this->obj->getRefId()
263  );
264  }
265 
266  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
267  $this->ctrl->redirect($this, "");
268  } else {
269  $form->setValuesByPost();
270  $this->tpl->setContent($form->getHTML());
271  }
272  }
initPermissionForm()
Init permission form.
$r
+ Here is the call graph for this function:

◆ setPermissions()

ilSettingsPermissionGUI::setPermissions ( array  $a_val)

Set permissions.

Parameters
array$a_valarray of operations (string) that should be offered

Definition at line 142 of file class.ilSettingsPermissionGUI.php.

142  : void
143  {
144  if (is_array($a_val)) {
145  foreach ($a_val as $p) {
146  if (in_array($p, $this->base_permissions)) {
147  $this->permissions[$this->base_permissions_by_op[$p]] = $p;
148  }
149  }
150  }
151  }

◆ setRoleProhibitedPermissions()

ilSettingsPermissionGUI::setRoleProhibitedPermissions ( array  $a_val)

Set role prohibited permissions (this permissions are prohibited for a role to be listed)

Parameters
array$a_valpermissions prohibited to be listed

Definition at line 118 of file class.ilSettingsPermissionGUI.php.

118  : void
119  {
120  if (is_array($a_val)) {
121  foreach ($a_val as $p) {
122  if (in_array($p, $this->base_permissions)) {
123  $this->role_prohibited_permissions[] = $this->base_permissions_by_op[$p];
124  }
125  }
126  }
127  }

◆ setRoleRequiredPermissions()

ilSettingsPermissionGUI::setRoleRequiredPermissions ( array  $a_val)

Set role required permissions (this permissions are required for a role to be listed)

Definition at line 94 of file class.ilSettingsPermissionGUI.php.

94  : void
95  {
96  if (is_array($a_val)) {
97  foreach ($a_val as $p) {
98  if (in_array($p, $this->base_permissions)) {
99  $this->role_required_permissions[] = $this->base_permissions_by_op[$p];
100  }
101  }
102  }
103  }

◆ showForm()

ilSettingsPermissionGUI::showForm ( )

Show form.

Definition at line 176 of file class.ilSettingsPermissionGUI.php.

References initPermissionForm().

176  : void
177  {
178  $form = $this->initPermissionForm();
179  $this->tpl->setContent($form->getHTML());
180  }
initPermissionForm()
Init permission form.
+ Here is the call graph for this function:

Field Documentation

◆ $admin

ilRbacAdmin ilSettingsPermissionGUI::$admin
protected

Definition at line 40 of file class.ilSettingsPermissionGUI.php.

◆ $base_permissions

array ilSettingsPermissionGUI::$base_permissions = []
protected

Definition at line 31 of file class.ilSettingsPermissionGUI.php.

◆ $base_permissions_by_op

array ilSettingsPermissionGUI::$base_permissions_by_op = []
protected

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

◆ $base_roles

array ilSettingsPermissionGUI::$base_roles = []
protected

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

◆ $ctrl

ilCtrl ilSettingsPermissionGUI::$ctrl
protected

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

◆ $lng

ilLanguage ilSettingsPermissionGUI::$lng
protected

Definition at line 42 of file class.ilSettingsPermissionGUI.php.

◆ $obj

object ilSettingsPermissionGUI::$obj
private

Definition at line 37 of file class.ilSettingsPermissionGUI.php.

◆ $permissions

array ilSettingsPermissionGUI::$permissions = []
protected

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

Referenced by getPermissions().

◆ $review

ilRbacReview ilSettingsPermissionGUI::$review
protected

Definition at line 39 of file class.ilSettingsPermissionGUI.php.

◆ $role_prohibited_permissions

array ilSettingsPermissionGUI::$role_prohibited_permissions = []
protected

Definition at line 34 of file class.ilSettingsPermissionGUI.php.

Referenced by getRoleProhibitedPermissions().

◆ $role_required_permissions

array ilSettingsPermissionGUI::$role_required_permissions = []
protected

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

Referenced by getRoleRequiredPermissions().

◆ $tpl

ilGlobalTemplateInterface ilSettingsPermissionGUI::$tpl
protected

Definition at line 41 of file class.ilSettingsPermissionGUI.php.


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