ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilUserStartingPointGUI.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  protected ilCtrl $ctrl;
29  protected \ILIAS\User\StandardGUIRequest $user_request;
30  protected ilLogger $log;
31  protected ilLanguage $lng;
33  protected int $parent_ref_id;
34 
35  public function __construct(int $a_parent_ref_id)
36  {
37  global $DIC;
38 
39  $lng = $DIC['lng'];
40  $tpl = $DIC['tpl'];
41  $ilToolbar = $DIC['ilToolbar'];
42  $ilCtrl = $DIC['ilCtrl'];
43 
44  $this->log = ilLoggerFactory::getLogger("user");
45  $this->lng = $lng;
46  $this->tpl = $tpl;
47  $this->toolbar = $ilToolbar;
48  $this->ctrl = $ilCtrl;
49  $this->parent_ref_id = $a_parent_ref_id;
50  $this->lng->loadLanguageModule("administration");
51  $this->lng->loadLanguageModule("dateplaner");
52  $this->user_request = new \ILIAS\User\StandardGUIRequest(
53  $DIC->http(),
54  $DIC->refinery()
55  );
56  }
57 
58  public function executeCommand(): void
59  {
60  global $DIC;
61 
62  $ilCtrl = $DIC['ilCtrl'];
63 
64  $cmd = $ilCtrl->getCmd();
65  if ($cmd == "roleStartingPointform" || !$cmd) {
66  $cmd = "initRoleStartingPointForm";
67  }
68 
69  $this->$cmd();
70  }
71 
75  public function startingPoints(): void
76  {
78 
79  if (!empty($roles_without_point)) {
80  $this->toolbar->addButton(
81  $this->lng->txt('create_starting_point'),
82  $this->ctrl->getLinkTarget($this, "roleStartingPointform")
83  );
84  } else {
85  $this->tpl->setOnScreenMessage('info', $this->lng->txt("all_roles_has_starting_point"));
86  }
87 
88 
89  $tbl = new ilUserRoleStartingPointTableGUI($this);
90 
91  $this->tpl->setContent($tbl->getHTML());
92  }
93 
94  public function initUserStartingPointForm(ilPropertyFormGUI $form = null): void
95  {
96  if (!($form instanceof ilPropertyFormGUI)) {
97  $form = $this->getUserStartingPointForm();
98  }
99  $this->tpl->setContent($form->getHTML());
100  }
101 
102  public function initRoleStartingPointForm(ilPropertyFormGUI $form = null): void
103  {
104  if (!($form instanceof ilPropertyFormGUI)) {
105  $form = $this->getRoleStartingPointForm();
106  }
107  $this->tpl->setContent($form->getHTML());
108  }
109 
111  {
112  global $DIC;
113 
114  $ilCtrl = $DIC['ilCtrl'];
115 
116  $form = new ilPropertyFormGUI();
117 
118  // starting point: personal
119  $startp = new ilCheckboxInputGUI($this->lng->txt("user_chooses_starting_page"), "usr_start_pers");
120  $startp->setInfo($this->lng->txt("adm_user_starting_point_personal_info"));
121  $startp->setChecked(ilUserUtil::hasPersonalStartingPoint());
122 
123  $form->addItem($startp);
124 
125  $form->addCommandButton("saveUserStartingPoint", $this->lng->txt("save"));
126  $form->setFormAction($ilCtrl->getFormAction($this));
127 
128  return $form;
129  }
130 
135  {
136  global $DIC;
137 
138  $ilCtrl = $DIC['ilCtrl'];
139  $rbacsystem = $DIC['rbacsystem'];
140  $ilErr = $DIC['ilErr'];
141  $options = [];
142  $starting_point = 0;
143  $st_point = null;
144 
145  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
146  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
147  }
148  $form = new ilPropertyFormGUI();
149  $ilCtrl->saveParameter($this, array("spid"));
150 
151  $spoint_id = $this->user_request->getStartingPointId();
152  $req_role_id = $this->user_request->getRoleId();
153 
154  if ($spoint_id === 'default') {
155  $starting_point = ilUserUtil::getStartingPoint();
156  } elseif (is_numeric($spoint_id) && intval($spoint_id) > 0) {
157  $st_point = new ilStartingPoint((int) $spoint_id);
158 
159  //starting point role based
160  if ($st_point->getRuleType() === ilStartingPoint::ROLE_BASED
161  && is_numeric($req_role_id) && intval($req_role_id) > 0
162  && ($role = new ilObjRole((int) $req_role_id))) {
163  $options[$req_role_id] = $role->getTitle();
164  $starting_point = $st_point->getStartingPoint();
165 
166  // role title, non editable
167  $ne = new ilNonEditableValueGUI($this->lng->txt("editing_this_role"), 'role_disabled');
168  $ne->setValue($role->getTitle());
169  $form->addItem($ne);
170 
171  $hi = new ilHiddenInputGUI("role");
172  $hi->setValue($req_role_id);
173  $form->addItem($hi);
174 
175  $hidde_sp_id = new ilHiddenInputGUI("start_point_id");
176  $hidde_sp_id->setValue($spoint_id);
177  $form->addItem($hidde_sp_id);
178  }
179  } else {
180  //starting point role based
183 
184  // role type
185  $radg = new ilRadioGroupInputGUI($this->lng->txt("role"), "role_type");
186  $radg->setValue(0);
187  $op1 = new ilRadioOption($this->lng->txt("user_global_role"), 0);
188  $radg->addOption($op1);
189  $op2 = new ilRadioOption($this->lng->txt("user_local_role"), 1);
190  $radg->addOption($op2);
191  $form->addItem($radg);
192 
193  foreach ($roles as $role) {
194  $options[$role['id']] = $role['title'];
195  }
196  $si_roles = new ilSelectInputGUI($this->lng->txt("roles_without_starting_point"), 'role');
197  $si_roles->setOptions($options);
198  $op1->addSubItem($si_roles);
199 
200  // local role
201  $role_search = new ilRoleAutoCompleteInputGUI('', 'role_search', $this, 'addRoleAutoCompleteObject');
202  $role_search->setSize(40);
203  $op2->addSubItem($role_search);
204  }
205  }
206 
207  // starting point
208 
209  $si = new ilRadioGroupInputGUI($this->lng->txt("adm_user_starting_point"), "start_point");
210  $si->setRequired(true);
211  $si->setInfo($this->lng->txt("adm_user_starting_point_info"));
213  foreach (ilUserUtil::getPossibleStartingPoints(true) as $value => $caption) {
214  if ($value === ilUserUtil::START_REPOSITORY_OBJ) {
215  continue;
216  }
217  $opt = new ilRadioOption($caption, $value);
218 
219  if ($value === ilUserUtil::START_PD_CALENDAR) {
220  $default_cal_view = new ilRadioGroupInputGUI($this->lng->txt('cal_def_view'), 'user_calendar_view');
221  $default_cal_view->setRequired(true);
222 
223  $option = new ilRadioOption($this->lng->txt("day"), ilCalendarSettings::DEFAULT_CAL_DAY);
224  $default_cal_view->addOption($option);
225  $option = new ilRadioOption($this->lng->txt("week"), ilCalendarSettings::DEFAULT_CAL_WEEK);
226  $default_cal_view->addOption($option);
227  $option = new ilRadioOption($this->lng->txt("month"), ilCalendarSettings::DEFAULT_CAL_MONTH);
228  $default_cal_view->addOption($option);
229 
230  $option = new ilRadioOption($this->lng->txt("cal_list"), ilCalendarSettings::DEFAULT_CAL_LIST);
231 
232  $cal_periods = new ilSelectInputGUI($this->lng->txt("cal_list"), "user_cal_period");
233  $cal_periods->setOptions([
234  ilCalendarAgendaListGUI::PERIOD_DAY => "1 " . $this->lng->txt("day"),
235  ilCalendarAgendaListGUI::PERIOD_WEEK => "1 " . $this->lng->txt("week"),
236  ilCalendarAgendaListGUI::PERIOD_MONTH => "1 " . $this->lng->txt("month"),
237  ilCalendarAgendaListGUI::PERIOD_HALF_YEAR => "6 " . $this->lng->txt("months")
238  ]);
239  $cal_periods->setRequired(true);
240 
241 
242  if (isset($st_point)) {
243  $default_cal_view->setValue($st_point->getCalendarView());
244  $cal_periods->setValue($st_point->getCalendarPeriod());
245  } else {
246  $default_cal_view->setValue(ilUserUtil::getCalendarView());
247  $cal_periods->setValue(ilUserUtil::getCalendarPeriod());
248  }
249  $option->addSubItem($cal_periods);
250  $default_cal_view->addOption($option);
251 
252  $opt->addSubItem($default_cal_view);
253  }
254 
255  $si->addOption($opt);
256 
257  if (!in_array($value, $valid)) {
258  $opt->setInfo($this->lng->txt("adm_user_starting_point_invalid_info"));
259  }
260  }
261  $si->setValue($starting_point);
262  $form->addItem($si);
263 
264  // starting point: repository object
265  $repobj = new ilRadioOption($this->lng->txt("adm_user_starting_point_object"), ilUserUtil::START_REPOSITORY_OBJ);
266  $repobj_id = new ilTextInputGUI($this->lng->txt("adm_user_starting_point_ref_id"), "start_object");
267  $repobj_id->setRequired(true);
268  $repobj_id->setSize(5);
269  //$i has the starting_point value, so we are here only when edit one role or setting the default role.
270  if ($si->getValue() == ilUserUtil::START_REPOSITORY_OBJ) {
271  if ($st_point) {
272  $start_ref_id = $st_point->getStartingObject();
273  } else {
274  $start_ref_id = ilUserUtil::getStartingObject();
275  }
276 
277  $repobj_id->setValue($start_ref_id);
278  if ($start_ref_id) {
279  $start_obj_id = ilObject::_lookupObjId($start_ref_id);
280  if ($start_obj_id) {
281  $repobj_id->setInfo($this->lng->txt("obj_" . ilObject::_lookupType($start_obj_id)) .
282  ": " . ilObject::_lookupTitle($start_obj_id));
283  }
284  }
285  }
286  $repobj->addSubItem($repobj_id);
287  $si->addOption($repobj);
288 
289  // save and cancel commands
290  $form->addCommandButton("saveStartingPoint", $this->lng->txt("save"));
291  $form->addCommandButton("startingPoints", $this->lng->txt("cancel"));
292 
293  $form->setTitle($this->lng->txt("starting_point_settings"));
294  $form->setFormAction($ilCtrl->getFormAction($this));
295 
296  return $form;
297  }
298 
299  public function addRoleAutoCompleteObject(): void
300  {
302  }
303 
304  protected function saveUserStartingPoint(): void
305  {
306  global $DIC;
307 
308  $ilCtrl = $DIC['ilCtrl'];
309  $rbacsystem = $DIC['rbacsystem'];
310  $ilErr = $DIC['ilErr'];
311 
312  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
313  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
314  }
315 
316  $form = $this->getUserStartingPointForm();
317 
318  if ($form->checkInput()) {
319  ilUserUtil::togglePersonalStartingPoint($form->getInput('usr_start_pers'));
320  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
321  $ilCtrl->redirect($this, "startingPoints");
322  }
323  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_error"), true);
324  $ilCtrl->redirect($this, "startingPoints");
325  }
326 
330  protected function saveStartingPoint(): void
331  {
332  global $DIC;
333 
334  $ilCtrl = $DIC['ilCtrl'];
335  $tree = $DIC['tree'];
336  $rbacsystem = $DIC['rbacsystem'];
337  $ilErr = $DIC['ilErr'];
338  $tpl = $DIC['tpl'];
339  $start_point_id = 0;
340 
341  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
342  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
343  }
344 
345  if ($this->user_request->getStartingPointId() > 0) {
346  $start_point_id = $this->user_request->getStartingPointId();
347  }
348 
349  //add from form
350  $form = $this->getRoleStartingPointForm();
351  if ($form->checkInput()) {
352  //if role
353  if ($form->getInput('role')) {
354 
355  // check if we have a locale role
356  if ($form->getInput('role_type') == 1) {
357  if ($this->user_request->getRoleId() > 0) {
358  $role_id = $this->user_request->getRoleId(); // id from role selection
359  } else {
360  $parser = new ilQueryParser($form->getInput('role_search'));
361 
362  // TODO: Handle minWordLength
363  $parser->setMinWordLength(1);
364  $parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
365  $parser->parse();
366 
367  $object_search = new ilLikeObjectSearch($parser);
368  $object_search->setFilter(array('role'));
369  $res = $object_search->performSearch();
370 
371  $entries = $res->getEntries();
372  if (count($entries) == 1) { // role name only finds one match -> use it
373  $role = current($entries);
374  $role_id = $role['obj_id'];
375  } elseif (count($entries) > 1) { // multiple matches -> show selection
376  $this->showRoleSelection(
377  $form->getInput('role'),
378  $form->getInput('role_search'),
379  $form->getInput('start_point'),
380  $form->getInput('start_object')
381  );
382  return;
383  }
384  }
385  } else {
386  $role_id = $form->getInput('role');
387  }
388 
389  //create starting point
390  if ($start_point_id) {
391  $starting_point = new ilStartingPoint($start_point_id);
392  } else { //edit
393  $starting_point = new ilStartingPoint();
394  }
395  $starting_point->setRuleType(ilStartingPoint::ROLE_BASED);
396  $starting_point->setStartingPoint((int) $form->getInput("start_point"));
397  $rules = array("role_id" => $role_id);
398  $starting_point->setRuleOptions(serialize($rules));
399 
400  $obj_id = $form->getInput('start_object');
401  $cal_view = $form->getInput("user_calendar_view");
402  $cal_period = $form->getInput("user_cal_period");
403  if ($obj_id && ($starting_point->getStartingPoint() == ilUserUtil::START_REPOSITORY_OBJ)) {
404  if (ilObject::_lookupObjId($obj_id) && !$tree->isDeleted($obj_id)) {
405  $starting_point->setStartingObject($obj_id);
406  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
407  } else {
408  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("obj_ref_id_not_exist"), true);
409  }
410  } else {
411  $starting_point->setStartingObject(0);
412  }
413 
414  if (!empty($cal_view) && !empty($cal_period) && ($starting_point->getStartingPoint() == ilUserUtil::START_PD_CALENDAR)) {
415  $starting_point->setCalendarView($cal_view);
416  $starting_point->setCalendarPeriod($cal_period);
417  } else {
418  $starting_point->setCalendarView(0);
419  $starting_point->setCalendarPeriod(0);
420  }
421 
422  if ($start_point_id) {
423  $starting_point->update();
424  } else {
425  $starting_point->save();
426  }
427  } elseif (!empty($form->getInput("user_calendar_view")) && !empty($form->getInput("user_cal_period"))) {
428  $calendar_info = [
429  "user_calendar_view" => $form->getInput("user_calendar_view"),
430  "user_cal_period" => $form->getInput("user_cal_period")
431  ];
432  ilUserUtil::setStartingPoint($form->getInput('start_point'), (int) $form->getInput('start_object'), $calendar_info);
433  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
434  } else { //default
435  ilUserUtil::setStartingPoint($form->getInput('start_point'), (int) $form->getInput('start_object'));
436  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
437  }
438 
439  $ilCtrl->redirect($this, "startingPoints");
440  }
441  $form->setValuesByPost();
442  $tpl->setContent($form->getHTML());
443  }
444 
445  protected function showRoleSelection(
446  string $role,
447  string $role_search,
448  string $start_point,
449  string $start_object
450  ): void {
451  $parser = new ilQueryParser($role_search);
452  $parser->setMinWordLength(1);
453  $parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
454  $parser->parse();
455 
456  $object_search = new ilLikeObjectSearch($parser);
457  $object_search->setFilter(array('role'));
458  $res = $object_search->performSearch();
459 
460  $entries = $res->getEntries();
461 
462  $table = new ilRoleSelectionTableGUI($this, 'saveStartingPoint');
463  $table->setLimit(9999);
464  $table->disable("sort");
465  $table->addHiddenInput("role_search", $role_search);
466  $table->addHiddenInput("start_point", $start_point);
467  $table->addHiddenInput("start_object", $start_object);
468  $table->addHiddenInput("role", $role);
469  $table->addHiddenInput("role_type", 1);
470  $table->setTitle($this->lng->txt('user_role_selection'));
471  $table->addMultiCommand('saveStartingPoint', $this->lng->txt('select'));
472  $table->parse($entries);
473 
474  $this->tpl->setContent($table->getHTML());
475  }
476 
477  public function saveOrder(): void
478  {
479  global $DIC;
480 
481  $ilCtrl = $DIC['ilCtrl'];
482  $rbacsystem = $DIC['rbacsystem'];
483 
484  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
485  throw new ilPermissionException($this->lng->txt("msg_no_perm_read"));
486  }
487 
488  $positions = $this->user_request->getPositions();
489  if (count($positions) > 0) {
490  $sp = new ilStartingPoint();
491  $sp->saveOrder($positions);
492  }
493 
494  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
495  $ilCtrl->redirect($this, "startingPoints");
496  }
497 
501  public function confirmDeleteStartingPoint(): void
502  {
503  global $DIC;
504 
505  $ilCtrl = $DIC['ilCtrl'];
506  $lng = $DIC['lng'];
507  $tpl = $DIC['tpl'];
508  $ilTabs = $DIC['ilTabs'];
509 
510  $ilTabs->clearTargets();
511  $ilTabs->setBackTarget($lng->txt('back_to_starting_points_list'), $ilCtrl->getLinkTarget($this, 'startingPoints'));
512 
513  $conf = new ilConfirmationGUI();
514  $conf->setFormAction($ilCtrl->getFormAction($this));
515  $conf->setHeaderText($lng->txt('confirm_delete_starting_point'));
516 
517  $req_role_id = $this->user_request->getRoleId();
518  $req_sp_id = $this->user_request->getStartingPointId();
519 
520  //if type role based
521  if ($req_role_id && $req_sp_id) {
522  $rolid = $req_role_id;
523  $spid = $req_sp_id;
524 
525  $role = new ilObjRole($rolid);
526 
527  $conf->addItem('rolid', $rolid, $role->getTitle());
528  $conf->addItem('spid', $spid, "");
529  }
530 
531  $conf->setConfirm($lng->txt('delete'), 'deleteStartingPoint');
532  $conf->setCancel($lng->txt('cancel'), 'startingPoints');
533 
534  $tpl->setContent($conf->getHTML());
535  }
536 
540  protected function deleteStartingPoint(): void
541  {
542  global $DIC;
543 
544  $ilCtrl = $DIC['ilCtrl'];
545  $rbacsystem = $DIC['rbacsystem'];
546  $spid = 0;
547 
548  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
549  throw new ilPermissionException($this->lng->txt("msg_no_perm_read"));
550  }
551 
552  $spoint_id = $this->user_request->getStartingPointId();
553  $req_role_id = $this->user_request->getRoleId();
554 
555  if ($req_role_id && $spid = $spoint_id) {
556  $sp = new ilStartingPoint($spid);
557  $sp->delete();
558  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
559  } else {
560  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_spoint_not_modified"), true);
561  }
562  $ilCtrl->redirect($this, "startingPoints");
563  }
564 }
Class ilObjRole.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
static getLogger(string $a_component_id)
Get component logger.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Class ilStartingPoint.
saveStartingPoint()
store starting point from the form
setInfo(string $a_info)
$valid
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
static getGlobalRolesWithoutStartingPoint()
Get id and title of the roles without starting points.
static getStartingPoint()
Get current starting point setting.
ILIAS User StandardGUIRequest $user_request
ilGlobalTemplateInterface $tpl
showRoleSelection(string $role, string $role_search, string $start_point, string $start_object)
$ilErr
Definition: raiseError.php:17
static hasPersonalStartingPoint()
Can starting point be personalized?
initRoleStartingPointForm(ilPropertyFormGUI $form=null)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
setMinWordLength(int $a_length)
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...
startingPoints()
table form to set up starting points depends of user roles
static getPossibleStartingPoints(bool $a_force_all=false)
Get all valid starting points.
This class represents a property in a property form.
static echoAutoCompleteList()
Static asynchronous default auto complete function.
confirmDeleteStartingPoint()
Confirm delete starting point.
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
initUserStartingPointForm(ilPropertyFormGUI $form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValue(string $a_value)
static getStartingObject()
Get ref id of starting object.
setRequired(bool $a_required)
const START_PD_CALENDAR
deleteStartingPoint()
Set to 0 the starting point values.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setStartingPoint(int $a_value, int $a_ref_id=null, array $a_cal_view=[])
Set starting point setting.
static getCalendarPeriod()
Get time frame of calendar view.
static togglePersonalStartingPoint(bool $a_value)
Toggle personal starting point setting.
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...
static getCalendarView()
Get specific view of calendar starting point.
const START_REPOSITORY_OBJ
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...