ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 }
41 public function &executeCommand()
42 {
43 global $DIC;
44
45 $ilCtrl = $DIC['ilCtrl'];
46
47 $cmd = $ilCtrl->getCmd();
48 if ($cmd == "roleStartingPointform" || !$cmd) {
49 $cmd = "initRoleStartingPointForm";
50 }
51
52 $this->$cmd();
53
54 return true;
55 }
56
60 public function startingPoints()
61 {
62 include_once "Services/User/classes/class.ilUserRoleStartingPointTableGUI.php";
63
64 require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
66
67 if (!empty($roles_without_point)) {
68 $this->toolbar->addButton(
69 $this->lng->txt('create_starting_point'),
70 $this->ctrl->getLinkTarget($this, "roleStartingPointform")
71 );
72 } else {
73 ilUtil::sendInfo($this->lng->txt("all_roles_has_starting_point"));
74 }
75
76
77 $tbl = new ilUserRoleStartingPointTableGUI($this);
78
79 $this->tpl->setContent($tbl->getHTML());
80 }
81
82 public function initUserStartingPointForm(ilPropertyFormGUI $form = null)
83 {
84 if (!($form instanceof ilPropertyFormGUI)) {
85 $form = $this->getUserStartingPointForm();
86 }
87 $this->tpl->setContent($form->getHTML());
88 }
89
90 public function initRoleStartingPointForm(ilPropertyFormGUI $form = null)
91 {
92 if (!($form instanceof ilPropertyFormGUI)) {
93 $form = $this->getRoleStartingPointForm();
94 }
95 $this->tpl->setContent($form->getHTML());
96 }
97
98 protected function getUserStartingPointForm()
99 {
100 global $DIC;
101
102 $ilCtrl = $DIC['ilCtrl'];
103
104 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
105 require_once "Services/User/classes/class.ilUserUtil.php";
106
107 $form = new ilPropertyFormGUI();
108
109 // starting point: personal
110 $startp = new ilCheckboxInputGUI($this->lng->txt("user_chooses_starting_page"), "usr_start_pers");
111 $startp->setInfo($this->lng->txt("adm_user_starting_point_personal_info"));
112 $startp->setChecked(ilUserUtil::hasPersonalStartingPoint());
113
114 $form->addItem($startp);
115
116 $form->addCommandButton("saveUserStartingPoint", $this->lng->txt("save"));
117 $form->setFormAction($ilCtrl->getFormAction($this));
118
119 return $form;
120 }
121
125 protected function getRoleStartingPointForm()
126 {
127 global $DIC;
128
129 $ilCtrl = $DIC['ilCtrl'];
130 $rbacsystem = $DIC['rbacsystem'];
131 $ilErr = $DIC['ilErr'];
132
133 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
134 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
135 }
136
137 require_once "Services/Form/classes/class.ilPropertyFormGUI.php";
138 require_once "./Services/AccessControl/classes/class.ilObjRole.php";
139 require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
140 include_once "Services/User/classes/class.ilUserUtil.php";
141
142 $form = new ilPropertyFormGUI();
143 $ilCtrl->saveParameter($this, array("spid"));
144
145 $spoint_id = $_REQUEST['spid'];
146
147 //edit no default
148 if ($spoint_id > 0 && $spoint_id != 'default') {
149 $st_point = new ilStartingPoint($spoint_id);
150
151 //starting point role based
152 if ($st_point->getRuleType() == ilStartingPoint::ROLE_BASED && $_REQUEST['rolid']) {
153 $rolid = (int) $_REQUEST['rolid'];
154 if ($role = new ilObjRole($rolid)) {
155 $options[$rolid] = $role->getTitle();
156 $starting_point = $st_point->getStartingPoint();
157 $si_roles = new ilSelectInputGUI($this->lng->txt("editing_this_role"), 'role_disabled');
158 $si_roles->setOptions($options);
159 $si_roles->setDisabled(true);
160 $form->addItem($si_roles);
161
162 $hi = new ilHiddenInputGUI("role");
163 $hi->setValue($rolid);
164 $form->addItem($hi);
165
166 $hidde_sp_id = new ilHiddenInputGUI("start_point_id");
167 $hidde_sp_id->setValue($spoint_id);
168 $form->addItem($hidde_sp_id);
169 }
170 }
171 }
172 //create
173 elseif (!$spoint_id || $spoint_id != 'default') {
174 //starting point role based
177
178 foreach ($roles as $role) {
179 $options[$role['id']] = $role['title'];
180 }
181 $si_roles = new ilSelectInputGUI($this->lng->txt("roles_without_starting_point"), 'role');
182 $si_roles->setOptions($options);
183 $form->addItem($si_roles);
184 }
185 } else {
186 $starting_point = ilUserUtil::getStartingPoint();
187 }
188
189 // starting point
190
191 $si = new ilRadioGroupInputGUI($this->lng->txt("adm_user_starting_point"), "start_point");
192 $si->setRequired(true);
193 $si->setInfo($this->lng->txt("adm_user_starting_point_info"));
195 foreach (ilUserUtil::getPossibleStartingPoints(true) as $value => $caption) {
196 $opt = new ilRadioOption($caption, $value);
197 $si->addOption($opt);
198
199 if (!in_array($value, $valid)) {
200 $opt->setInfo($this->lng->txt("adm_user_starting_point_invalid_info"));
201 }
202 }
203 $si->setValue($starting_point);
204 $form->addItem($si);
205
206 // starting point: repository object
207 $repobj = new ilRadioOption($this->lng->txt("adm_user_starting_point_object"), ilUserUtil::START_REPOSITORY_OBJ);
208 $repobj_id = new ilTextInputGUI($this->lng->txt("adm_user_starting_point_ref_id"), "start_object");
209 $repobj_id->setRequired(true);
210 $repobj_id->setSize(5);
211 //$i has the starting_point value, so we are here only when edit one role or setting the default role.
212 if ($si->getValue() == ilUserUtil::START_REPOSITORY_OBJ) {
213 if ($st_point) {
214 $start_ref_id = $st_point->getStartingObject();
215 } else {
216 $start_ref_id = ilUserUtil::getStartingObject();
217 }
218
219 $repobj_id->setValue($start_ref_id);
220 if ($start_ref_id) {
221 $start_obj_id = ilObject::_lookupObjId($start_ref_id);
222 if ($start_obj_id) {
223 $repobj_id->setInfo($this->lng->txt("obj_" . ilObject::_lookupType($start_obj_id)) .
224 ": " . ilObject::_lookupTitle($start_obj_id));
225 }
226 }
227 }
228 $repobj->addSubItem($repobj_id);
229 $si->addOption($repobj);
230
231 // save and cancel commands
232 $form->addCommandButton("saveStartingPoint", $this->lng->txt("save"));
233 $form->addCommandButton("startingPoints", $this->lng->txt("cancel"));
234
235 $form->setTitle($this->lng->txt("starting_point_settings"));
236 $form->setFormAction($ilCtrl->getFormAction($this));
237
238 return $form;
239 }
240
241 protected function saveUserStartingPoint()
242 {
243 global $DIC;
244
245 $ilCtrl = $DIC['ilCtrl'];
246 $rbacsystem = $DIC['rbacsystem'];
247 $ilErr = $DIC['ilErr'];
248
249 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
250 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
251 }
252
253 include_once "Services/User/classes/class.ilUserUtil.php";
254
255 $form = $this->getUserStartingPointForm();
256
257 if ($form->checkInput()) {
258 ilUserUtil::togglePersonalStartingPoint($form->getInput('usr_start_pers'));
259 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
260 $ilCtrl->redirect($this, "startingPoints");
261 }
262 ilUtil::sendFailure($this->lng->txt("msg_error"), true);
263 $ilCtrl->redirect($this, "startingPoints");
264 }
265
269 protected function saveStartingPoint()
270 {
271 global $DIC;
272
273 $ilCtrl = $DIC['ilCtrl'];
274 $tree = $DIC['tree'];
275 $rbacsystem = $DIC['rbacsystem'];
276 $ilErr = $DIC['ilErr'];
277 $tpl = $DIC['tpl'];
278
279 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
280 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
281 }
282
283 if ((int) $_POST['start_point_id'] > 0) {
284 $start_point_id = (int) $_POST['start_point_id'];
285 }
286
287 //add from form
288 $form = $this->getRoleStartingPointForm();
289 if ($form->checkInput()) {
290 //if role
291 if ($form->getInput('role')) {
292
293 //create starting point
294 if ($start_point_id) {
295 $starting_point = new ilStartingPoint($start_point_id);
296 } else { //edit
297 $starting_point = new ilStartingPoint();
298 }
299 $starting_point->setRuleType(ilStartingPoint::ROLE_BASED);
300 $starting_point->setStartingPoint($form->getInput("start_point"));
301 $rules = array("role_id" => $form->getInput('role'));
302 $starting_point->setRuleOptions(serialize($rules));
303
304 $obj_id = $form->getInput('start_object');
305 if ($obj_id && ($starting_point->getStartingPoint() == ilUserUtil::START_REPOSITORY_OBJ)) {
306 if (ilObject::_lookupObjId($obj_id) && !$tree->isDeleted($obj_id)) {
307 $starting_point->setStartingObject($obj_id);
308 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
309 } else {
310 ilUtil::sendFailure($this->lng->txt("obj_ref_id_not_exist"), true);
311 }
312 } else {
313 $starting_point->setStartingObject(0);
314 }
315
316 if ($start_point_id) {
317 $starting_point->update();
318 } else {
319 $starting_point->save();
320 }
321 } else { //default
322 ilUserUtil::setStartingPoint($form->getInput('start_point'), $form->getInput('start_object'));
323 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
324 }
325
326 $ilCtrl->redirect($this, "startingPoints");
327 }
328 $tpl->setContent($form->getHTML());
329
330 //$ilCtrl->redirect($this, "startingPoints");
331 }
332
333 public function saveOrder()
334 {
335 global $DIC;
336
337 $ilCtrl = $DIC['ilCtrl'];
338 $rbacsystem = $DIC['rbacsystem'];
339 $ilErr = $DIC['ilErr'];
340
341 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
342 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
343 }
344
345 if ($_POST['position']) {
346 require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
347
348 $sp = new ilStartingPoint();
349 $sp->saveOrder($_POST['position']);
350 }
351
352 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
353 $ilCtrl->redirect($this, "startingPoints");
354 }
355
360 {
361 global $DIC;
362
363 $ilCtrl = $DIC['ilCtrl'];
364 $lng = $DIC['lng'];
365 $tpl = $DIC['tpl'];
366 $ilTabs = $DIC['ilTabs'];
367
368 $ilTabs->clearTargets();
369 $ilTabs->setBackTarget($lng->txt('back_to_starting_points_list'), $ilCtrl->getLinkTarget($this, 'startingPoints'));
370
371 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
372 $conf = new ilConfirmationGUI();
373 $conf->setFormAction($ilCtrl->getFormAction($this));
374 $conf->setHeaderText($lng->txt('confirm_delete_starting_point'));
375
376 //if type role based
377 if ($_REQUEST['rolid'] && $_REQUEST['spid']) {
378 include_once "./Services/AccessControl/classes/class.ilObjRole.php";
379
380 $rolid = (int) $_REQUEST['rolid'];
381 $spid = (int) $_REQUEST['spid'];
382
383 $role = new ilObjRole($rolid);
384
385 $conf->addItem('rolid', $rolid, $role->getTitle());
386 $conf->addItem('spid', $spid, "");
387 }
388
389 $conf->setConfirm($lng->txt('delete'), 'deleteStartingPoint');
390 $conf->setCancel($lng->txt('cancel'), 'startingPoints');
391
392 $tpl->setContent($conf->getHTML());
393 }
394
398 protected function deleteStartingPoint()
399 {
400 global $DIC;
401
402 $ilCtrl = $DIC['ilCtrl'];
403 $rbacsystem = $DIC['rbacsystem'];
404 $ilErr = $DIC['ilErr'];
405
406 if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
407 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
408 }
409
410 require_once "./Services/AccessControl/classes/class.ilObjRole.php";
411
412 if ($rolid = $_REQUEST['rolid'] && $spid = $_REQUEST['spid']) {
413 include_once("./Services/AccessControl/classes/class.ilStartingPoint.php");
414 $sp = new ilStartingPoint($spid);
415 $sp->delete();
416 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
417 } else {
418 ilUtil::sendFailure($this->lng->txt("msg_spoint_not_modified"), true);
419 }
420 $ilCtrl->redirect($this, "startingPoints");
421 }
422}
$_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 getPossibleStartingPoints($a_force_all=false)
Get all valid starting points.
static hasPersonalStartingPoint()
Can starting point be personalized?
static togglePersonalStartingPoint($a_value)
Toggle personal starting point setting.
static getStartingPoint()
Get current starting point setting.
static getStartingObject()
Get ref id of starting object.
const START_REPOSITORY_OBJ
static setStartingPoint($a_value, $a_ref_id=null)
Set starting point setting.
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 $ilCtrl
Definition: ilias.php:18
$ilErr
Definition: raiseError.php:18
$DIC
Definition: xapitoken.php:46