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