ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilUserStartingPointGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
15 protected $log;
16 protected $lng;
17 protected $tpl;
18 protected $parent_ref_id;
19
24 public function __construct($a_parent_ref_id)
25 {
26 global $DIC;
27
28 $lng = $DIC['lng'];
29 $tpl = $DIC['tpl'];
30 $ilToolbar = $DIC['ilToolbar'];
31 $ilCtrl = $DIC['ilCtrl'];
32
33 $this->log = ilLoggerFactory::getLogger("user");
34 $this->lng = $lng;
35 $this->tpl = $tpl;
36 $this->toolbar = $ilToolbar;
37 $this->ctrl = $ilCtrl;
38 $this->parent_ref_id = $a_parent_ref_id;
39 $this->lng->loadLanguageModule("administration");
40 $this->lng->loadLanguageModule("dateplaner");
41 }
42 public function &executeCommand()
43 {
44 global $DIC;
45
46 $ilCtrl = $DIC['ilCtrl'];
47
48 $cmd = $ilCtrl->getCmd();
49 if ($cmd == "roleStartingPointform" || !$cmd) {
50 $cmd = "initRoleStartingPointForm";
51 }
52
53 $this->$cmd();
54
55 return true;
56 }
57
61 public function startingPoints()
62 {
63 include_once "Services/User/classes/class.ilUserRoleStartingPointTableGUI.php";
64
65 require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
67
68 if (!empty($roles_without_point)) {
69 $this->toolbar->addButton(
70 $this->lng->txt('create_starting_point'),
71 $this->ctrl->getLinkTarget($this, "roleStartingPointform")
72 );
73 } else {
74 ilUtil::sendInfo($this->lng->txt("all_roles_has_starting_point"));
75 }
76
77
78 $tbl = new ilUserRoleStartingPointTableGUI($this);
79
80 $this->tpl->setContent($tbl->getHTML());
81 }
82
83 public function initUserStartingPointForm(ilPropertyFormGUI $form = null)
84 {
85 if (!($form instanceof ilPropertyFormGUI)) {
86 $form = $this->getUserStartingPointForm();
87 }
88 $this->tpl->setContent($form->getHTML());
89 }
90
91 public function initRoleStartingPointForm(ilPropertyFormGUI $form = null)
92 {
93 if (!($form instanceof ilPropertyFormGUI)) {
94 $form = $this->getRoleStartingPointForm();
95 }
96 $this->tpl->setContent($form->getHTML());
97 }
98
99 protected function getUserStartingPointForm()
100 {
101 global $DIC;
102
103 $ilCtrl = $DIC['ilCtrl'];
104
105 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
106 require_once "Services/User/classes/class.ilUserUtil.php";
107
108 $form = new ilPropertyFormGUI();
109
110 // starting point: personal
111 $startp = new ilCheckboxInputGUI($this->lng->txt("user_chooses_starting_page"), "usr_start_pers");
112 $startp->setInfo($this->lng->txt("adm_user_starting_point_personal_info"));
113 $startp->setChecked(ilUserUtil::hasPersonalStartingPoint());
114
115 $form->addItem($startp);
116
117 $form->addCommandButton("saveUserStartingPoint", $this->lng->txt("save"));
118 $form->setFormAction($ilCtrl->getFormAction($this));
119
120 return $form;
121 }
122
126 protected function getRoleStartingPointForm()
127 {
128 global $DIC;
129
130 $ilCtrl = $DIC['ilCtrl'];
131 $rbacsystem = $DIC['rbacsystem'];
132 $ilErr = $DIC['ilErr'];
133
134 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
135 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
136 }
137
138 require_once "Services/Form/classes/class.ilPropertyFormGUI.php";
139 require_once "./Services/AccessControl/classes/class.ilObjRole.php";
140 require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
141 include_once "Services/User/classes/class.ilUserUtil.php";
142
143 $form = new ilPropertyFormGUI();
144 $ilCtrl->saveParameter($this, array("spid"));
145
146 $spoint_id = $_REQUEST['spid'];
147
148 //edit no default
149 if ($spoint_id > 0 && $spoint_id != 'default') {
150 $st_point = new ilStartingPoint($spoint_id);
151
152 //starting point role based
153 if ($st_point->getRuleType() == ilStartingPoint::ROLE_BASED && $_REQUEST['rolid']) {
154 $rolid = (int) $_REQUEST['rolid'];
155 if ($role = new ilObjRole($rolid)) {
156 $options[$rolid] = $role->getTitle();
157 $starting_point = $st_point->getStartingPoint();
158 $si_roles = new ilSelectInputGUI($this->lng->txt("editing_this_role"), 'role_disabled');
159 $si_roles->setOptions($options);
160 $si_roles->setDisabled(true);
161 $form->addItem($si_roles);
162
163 $hi = new ilHiddenInputGUI("role");
164 $hi->setValue($rolid);
165 $form->addItem($hi);
166
167 $hidde_sp_id = new ilHiddenInputGUI("start_point_id");
168 $hidde_sp_id->setValue($spoint_id);
169 $form->addItem($hidde_sp_id);
170 }
171 }
172 }
173 //create
174 elseif (!$spoint_id || $spoint_id != 'default') {
175 //starting point role based
178
179 foreach ($roles as $role) {
180 $options[$role['id']] = $role['title'];
181 }
182 $si_roles = new ilSelectInputGUI($this->lng->txt("roles_without_starting_point"), 'role');
183 $si_roles->setOptions($options);
184 $form->addItem($si_roles);
185 }
186 } else {
187 $starting_point = ilUserUtil::getStartingPoint();
188 }
189
190 // starting point
191
192 $si = new ilRadioGroupInputGUI($this->lng->txt("adm_user_starting_point"), "start_point");
193 $si->setRequired(true);
194 $si->setInfo($this->lng->txt("adm_user_starting_point_info"));
196 foreach (ilUserUtil::getPossibleStartingPoints(true) as $value => $caption) {
197 $opt = new ilRadioOption($caption, $value);
198
199 if ($value === ilUserUtil::START_PD_CALENDAR) {
200
201 $default_cal_view = new ilRadioGroupInputGUI($this->lng->txt('cal_def_view'), 'user_calendar_view');
202 $default_cal_view->setRequired(true);
203
204 $option = new ilRadioOption($this->lng->txt("day"), ilCalendarSettings::DEFAULT_CAL_DAY);
205 $default_cal_view->addOption($option);
206 $option = new ilRadioOption($this->lng->txt("week"), ilCalendarSettings::DEFAULT_CAL_WEEK);
207 $default_cal_view->addOption($option);
208 $option = new ilRadioOption($this->lng->txt("month"), ilCalendarSettings::DEFAULT_CAL_MONTH);
209 $default_cal_view->addOption($option);
210
211 $option = new ilRadioOption($this->lng->txt("cal_list"), ilCalendarSettings::DEFAULT_CAL_LIST);
212
213 $cal_periods = new ilSelectInputGUI($this->lng->txt("cal_list"), "user_cal_period");
214 $cal_periods->setOptions([
215 ilCalendarAgendaListGUI::PERIOD_DAY => "1 " . $this->lng->txt("day"),
216 ilCalendarAgendaListGUI::PERIOD_WEEK => "1 " . $this->lng->txt("week"),
217 ilCalendarAgendaListGUI::PERIOD_MONTH => "1 " . $this->lng->txt("month"),
218 ilCalendarAgendaListGUI::PERIOD_HALF_YEAR => "6 " . $this->lng->txt("months")
219 ]);
220 $cal_periods->setRequired(true);
221
222
223 if(isset($st_point)) {
224 $default_cal_view->setValue($st_point->getCalendarView());
225 $cal_periods->setValue($st_point->getCalendarPeriod());
226 } else {
227 $default_cal_view->setValue(ilUserUtil::getCalendarView());
228 $cal_periods->setValue(ilUserUtil::getCalendarPeriod());
229 }
230 $option->addSubItem($cal_periods);
231 $default_cal_view->addOption($option);
232
233 $opt->addSubItem($default_cal_view);
234 }
235
236 $si->addOption($opt);
237
238 if (!in_array($value, $valid)) {
239 $opt->setInfo($this->lng->txt("adm_user_starting_point_invalid_info"));
240 }
241 }
242 $si->setValue($starting_point);
243 $form->addItem($si);
244
245 // starting point: repository object
246 $repobj = new ilRadioOption($this->lng->txt("adm_user_starting_point_object"), ilUserUtil::START_REPOSITORY_OBJ);
247 $repobj_id = new ilTextInputGUI($this->lng->txt("adm_user_starting_point_ref_id"), "start_object");
248 $repobj_id->setRequired(true);
249 $repobj_id->setSize(5);
250 //$i has the starting_point value, so we are here only when edit one role or setting the default role.
251 if ($si->getValue() == ilUserUtil::START_REPOSITORY_OBJ) {
252 if ($st_point) {
253 $start_ref_id = $st_point->getStartingObject();
254 } else {
255 $start_ref_id = ilUserUtil::getStartingObject();
256 }
257
258 $repobj_id->setValue($start_ref_id);
259 if ($start_ref_id) {
260 $start_obj_id = ilObject::_lookupObjId($start_ref_id);
261 if ($start_obj_id) {
262 $repobj_id->setInfo($this->lng->txt("obj_" . ilObject::_lookupType($start_obj_id)) .
263 ": " . ilObject::_lookupTitle($start_obj_id));
264 }
265 }
266 }
267 $repobj->addSubItem($repobj_id);
268 $si->addOption($repobj);
269
270 // save and cancel commands
271 $form->addCommandButton("saveStartingPoint", $this->lng->txt("save"));
272 $form->addCommandButton("startingPoints", $this->lng->txt("cancel"));
273
274 $form->setTitle($this->lng->txt("starting_point_settings"));
275 $form->setFormAction($ilCtrl->getFormAction($this));
276
277 return $form;
278 }
279
280 protected function saveUserStartingPoint()
281 {
282 global $DIC;
283
284 $ilCtrl = $DIC['ilCtrl'];
285 $rbacsystem = $DIC['rbacsystem'];
286 $ilErr = $DIC['ilErr'];
287
288 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
289 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
290 }
291
292 include_once "Services/User/classes/class.ilUserUtil.php";
293
294 $form = $this->getUserStartingPointForm();
295
296 if ($form->checkInput()) {
297 ilUserUtil::togglePersonalStartingPoint($form->getInput('usr_start_pers'));
298 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
299 $ilCtrl->redirect($this, "startingPoints");
300 }
301 ilUtil::sendFailure($this->lng->txt("msg_error"), true);
302 $ilCtrl->redirect($this, "startingPoints");
303 }
304
308 protected function saveStartingPoint()
309 {
310 global $DIC;
311
312 $ilCtrl = $DIC['ilCtrl'];
313 $tree = $DIC['tree'];
314 $rbacsystem = $DIC['rbacsystem'];
315 $ilErr = $DIC['ilErr'];
316 $tpl = $DIC['tpl'];
317
318 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
319 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
320 }
321
322 if ((int) $_POST['start_point_id'] > 0) {
323 $start_point_id = (int) $_POST['start_point_id'];
324 }
325
326 //add from form
327 $form = $this->getRoleStartingPointForm();
328 if ($form->checkInput()) {
329 //if role
330 if ($form->getInput('role')) {
331
332 //create starting point
333 if ($start_point_id) {
334 $starting_point = new ilStartingPoint($start_point_id);
335 } else { //edit
336 $starting_point = new ilStartingPoint();
337 }
338 $starting_point->setRuleType(ilStartingPoint::ROLE_BASED);
339 $starting_point->setStartingPoint($form->getInput("start_point"));
340 $rules = array("role_id" => $form->getInput('role'));
341 $starting_point->setRuleOptions(serialize($rules));
342
343 $obj_id = $form->getInput('start_object');
344 $cal_view = $form->getInput("user_calendar_view");
345 $cal_period = $form->getInput("user_cal_period");
346 if ($obj_id && ($starting_point->getStartingPoint() == ilUserUtil::START_REPOSITORY_OBJ)) {
347 if (ilObject::_lookupObjId($obj_id) && !$tree->isDeleted($obj_id)) {
348 $starting_point->setStartingObject($obj_id);
349 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
350 } else {
351 ilUtil::sendFailure($this->lng->txt("obj_ref_id_not_exist"), true);
352 }
353 } else {
354 $starting_point->setStartingObject(0);
355 }
356
357 if (!empty($cal_view) && !empty($cal_period) && ($starting_point->getStartingPoint() == ilUserUtil::START_PD_CALENDAR)) {
358 $starting_point->setCalendarView($cal_view);
359 $starting_point->setCalendarPeriod($cal_period);
360 } else {
361 $starting_point->setCalendarView(0);
362 $starting_point->setCalendarPeriod(0);
363 }
364
365 if ($start_point_id) {
366 $starting_point->update();
367 } else {
368 $starting_point->save();
369 }
370 } else if(!empty($form->getInput("user_calendar_view")) && !empty($form->getInput("user_cal_period"))) {
371 $calendar_info = [
372 "user_calendar_view" => $form->getInput("user_calendar_view"),
373 "user_cal_period" => $form->getInput("user_cal_period")
374 ];
375 ilUserUtil::setStartingPoint($form->getInput('start_point'), $form->getInput('start_object'), $calendar_info);
376 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
377 } else { //default
378 ilUserUtil::setStartingPoint($form->getInput('start_point'), $form->getInput('start_object'));
379 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
380 }
381
382 $ilCtrl->redirect($this, "startingPoints");
383 }
384 $tpl->setContent($form->getHTML());
385
386 //$ilCtrl->redirect($this, "startingPoints");
387 }
388
389 public function saveOrder()
390 {
391 global $DIC;
392
393 $ilCtrl = $DIC['ilCtrl'];
394 $rbacsystem = $DIC['rbacsystem'];
395 $ilErr = $DIC['ilErr'];
396
397 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
398 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
399 }
400
401 if ($_POST['position']) {
402 require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
403
404 $sp = new ilStartingPoint();
405 $sp->saveOrder($_POST['position']);
406 }
407
408 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
409 $ilCtrl->redirect($this, "startingPoints");
410 }
411
416 {
417 global $DIC;
418
419 $ilCtrl = $DIC['ilCtrl'];
420 $lng = $DIC['lng'];
421 $tpl = $DIC['tpl'];
422 $ilTabs = $DIC['ilTabs'];
423
424 $ilTabs->clearTargets();
425 $ilTabs->setBackTarget($lng->txt('back_to_starting_points_list'), $ilCtrl->getLinkTarget($this, 'startingPoints'));
426
427 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
428 $conf = new ilConfirmationGUI();
429 $conf->setFormAction($ilCtrl->getFormAction($this));
430 $conf->setHeaderText($lng->txt('confirm_delete_starting_point'));
431
432 //if type role based
433 if ($_REQUEST['rolid'] && $_REQUEST['spid']) {
434 include_once "./Services/AccessControl/classes/class.ilObjRole.php";
435
436 $rolid = (int) $_REQUEST['rolid'];
437 $spid = (int) $_REQUEST['spid'];
438
439 $role = new ilObjRole($rolid);
440
441 $conf->addItem('rolid', $rolid, $role->getTitle());
442 $conf->addItem('spid', $spid, "");
443 }
444
445 $conf->setConfirm($lng->txt('delete'), 'deleteStartingPoint');
446 $conf->setCancel($lng->txt('cancel'), 'startingPoints');
447
448 $tpl->setContent($conf->getHTML());
449 }
450
454 protected function deleteStartingPoint()
455 {
456 global $DIC;
457
458 $ilCtrl = $DIC['ilCtrl'];
459 $rbacsystem = $DIC['rbacsystem'];
460 $ilErr = $DIC['ilErr'];
461
462 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
463 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
464 }
465
466 require_once "./Services/AccessControl/classes/class.ilObjRole.php";
467
468 if ($rolid = $_REQUEST['rolid'] && $spid = $_REQUEST['spid']) {
469 include_once("./Services/AccessControl/classes/class.ilStartingPoint.php");
470 $sp = new ilStartingPoint($spid);
471 $sp->delete();
472 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
473 } else {
474 ilUtil::sendFailure($this->lng->txt("msg_spoint_not_modified"), true);
475 }
476 $ilCtrl->redirect($this, "startingPoints");
477 }
478}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a hidden form property in a property form.
static getLogger($a_component_id)
Get component logger.
Class ilObjRole.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
Class ilStartingPoint.
static getGlobalRolesWithoutStartingPoint()
Get id and title of the roles without starting points.
This class represents a text property in a property form.
TableGUI class for LTI consumer listing.
Class ilUserStartingPointGUI.
initRoleStartingPointForm(ilPropertyFormGUI $form=null)
initUserStartingPointForm(ilPropertyFormGUI $form=null)
deleteStartingPoint()
Set to 0 the starting point values.
__construct($a_parent_ref_id)
Constructor @access public.
startingPoints()
table form to set up starting points depends of user roles
confirmDeleteStartingPoint()
Confirm delete starting point.
saveStartingPoint()
store starting point from the form
static getCalendarPeriod()
Get time frame of calendar view.
static getPossibleStartingPoints($a_force_all=false)
Get all valid starting points.
static getCalendarView()
Get specific view of calendar starting point.
static hasPersonalStartingPoint()
Can starting point be personalized?
static togglePersonalStartingPoint($a_value)
Toggle personal starting point setting.
static setStartingPoint($a_value, $a_ref_id=null, $a_cal_view=[])
Set starting point setting.
const START_PD_CALENDAR
static getStartingPoint()
Get current starting point setting.
static getStartingObject()
Get ref id of starting object.
const START_REPOSITORY_OBJ
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$valid
global $DIC
Definition: goto.php:24
$ilErr
Definition: raiseError.php:18