ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjRoleTemplateGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
32 {
33  private const FORM_MODE_EDIT = 1;
34  private const FORM_MODE_CREATE = 2;
35 
36  private int $rolf_ref_id;
37 
39 
41  protected Factory $refinery;
42 
43  public function __construct($a_data, int $a_id, bool $a_call_by_reference)
44  {
45  global $DIC;
46 
47  $this->rbac_admin = $DIC->rbac()->admin();
48 
49  $this->type = "rolt";
50  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
51  $this->lng->loadLanguageModule('rbac');
52  $this->rolf_ref_id = &$this->ref_id;
53  $this->ctrl->saveParameter($this, "obj_id");
54  $this->http = $DIC->http();
55  $this->refinery = $DIC->refinery();
56  }
57 
58  public function executeCommand(): void
59  {
60  $this->prepareOutput();
61 
62  $next_class = $this->ctrl->getNextClass($this);
63  $cmd = $this->ctrl->getCmd();
64 
65  switch ($next_class) {
66  default:
67  if (!$cmd) {
68  $cmd = "perm";
69  }
70  $cmd .= "Object";
71  $this->$cmd();
72 
73  break;
74  }
75  }
76 
77  protected function initFormRoleTemplate(int $a_mode = self::FORM_MODE_CREATE): ilPropertyFormGUI
78  {
79  $form = new ilPropertyFormGUI();
80 
81  if ($this->creation_mode) {
82  $this->ctrl->setParameter($this, "new_type", 'rolt');
83  }
84 
85  $form->setFormAction($this->ctrl->getFormAction($this));
86 
87  if ($a_mode == self::FORM_MODE_CREATE) {
88  $form->setTitle($this->lng->txt('rolt_new'));
89  $form->addCommandButton('save', $this->lng->txt('rolt_new'));
90  } else {
91  $form->setTitle($this->lng->txt('rolt_edit'));
92  $form->addCommandButton('update', $this->lng->txt('save'));
93  }
94  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
95 
96  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
97  if ($a_mode != self::FORM_MODE_CREATE) {
98  if ($this->object->isInternalTemplate()) {
99  $title->setDisabled(true);
100  }
101  $title->setValue(ilObjRole::_getTranslation($this->object->getTitle()));
102  }
103  $title->setSize(40);
104  $title->setMaxLength(70);
105  $title->setRequired(true);
106  $form->addItem($title);
107 
108  $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'desc');
109 
110  if ($a_mode != self::FORM_MODE_CREATE) {
111  $desc->setValue($this->object->getDescription());
112  }
113  $desc->setCols(40);
114  $desc->setRows(3);
115  $form->addItem($desc);
116 
117  if ($a_mode != self::FORM_MODE_CREATE) {
118  $ilias_id = new ilNonEditableValueGUI($this->lng->txt("ilias_id"), "ilias_id");
119  $ilias_id->setValue('il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->object->getId()) . '_' . $this->object->getId());
120  $form->addItem($ilias_id);
121  }
122 
123  $pro = new ilCheckboxInputGUI($this->lng->txt('role_protect_permissions'), 'protected');
124  $pro->setChecked($GLOBALS['DIC']['rbacreview']->isProtected(
125  $this->rolf_ref_id,
126  $this->object->getId()
127  ));
128  $pro->setValue((string) 1);
129  $form->addItem($pro);
130 
131  return $form;
132  }
133 
134  public function createObject(ilPropertyFormGUI $form = null): void
135  {
136  if (!$this->rbac_system->checkAccess("create_rolt", $this->rolf_ref_id)) {
137  $this->error->raiseError($this->lng->txt("permission_denied"), $this->error->MESSAGE);
138  }
139  if ($form === null) {
140  $form = $this->initFormRoleTemplate(self::FORM_MODE_CREATE);
141  }
142  $this->tpl->setContent($form->getHTML());
143  }
144 
148  public function editObject(ilPropertyFormGUI $form = null): void
149  {
150  $this->tabs_gui->activateTab('settings');
151 
152  if (!$this->rbac_system->checkAccess("write", $this->rolf_ref_id)) {
153  $this->error->raiseError($this->lng->txt("msg_no_perm_write"), $this->error->MESSAGE);
154  }
155 
156  if ($form === null) {
157  $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
158  }
159  $this->tpl->setContent($form->getHTML());
160  }
161 
162  public function updateObject(): void
163  {
164  // check write access
165  if (!$this->rbac_system->checkAccess("write", $this->rolf_ref_id)) {
166  $this->error->raiseError($this->lng->txt("msg_no_perm_modify_rolt"), $this->error->WARNING);
167  }
168 
169  $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
170  if ($form->checkInput()) {
171  if (!$this->object->isInternalTemplate()) {
172  $this->object->setTitle($form->getInput('title'));
173  }
174  $this->object->setDescription($form->getInput('desc'));
175  $this->rbac_admin->setProtected(
176  $this->rolf_ref_id,
177  $this->object->getId(),
178  $form->getInput('protected') ? 'y' : 'n'
179  );
180  $this->object->update();
181  $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"), true);
182  $this->ctrl->returnToParent($this);
183  }
184 
185  $form->setValuesByPost();
186  $this->editObject($form);
187  }
188 
189  public function saveObject(): void
190  {
191  if (!$this->rbac_system->checkAccess("create_rolt", $this->rolf_ref_id)) {
192  $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolt"), $this->ilias->error_obj->WARNING);
193  }
194  $form = $this->initFormRoleTemplate();
195  if ($form->checkInput()) {
196  $roltObj = new ilObjRoleTemplate();
197  $roltObj->setTitle($form->getInput('title'));
198  $roltObj->setDescription($form->getInput('desc'));
199  $roltObj->create();
200  $this->rbac_admin->assignRoleToFolder($roltObj->getId(), $this->rolf_ref_id, 'n');
201  $this->rbac_admin->setProtected(
202  $this->rolf_ref_id,
203  $roltObj->getId(),
204  $form->getInput('protected') ? 'y' : 'n'
205  );
206 
207  $this->tpl->setOnScreenMessage('success', $this->lng->txt("rolt_added"), true);
208  // redirect to permission screen
209  $this->ctrl->setParameter($this, 'obj_id', $roltObj->getId());
210  $this->ctrl->redirect($this, 'perm');
211  }
212  $form->setValuesByPost();
213  $this->createObject($form);
214  }
215 
216  protected function permObject(): void
217  {
218  if (!$this->rbac_system->checkAccess('edit_permission', $this->ref_id)) {
219  $this->error->raiseError($this->lng->txt('msg_no_perm_perm'), $this->error->MESSAGE);
220  return;
221  }
222  $this->tabs_gui->activateTab('perm');
223 
224  $this->tpl->addBlockFile(
225  'ADM_CONTENT',
226  'adm_content',
227  'tpl.rbac_template_permissions.html',
228  'Services/AccessControl'
229  );
230 
231  $this->tpl->setVariable('PERM_ACTION', $this->ctrl->getFormAction($this));
232 
233  $acc = new ilAccordionGUI();
234  $acc->setBehaviour(ilAccordionGUI::FORCE_ALL_OPEN);
235  $acc->setId('template_perm_' . $this->ref_id);
236 
237  $subs = ilObjRole::getSubObjects('root', false);
238 
239  foreach ($subs as $subtype => $def) {
241  $this,
242  'perm',
243  $this->ref_id,
244  $this->obj_id,
245  $subtype,
246  false
247  );
248  $tbl->setShowChangeExistingObjects(false);
249  $tbl->parse();
250 
251  $acc->addItem($def['translation'], $tbl->getHTML());
252  }
253 
254  $this->tpl->setVariable('ACCORDION', $acc->getHTML());
255 
256  // Add options table
258  $this,
259  'perm',
260  $this->ref_id,
261  $this->obj_id,
262  false
263  );
264  $options->setShowOptions(false);
265  $options->addMultiCommand(
266  'permSave',
267  $this->lng->txt('save')
268  );
269 
270  $options->parse();
271  $this->tpl->setVariable('OPTIONS_TABLE', $options->getHTML());
272  }
273 
277  protected function permSaveObject(): void
278  {
279  if (!$this->rbac_system->checkAccess('write', $this->rolf_ref_id)) {
280  $this->error->raiseError($this->lng->txt('msg_no_perm_perm'), $this->error->MESSAGE);
281  return;
282  }
283 
284  $template_permissions = [];
285  if ($this->http->wrapper()->post()->has('template_perm')) {
286  $custom_transformer = $this->refinery->custom()->transformation(
287  function ($array) {
288  return $array;
289  }
290  );
291  $template_permissions = $this->http->wrapper()->post()->retrieve(
292  'template_perm',
293  $custom_transformer
294  );
295  }
296  // delete all existing template entries
297  //$rbacadmin->deleteRolePermission($this->object->getId(), $this->ref_id);
298  $subs = ilObjRole::getSubObjects('root', false);
299 
300  foreach (array_keys($subs) as $subtype) {
301  // Delete per object type
302  $this->rbac_admin->deleteRolePermission($this->object->getId(), $this->ref_id, $subtype);
303  }
304 
305  foreach ($template_permissions as $key => $ops_array) {
306  $this->rbac_admin->setRolePermission($this->object->getId(), $key, $ops_array, $this->rolf_ref_id);
307  }
308 
309  // update object data entry (to update last modification date)
310  $this->object->update();
311 
312  $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"), true);
313  $this->ctrl->redirect($this, "perm");
314  }
315 
316  public function adoptPermSaveObject(): void
317  {
318  $source = 0;
319  if ($this->http->wrapper()->post()->has('adopt')) {
320  $source = $this->http->wrapper()->post()->retrieve(
321  'adopt',
322  $this->refinery->kindlyTo()->int()
323  );
324  }
325 
326  if (!$this->rbac_system->checkAccess('write', $this->rolf_ref_id)) {
327  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_perm'), true);
328  } elseif ($this->obj_id == $source) {
329  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_perm_adopted_from_itself"), true);
330  } else {
331  $this->rbac_admin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
332  $parentRoles = $this->rbac_review->getParentRoleIds($this->rolf_ref_id, true);
333  $this->rbac_admin->copyRoleTemplatePermissions(
334  $source,
335  $parentRoles[$source]["parent"],
336  $this->rolf_ref_id,
337  $this->obj_id
338  );
339  // update object data entry (to update last modification date)
340  $this->object->update();
341 
342  // send info
343  $title = ilObject::_lookupTitle($source);
344  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_perm_adopted_from1") . " '" . $title . "'.<br/>" . $this->lng->txt("msg_perm_adopted_from2"), true);
345  }
346  $this->ctrl->redirect($this, "perm");
347  }
348 
349  public function getAdminTabs(): void
350  {
351  $this->getTabs();
352  }
353 
357  protected function getTabs(): void
358  {
359  $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), (string) $this->ctrl->getParentReturn($this));
360 
361  if ($this->rbac_system->checkAccess('write', $this->ref_id)) {
362  $this->tabs_gui->addTab(
363  'settings',
364  $this->lng->txt('settings'),
365  $this->ctrl->getLinkTarget($this, 'edit')
366  );
367  }
368  if ($this->rbac_system->checkAccess('edit_permission', $this->ref_id)) {
369  $this->tabs_gui->addTab(
370  'perm',
371  $this->lng->txt('default_perm_settings'),
372  $this->ctrl->getLinkTarget($this, 'perm')
373  );
374  }
375  }
376 
377  public function cancelObject(): void
378  {
379  $this->ctrl->redirectByClass("ilobjrolefoldergui", "view");
380  }
381 
385  protected function addAdminLocatorItems(bool $do_not_add_object = false): void
386  {
387  parent::addAdminLocatorItems(true);
388 
389  $query = $this->http->wrapper()->query();
390 
391  if ($query->has('ref_id')) {
392  $ref_id = $query->retrieve('ref_id', $this->refinery->kindlyTo()->int());
393  $this->locator->addItem(
394  $this->lng->txt('obj_' . ilObject::_lookupType(
396  )),
397  $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", "view")
398  );
399  }
400 
401  if ($query->has('obj_id')) {
402  $this->locator->addItem(
403  ilObjRole::_getTranslation($this->object->getTitle()),
404  $this->ctrl->getLinkTarget($this, 'perm')
405  );
406  }
407  }
408 } // END class.ilObjRoleTemplateGUI
Interface GlobalHttpState.
addAdminLocatorItems(bool $do_not_add_object=false)
const IL_INST_ID
Definition: constants.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prepareOutput(bool $show_sub_objects=true)
This class represents a checkbox property in a property form.
createObject()
create new object form
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
static _lookupTitle(int $obj_id)
initFormRoleTemplate(int $a_mode=self::FORM_MODE_CREATE)
static _getTranslation(string $a_role_title)
Class ilObjectGUI Basic methods of all Output classes.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
string $key
Consumer key/client ID value.
Definition: System.php:193
header include for all ilias files.
$query
__construct($a_data, int $a_id, bool $a_call_by_reference)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
Class ilObjRoleTemplateGUI.
Class ilRbacAdmin Core functions for role based access control.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$source
Definition: metadata.php:93
createObject(ilPropertyFormGUI $form=null)
editObject(ilPropertyFormGUI $form=null)
Create new object.