ILIAS  trunk Revision v12.0_alpha-1541-g23eaa5e013d
class.SettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\UI\Factory as UIFactory;
28
30{
31 private \ilLogger $log;
32 private Language $lng;
33 private \ilSetting $settings;
34 private \ilGlobalTemplateInterface $tpl;
35 private \ilToolbarGUI $toolbar;
36 private \ilTabsGUI $tabs;
37 private \ilCtrl $ctrl;
38 private \ilTree $tree;
39 private \ilObjUser $user;
40 private \ilDBInterface $db;
41 private \ilRbacReview $rbac_review;
42 private \ilRbacSystem $rbac_system;
43 private UIFactory $ui_factory;
47 private \ilErrorHandling $error;
48
49 private int $parent_ref_id;
50
51 public function __construct(int $a_parent_ref_id)
52 {
54 global $DIC;
55
56 $this->log = \ilLoggerFactory::getLogger("user");
57 $this->lng = $DIC['lng'];
58 $this->settings = $DIC['ilSetting'];
59 $this->tpl = $DIC['tpl'];
60 $this->toolbar = $DIC['ilToolbar'];
61 $this->tabs = $DIC['ilTabs'];
62 $this->ctrl = $DIC['ilCtrl'];
63 $this->tree = $DIC['tree'];
64 $this->user = $DIC['ilUser'];
65 $this->db = $DIC['ilDB'];
66 $this->error = $DIC['ilErr'];
67 $this->rbac_review = $DIC['rbacreview'];
68 $this->rbac_system = $DIC['rbacsystem'];
69 $this->ui_factory = $DIC['ui.factory'];
70 $this->ui_renderer = $DIC['ui.renderer'];
71 $this->user_request = new UserGUIRequest(
72 $DIC->http(),
73 $DIC->refinery()
74 );
75
76 $this->starting_point_repository = LocalDIC::dic()[Repository::class];
77
78 $this->parent_ref_id = $a_parent_ref_id;
79
80 $this->lng->loadLanguageModule("administration");
81 $this->lng->loadLanguageModule("user");
82 $this->lng->loadLanguageModule("dateplaner");
83 }
84
85 public function executeCommand(): void
86 {
87 $cmd = $this->ctrl->getCmd();
88 if ($cmd == 'roleStartingPointform' || !$cmd) {
89 $cmd = 'initRoleStartingPointForm';
90 }
91
92 $this->$cmd();
93 }
94
98 public function startingPoints(): void
99 {
100 $this->toolbar->addComponent(
101 $this->ui_factory->link()->standard(
102 $this->lng->txt('create_starting_point'),
103 $this->ctrl->getLinkTarget($this, "roleStartingPointform")
104 )
105 );
106
107 $tbl = new \ilUserRoleStartingPointTableGUI(
108 $this,
109 $this->starting_point_repository,
110 $this->rbac_review,
111 $this->ui_factory,
112 $this->ui_renderer,
113 );
114
115 $this->tpl->setContent($tbl->getHTML());
116 }
117
118 public function initUserStartingPointForm(?\ilPropertyFormGUI $form = null): void
119 {
120 if (!($form instanceof \ilPropertyFormGUI)) {
121 $form = $this->getUserStartingPointForm();
122 }
123 $this->tpl->setContent($form->getHTML());
124 }
125
126 public function initRoleStartingPointForm(?\ilPropertyFormGUI $form = null): void
127 {
128 if (!($form instanceof \ilPropertyFormGUI)) {
129 $form = $this->getRoleStartingPointForm();
130 }
131 $this->tpl->setContent($form->getHTML());
132 }
133
135 {
136 if (!$this->rbac_system->checkAccess('write', $this->parent_ref_id)) {
137 $this->error->raiseError(
138 $this->lng->txt('msg_no_perm_read'),
139 $this->error->FATAL
140 );
141 }
142 $form = new \ilPropertyFormGUI();
143 $this->ctrl->saveParameter($this, ['spid']);
144
145 $starting_point_id = $this->user_request->getStartingPointId();
146 $starting_point = $this->getCurrentStartingPointOrNullForStartingPointForm($starting_point_id);
147 $starting_point_type = $this->getCurrentTypeForStartingPointForm($starting_point);
148 $req_role_id = $this->user_request->getRoleId();
149
150 foreach ($this->getFormTypeSpecificStartingPointFormParts($starting_point_id, $req_role_id) as $input) {
151 $form->addItem(
152 $input
153 );
154 }
155
156 $si = $this->getStartingPointSelectionInput($starting_point);
157 $si->setValue((string) $starting_point_type);
158 $form->addItem($si);
159
160 // save and cancel commands
161 $form->addCommandButton('saveStartingPoint', $this->lng->txt('save'));
162 $form->addCommandButton('startingPoints', $this->lng->txt('cancel'));
163
164 $form->setTitle($this->lng->txt('starting_point_settings'));
165 $form->setFormAction($this->ctrl->getFormAction($this));
166
167 return $form;
168 }
169
170 private function getCurrentStartingPointOrNullForStartingPointForm(?int $starting_point_id): ?StartingPoint
171 {
172 if ($starting_point_id === null) {
173 return null;
174 }
175
176 return $this->starting_point_repository->getStartingPointById(
177 $starting_point_id
178 );
179 }
180
181 private function getCurrentTypeForStartingPointForm(?StartingPoint $starting_point): ?int
182 {
183 if ($starting_point === null) {
184 return null;
185 }
186
187 return $starting_point->getStartingPointType();
188 }
189
190 private function getFormTypeSpecificStartingPointFormParts(?int $spoint_id, ?int $req_role_id): \Generator
191 { //edit no default
192 if ($spoint_id === null) {
193 yield $this->getCreateFormSpecificInputs();
194 } else {
195 yield from $this->getEditFormSpecificInputs($spoint_id, $req_role_id);
196 }
197 }
198
200 {
201 $roles = $this->starting_point_repository->getGlobalRolesWithoutStartingPoint();
202
203
204 // role type
205 $radg = new \ilRadioGroupInputGUI($this->lng->txt('role'), 'role_type');
206 $radg->setValue('1');
207 if ($roles !== []) {
208 $radg->setValue('0');
209 $op1 = new \ilRadioOption($this->lng->txt('user_global_role'), '0');
210 $radg->addOption($op1);
211
212 $role_options = [];
213 foreach ($roles as $role) {
214 $role_options[$role['id']] = $role['title'];
215 }
216 $si_roles = new \ilSelectInputGUI($this->lng->txt('roles_without_starting_point'), 'role');
217 $si_roles->setOptions($role_options);
218 $op1->addSubItem($si_roles);
219 }
220
221 $op2 = new \ilRadioOption($this->lng->txt('user_local_role'), '1');
222 $radg->addOption($op2);
223 $role_search = new \ilRoleAutoCompleteInputGUI('', 'role_search', $this, 'addRoleAutoCompleteObject');
224 $role_search->setSize(40);
225 $op2->addSubItem($role_search);
226 return $radg;
227 }
228
229 private function getEditFormSpecificInputs(int $spoint_id, int $req_role_id): array
230 {
231 $title = $this->lng->txt('default');
232 if ($spoint_id !== $this->starting_point_repository->getDefaultStartingPointID()) {
233 $role = new \ilObjRole($req_role_id);
234 $title = $role->getTitle();
235 }
236
237 $inputs = [];
238 $inputs[0] = new \ilNonEditableValueGUI($this->lng->txt('editing_this_role'), 'role_disabled');
239 $inputs[0]->setValue($title);
240
241 $inputs[1] = new \ilHiddenInputGUI('role');
242 $inputs[1]->setValue((string) $req_role_id);
243
244 $inputs[2] = new \ilHiddenInputGUI('start_point_id');
245 $inputs[2]->setValue((string) $spoint_id);
246
247 return $inputs;
248 }
249
251 {
252 $si = new \ilRadioGroupInputGUI($this->lng->txt('adm_user_starting_point'), 'start_point');
253 $si->setRequired(true);
254 $si->setInfo($this->lng->txt('adm_user_starting_point_info'));
255 $valid = array_keys($this->starting_point_repository->getPossibleStartingPoints());
256 foreach ($this->starting_point_repository->getPossibleStartingPoints(true) as $value => $caption) {
257 $si->addOption(
258 $this->getStartingPointSelectionOption($value, $caption, $st_point, $valid)
259 );
260 }
261
262 return $si;
263 }
264
266 int $value,
267 string $caption,
268 ?StartingPoint $st_point,
269 array $valid
270 ): \ilRadioOption {
271 $opt = new \ilRadioOption($this->lng->txt($caption), (string) $value);
272
273 if ($value === Repository::START_PD_CALENDAR) {
274 $opt->addSubItem(
275 $this->getCalenderSubInputs($st_point)
276 );
277 }
278
279 if ($value === Repository::START_REPOSITORY_OBJ) {
280 $opt->addSubItem(
281 $this->getRepositoryObjectInput($st_point)
282 );
283 }
284
285 if (!in_array($value, $valid)) {
286 $opt->setInfo($this->lng->txt('adm_user_starting_point_invalid_info'));
287 }
288
289 return $opt;
290 }
291
293 {
294 $default_cal_view = new \ilRadioGroupInputGUI($this->lng->txt('cal_def_view'), 'user_calendar_view');
295 $default_cal_view->setRequired(true);
296
297 $day = new \ilRadioOption($this->lng->txt('day'), (string) \ilCalendarSettings::DEFAULT_CAL_DAY);
298 $default_cal_view->addOption($day);
299 $week = new \ilRadioOption($this->lng->txt('week'), (string) \ilCalendarSettings::DEFAULT_CAL_WEEK);
300 $default_cal_view->addOption($week);
301 $month = new \ilRadioOption($this->lng->txt('month'), (string) \ilCalendarSettings::DEFAULT_CAL_MONTH);
302 $default_cal_view->addOption($month);
303
304 $list = new \ilRadioOption($this->lng->txt('cal_list'), (string) \ilCalendarSettings::DEFAULT_CAL_LIST);
305
306 $cal_periods = new \ilSelectInputGUI($this->lng->txt('cal_list'), 'user_cal_period');
307 $cal_periods->setOptions([
308 \ilCalendarAgendaListGUI::PERIOD_DAY => '1 ' . $this->lng->txt('day'),
309 \ilCalendarAgendaListGUI::PERIOD_WEEK => '1 ' . $this->lng->txt('week'),
310 \ilCalendarAgendaListGUI::PERIOD_MONTH => '1 ' . $this->lng->txt('month'),
311 \ilCalendarAgendaListGUI::PERIOD_HALF_YEAR => '6 ' . $this->lng->txt('months')
312 ]);
313 $cal_periods->setRequired(true);
314
315 if ($st_point !== null) {
316 $default_cal_view->setValue((string) $st_point->getCalendarView());
317 $cal_periods->setValue((string) $st_point->getCalendarPeriod());
318 }
319
320 $list->addSubItem($cal_periods);
321 $default_cal_view->addOption($list);
322
323 return $default_cal_view;
324 }
325
327 {
328 $repobj_id = new \ilTextInputGUI($this->lng->txt('adm_user_starting_point_ref_id'), 'start_object');
329 $repobj_id->setRequired(true);
330 $repobj_id->setSize(5);
331
332 if ($st_point !== null) {
333 $start_ref_id = $st_point->getStartingObject();
334 $repobj_id->setValue($start_ref_id);
335 }
336
337 if (isset($start_ref_id)) {
338 $start_obj_id = \ilObject::_lookupObjId($start_ref_id);
339 if ($start_obj_id) {
340 $repobj_id->setInfo($this->lng->txt('obj_' . \ilObject::_lookupType($start_obj_id)) .
341 ': ' . \ilObject::_lookupTitle($start_obj_id));
342 }
343 }
344
345 return $repobj_id;
346 }
347
348 public function addRoleAutoCompleteObject(): void
349 {
351 }
352
356 protected function saveStartingPoint(): void
357 {
358 if (!$this->rbac_system->checkAccess('write', $this->parent_ref_id)) {
359 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->FATAL);
360 }
361
362 $start_point_id = $this->user_request->getStartingPointId();
363
364 //add from form
365 $form = $this->getRoleStartingPointForm();
366
367 if (!$form->checkInput()) {
368 $form->setValuesByPost();
369 $this->tpl->setContent($form->getHTML());
370 return;
371 }
372
373 $starting_point = $this->starting_point_repository->getStartingPointById(
374 $start_point_id
375 );
376
377
378 $role_id = $this->user_request->getRoleId();
379
380 if ($form->getInput('role_type') === '1'
381 && ($role_id === null || $role_id < 1)) {
382 $parser = new \ilQueryParser($form->getInput('role_search'));
383
384 // TODO: Handle minWordLength
385 $parser->setMinWordLength(1);
386 $parser->setCombination(\ilQueryParser::QP_COMBINATION_AND);
387 $parser->parse();
388
389 $object_search = new \ilLikeObjectSearch($parser);
390 $object_search->setFilter(['role']);
391 $res = $object_search->performSearch();
392
393 $entries = $res->getEntries();
394
395 if ($entries === []) {
396 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_corresponding_roles'), true);
397 $form->setValuesByPost();
398 $this->tpl->setContent($form->getHTML());
399 return;
400 }
401
402 if (count($entries) > 1) {
403 $this->showRoleSelection(
404 $form->getInput('role'),
405 $form->getInput('role_search'),
406 $form->getInput('start_point'),
407 $form->getInput('start_object')
408 );
409 return;
410 }
411
412 if (count($entries) === 1) {
413 $role = current($entries);
414 $role_id = $role['obj_id'];
415 }
416 }
417
418 if ($role_id === 0) {
419 $role_id = $form->getInput('role');
420 }
421
422 if ($role_id !== 0) {
423 $starting_point->setRuleTypeRoleBased();
424 $rules = ['role_id' => $role_id];
425 $starting_point->setRuleOptions(serialize($rules));
426 }
427
428 $starting_point->setStartingPointType((int) $form->getInput('start_point'));
429
430 $obj_id = (int) $form->getInput('start_object');
431 $cal_view = (int) $form->getInput('user_calendar_view');
432 $cal_period = (int) $form->getInput('user_cal_period');
433
434
435 if ($starting_point->getStartingPointType() === Repository::START_REPOSITORY_OBJ
436 && (\ilObject::_lookupObjId($obj_id) === 0 || $this->tree->isDeleted($obj_id))) {
437 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('obj_ref_id_not_exist'), true);
438 $form->setValuesByPost();
439 $this->tpl->setContent($form->getHTML());
440 return;
441 }
442 $starting_point->setStartingObject($obj_id);
443
444 if ($starting_point->getStartingPointType() === Repository::START_PD_CALENDAR) {
445 $starting_point->setCalendarView($cal_view);
446 $starting_point->setCalendarPeriod($cal_period);
447 }
448
449 if ($start_point_id !== null) {
450 $this->starting_point_repository->update($starting_point);
451 } else {
452 $this->starting_point_repository->save($starting_point);
453 }
454
455 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
456 $this->ctrl->redirect($this, 'startingPoints');
457 }
458
459 private function showRoleSelection(
460 string $role,
461 string $role_search,
462 string $start_point,
463 string $start_object
464 ): void {
465 $parser = new \ilQueryParser($role_search);
466 $parser->setMinWordLength(1);
467 $parser->setCombination(\ilQueryParser::QP_COMBINATION_AND);
468 $parser->parse();
469
470 $object_search = new \ilLikeObjectSearch($parser);
471 $object_search->setFilter(['role']);
472 $res = $object_search->performSearch();
473
474 $entries = $res->getEntries();
475
476 $table = new \ilRoleSelectionTableGUI($this, 'saveStartingPoint');
477 $table->setLimit(9999);
478 $table->disable('sort');
479 $table->addHiddenInput('role_search', $role_search);
480 $table->addHiddenInput('start_point', $start_point);
481 $table->addHiddenInput('start_object', $start_object);
482 $table->addHiddenInput('role', $role);
483 $table->addHiddenInput('role_type', '1');
484 $table->setTitle($this->lng->txt('user_role_selection'));
485 $table->addMultiCommand('saveStartingPoint', $this->lng->txt('select'));
486 $table->parse($entries);
487
488 $this->tpl->setContent($table->getHTML());
489 }
490
491 public function saveOrder(): void
492 {
493 if (!$this->rbac_system->checkAccess('write', $this->parent_ref_id)) {
494 throw new \ilPermissionException($this->lng->txt('msg_no_perm_read'));
495 }
496
497 $positions = $this->user_request->getPositions();
498 if (count($positions) > 0) {
499 $this->starting_point_repository->saveOrder($positions);
500 }
501
502 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
503 $this->ctrl->redirect($this, 'startingPoints');
504 }
505
506 protected function deleteStartingPoint(): void
507 {
508 if (!$this->rbac_system->checkAccess('write', $this->parent_ref_id)) {
509 throw new \ilPermissionException($this->lng->txt('msg_no_perm_read'));
510 }
511
512 $spoint_id = $this->user_request->getStartingPointId();
513 $req_role_id = $this->user_request->getRoleId();
514
515 if ($req_role_id && is_numeric($spoint_id)) {
516 $sp = $this->starting_point_repository->getStartingPointById(
517 $spoint_id
518 );
519 $this->starting_point_repository->delete($sp->getId());
520 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
521 } else {
522 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_spoint_not_modified'), true);
523 }
524 $this->ctrl->redirect($this, 'startingPoints');
525 }
526}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
initUserStartingPointForm(?\ilPropertyFormGUI $form=null)
getStartingPointSelectionOption(int $value, string $caption, ?StartingPoint $st_point, array $valid)
saveStartingPoint()
store starting point from the form
showRoleSelection(string $role, string $role_search, string $start_point, string $start_object)
startingPoints()
table form to set up starting points depends of user roles
getStartingPointSelectionInput(?StartingPoint $st_point)
initRoleStartingPointForm(?\ilPropertyFormGUI $form=null)
getFormTypeSpecificStartingPointFormParts(?int $spoint_id, ?int $req_role_id)
getCurrentStartingPointOrNullForStartingPointForm(?int $starting_point_id)
getCurrentTypeForStartingPointForm(?StartingPoint $starting_point)
getEditFormSpecificInputs(int $spoint_id, int $req_role_id)
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
error(string $a_errmsg)
static getLogger(string $a_component_id)
Get component logger.
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.
setMinWordLength(int $a_length)
This class represents a property in a property form.
This class represents an option in a radio group.
static echoAutoCompleteList()
Static asynchronous default auto complete function.
This class represents a text property in a property form.
$valid
An entity that renders components to a string output.
Definition: Renderer.php:31
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26