ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjRoleTemplateGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
33{
34 private const FORM_KEY_TITLE = 'title';
35 private const FORM_KEY_DESCRIPTION = 'description';
36 private const FORM_KEY_ILIAS_ID = 'ilias_id';
37 private const FORM_KEY_PROTECT = 'protect';
38
39 private int $rolf_ref_id;
40
41 public function __construct($a_data, int $a_id, bool $a_call_by_reference)
42 {
43 global $DIC;
44
45 $this->type = "rolt";
46 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
47 $this->lng->loadLanguageModule('rbac');
48 $this->rolf_ref_id = &$this->ref_id;
49 $this->ctrl->saveParameter($this, "obj_id");
50 }
51
52 public function executeCommand(): void
53 {
54 $this->prepareOutput();
55
56 $next_class = $this->ctrl->getNextClass($this);
57 $cmd = $this->ctrl->getCmd();
58
59 switch ($next_class) {
60 default:
61 if (!$cmd) {
62 $cmd = "perm";
63 }
64 $cmd .= "Object";
65 $this->$cmd();
66
67 break;
68 }
69 }
70
71 protected function getRoleTemplateForm(bool $is_role_creation_form = false): StandardForm
72 {
73 if ($this->creation_mode) {
74 $this->ctrl->setParameter($this, 'new_type', 'rolt');
75 }
76
77 $ff = $this->ui_factory->input()->field();
78
79 $title_validation_constraint = $this->refinery->custom()->constraint(
80 fn(string $v): bool => preg_match('/^il_.*$/', $v) ? false : true,
81 $this->lng->txt('msg_role_reserved_prefix')
82 );
83
84 $inputs = [
85 self::FORM_KEY_TITLE => $ff->text($this->lng->txt('title'))
86 ->withMaxLength(70)
87 ->withRequired(true)
88 ->withAdditionalTransformation($title_validation_constraint)
89 ->withValue(
90 $is_role_creation_form ? ''
91 : ilObjRole::_getTranslation($this->object->getTitle())
92 )->withDisabled($is_role_creation_form ? false : $this->object->isInternalTemplate()),
93 self::FORM_KEY_DESCRIPTION => $ff->textarea($this->lng->txt('description'))
94 ->withMaxLimit(4000)
95 ->withValue($is_role_creation_form ? '' : $this->object->getDescription())
96 ];
97
98 if (!$is_role_creation_form) {
99 $inputs[self::FORM_KEY_ILIAS_ID] = $ff->text($this->lng->txt('ilias_id'))
100 ->withDisabled(true)
101 ->withValue('il_' . IL_INST_ID . '_'
102 . $this->object->getType() . '_' . $this->object->getId());
103 }
104
105 $inputs[self::FORM_KEY_PROTECT] = $ff->checkbox($this->lng->txt('role_protect_permissions'))
106 ->withValue(
107 $is_role_creation_form
108 ? false
109 : $this->rbac_review->isProtected($this->rolf_ref_id, $this->object->getId())
110 );
111
112 return $this->ui_factory->input()->container()->form()->standard(
113 $this->ctrl->getFormActionByClass(
114 self::class,
115 $is_role_creation_form ? 'save' : 'update'
116 ),
117 $inputs
118 )->withSubmitLabel(
119 $is_role_creation_form ? $this->lng->txt('rolt_new') : $this->lng->txt('save')
120 );
121 }
122
123 public function createObject(): void
124 {
125 if (!$this->rbac_system->checkAccess('create_rolt', $this->rolf_ref_id)) {
126 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
127 }
128
129 $this->tabs_gui->setBackTarget(
130 $this->lng->txt('cancel'),
131 $this->ctrl->getParentReturnByClass(self::class)
132 );
133
134 $this->tpl->setContent(
135 $this->ui_renderer->render(
136 $this->ui_factory->panel()->standard(
137 $this->lng->txt('rolt_new'),
138 $this->getRoleTemplateForm(true)
139 )
140 )
141 );
142 }
143
147 public function editObject(?ilPropertyFormGUI $form = null): void
148 {
149 $this->tabs_gui->activateTab('settings');
150
151 if (!$this->rbac_system->checkAccess("write", $this->rolf_ref_id)) {
152 $this->error->raiseError($this->lng->txt("msg_no_perm_write"), $this->error->MESSAGE);
153 }
154
155 $this->tpl->setContent(
156 $this->ui_renderer->render(
157 $this->ui_factory->panel()->standard(
158 $this->lng->txt('rolt_edit'),
159 $this->getRoleTemplateForm()
160 )
161 )
162 );
163 }
164
165 public function saveObject(): void
166 {
167 if (!$this->rbac_system->checkAccess("create_rolt", $this->rolf_ref_id)) {
168 $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolt"), $this->ilias->error_obj->WARNING);
169 }
170
171 $form = $this->getRoleTemplateForm(true)->withRequest($this->request);
172 $data = $form->getData();
173 if ($data === null) {
174 $this->tabs_gui->setBackTarget(
175 $this->lng->txt('cancel'),
176 $this->ctrl->getParentReturnByClass(self::class)
177 );
178
179 $this->tpl->setContent(
180 $this->ui_renderer->render(
181 $this->ui_factory->panel()->standard(
182 $this->lng->txt('rolt_new'),
183 $form
184 )
185 )
186 );
187 return;
188 }
189
190 $role_template = new ilObjRoleTemplate();
191 $role_template->setTitle($data[self::FORM_KEY_TITLE]);
192 $role_template->setDescription($data[self::FORM_KEY_DESCRIPTION]);
193 $role_template->create();
194 $this->rbac_admin->assignRoleToFolder($role_template->getId(), $this->rolf_ref_id, 'n');
195 $this->rbac_admin->setProtected(
196 $this->rolf_ref_id,
197 $role_template->getId(),
198 $data[self::FORM_KEY_PROTECT] ? 'y' : 'n'
199 );
200 $this->tpl->setOnScreenMessage('success', $this->lng->txt("rolt_added"), true);
201 $this->ctrl->setParameter($this, 'obj_id', $role_template->getId());
202 $this->ctrl->redirect($this, 'perm');
203 }
204
205 public function updateObject(): void
206 {
207 if (!$this->rbac_system->checkAccess('write', $this->rolf_ref_id)) {
208 $this->error->raiseError($this->lng->txt('msg_no_perm_modify_rolt'), $this->error->WARNING);
209 }
210
211 $form = $this->getRoleTemplateForm()->withRequest($this->request);
212 $data = $form->getData();
213 if ($data === null) {
214 $this->tpl->setContent(
215 $this->ui_renderer->render(
216 $this->ui_factory->panel()->standard(
217 $this->lng->txt('rolt_edit'),
218 $form
219 )
220 )
221 );
222 return;
223 }
224
225 if (!$this->object->isInternalTemplate()) {
226 $this->object->setTitle($data[self::FORM_KEY_TITLE]);
227 }
228
229 $this->object->setDescription($data[self::FORM_KEY_DESCRIPTION]);
230 $this->object->update();
231 $this->rbac_admin->setProtected(
232 $this->rolf_ref_id,
233 $this->object->getId(),
234 $data[self::FORM_KEY_PROTECT] ? 'y' : 'n'
235 );
236 $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"), true);
237 $this->ctrl->returnToParent($this);
238 }
239
240 protected function permObject(): void
241 {
242 if (!$this->rbac_system->checkAccess('edit_permission', $this->ref_id)) {
243 $this->error->raiseError($this->lng->txt('msg_no_perm_perm'), $this->error->MESSAGE);
244 return;
245 }
246 $this->tabs_gui->activateTab('perm');
247
248 $this->tpl->addBlockFile(
249 'ADM_CONTENT',
250 'adm_content',
251 'tpl.rbac_template_permissions.html',
252 'components/ILIAS/AccessControl'
253 );
254
255 $this->tpl->setVariable('PERM_ACTION', $this->ctrl->getFormAction($this));
256
257 $acc = new ilAccordionGUI();
258 $acc->setBehaviour(ilAccordionGUI::FORCE_ALL_OPEN);
259 $acc->setId('template_perm_' . $this->ref_id);
260
261 $subs = ilObjRole::getSubObjects('root', false);
262
263 foreach ($subs as $subtype => $def) {
265 $this,
266 'perm',
267 $this->ref_id,
268 $this->obj_id,
269 $subtype,
270 false
271 );
272 $tbl->setShowChangeExistingObjects(false);
273 $tbl->parse();
274
275 $acc->addItem($def['translation'], $tbl->getHTML());
276 }
277
278 $this->tpl->setVariable('ACCORDION', $acc->getHTML());
279
280 // Add options table
282 $this,
283 'perm',
284 $this->ref_id,
285 $this->obj_id,
286 false
287 );
288 $options->setShowOptions(false);
289 $options->addMultiCommand(
290 'permSave',
291 $this->lng->txt('save')
292 );
293
294 $options->parse();
295 $this->tpl->setVariable('OPTIONS_TABLE', $options->getHTML());
296 }
297
301 protected function permSaveObject(): void
302 {
303 if (!$this->rbac_system->checkAccess('write', $this->rolf_ref_id)) {
304 $this->error->raiseError($this->lng->txt('msg_no_perm_perm'), $this->error->MESSAGE);
305 return;
306 }
307
308 $template_permissions = [];
309 if ($this->http->wrapper()->post()->has('template_perm')) {
310 $custom_transformer = $this->refinery->custom()->transformation(
311 function ($array) {
312 return $array;
313 }
314 );
315 $template_permissions = $this->http->wrapper()->post()->retrieve(
316 'template_perm',
317 $custom_transformer
318 );
319 }
320
321 $subs = ilObjRole::getSubObjects('root', false);
322 foreach (array_keys($subs) as $subtype) {
323 // Delete per object type
324 $this->rbac_admin->deleteRolePermission($this->object->getId(), $this->ref_id, $subtype);
325 }
326
327 foreach ($template_permissions as $key => $ops_array) {
328 $this->rbac_admin->setRolePermission($this->object->getId(), $key, $ops_array, $this->rolf_ref_id);
329 }
330
331 // update object data entry (to update last modification date)
332 $this->object->update();
333
334 $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"), true);
335 $this->ctrl->redirect($this, "perm");
336 }
337
338 public function adoptPermSaveObject(): void
339 {
340 $source = 0;
341 if ($this->http->wrapper()->post()->has('adopt')) {
342 $source = $this->http->wrapper()->post()->retrieve(
343 'adopt',
344 $this->refinery->kindlyTo()->int()
345 );
346 }
347
348 if (!$this->rbac_system->checkAccess('write', $this->rolf_ref_id)) {
349 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_perm'), true);
350 } elseif ($this->obj_id == $source) {
351 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_perm_adopted_from_itself"), true);
352 } else {
353 $this->rbac_admin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
354 $parentRoles = $this->rbac_review->getParentRoleIds($this->rolf_ref_id, true);
355 $this->rbac_admin->copyRoleTemplatePermissions(
356 $source,
357 $parentRoles[$source]["parent"],
358 $this->rolf_ref_id,
359 $this->obj_id
360 );
361 // update object data entry (to update last modification date)
362 $this->object->update();
363
364 // send info
365 $title = ilObject::_lookupTitle($source);
366 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_perm_adopted_from1") . " '" . $title . "'.<br/>" . $this->lng->txt("msg_perm_adopted_from2"), true);
367 }
368 $this->ctrl->redirect($this, "perm");
369 }
370
371 public function getAdminTabs(): void
372 {
373 $this->getTabs();
374 }
375
379 protected function getTabs(): void
380 {
381 $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), (string) $this->ctrl->getParentReturn($this));
382
383 if ($this->rbac_system->checkAccess('write', $this->ref_id)) {
384 $this->tabs_gui->addTab(
385 'settings',
386 $this->lng->txt('settings'),
387 $this->ctrl->getLinkTarget($this, 'edit')
388 );
389 }
390 if ($this->rbac_system->checkAccess('edit_permission', $this->ref_id)) {
391 $this->tabs_gui->addTab(
392 'perm',
393 $this->lng->txt('default_perm_settings'),
394 $this->ctrl->getLinkTarget($this, 'perm')
395 );
396 }
397 }
398
402 protected function addAdminLocatorItems(bool $do_not_add_object = false): void
403 {
404 parent::addAdminLocatorItems(true);
405
406 $query = $this->http->wrapper()->query();
407
408 if ($query->has('ref_id')) {
409 $ref_id = $query->retrieve('ref_id', $this->refinery->kindlyTo()->int());
410 $this->locator->addItem(
411 $this->lng->txt('obj_' . ilObject::_lookupType(
413 )),
414 $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", "view")
415 );
416 }
417
418 if ($query->has('obj_id')) {
419 $this->locator->addItem(
420 ilObjRole::_getTranslation($this->object->getTitle()),
421 $this->ctrl->getLinkTarget($this, 'perm')
422 );
423 }
424 }
425} // END class.ilObjRoleTemplateGUI
Builds data types.
Definition: Factory.php:36
error(string $a_errmsg)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjRoleTemplateGUI.
editObject(?ilPropertyFormGUI $form=null)
Create new object.
getAdminTabs()
administration tabs show only permissions and trash folder
__construct($a_data, int $a_id, bool $a_call_by_reference)
updateObject()
updates object entry in object_data
getTabs()
@abstract overwrite in derived GUI class of your object type
getRoleTemplateForm(bool $is_role_creation_form=false)
createObject()
create new object form
addAdminLocatorItems(bool $do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded)
Class ilObjRoleTemplate.
static _getTranslation(string $a_role_title)
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput(bool $show_sub_objects=true)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
const IL_INST_ID
Definition: constants.php:40
Interface GlobalHttpState.
This describes a standard form.
Definition: Standard.php:29
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ilObjForumAdministration.
global $DIC
Definition: shib_login.php:26