ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLPListOfSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once './Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
6include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
7
21{
22 protected $obj_settings;
23 protected $obj_lp;
24
25 public function __construct($a_mode, $a_ref_id)
26 {
27 parent::__construct($a_mode, $a_ref_id);
28
29 $this->obj_settings = new ilLPObjSettings($this->getObjId());
30
31 include_once './Services/Object/classes/class.ilObjectLP.php';
32 $this->obj_lp = ilObjectLP::getInstance($this->getObjId());
33 }
34
38 public function executeCommand()
39 {
40 switch ($this->ctrl->getNextClass()) {
41 default:
42 $cmd = $this->__getDefaultCommand();
43 $this->$cmd();
44
45 }
46 return true;
47 }
48
52 protected function show()
53 {
54 global $DIC;
55
56 $ilHelp = $DIC['ilHelp'];
57
58 $ilHelp->setSubScreenId("trac_settings");
59
60 $info = $this->obj_lp->getSettingsInfo();
61 if ($info) {
62 ilUtil::sendInfo($info);
63 }
64
65 $form = $this->initFormSettings();
66 $this->tpl->setContent(
67 $this->handleLPUsageInfo() .
68 $form->getHTML() .
69 $this->getTableByMode()
70 );
71 }
72
73
79 protected function initFormSettings()
80 {
81 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
82 $form = new ilPropertyFormGUI();
83 $form->setTitle($this->lng->txt('tracking_settings'));
84 $form->setFormAction($this->ctrl->getFormAction($this));
85
86 // Mode
87 $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus');
88 $mod->setRequired(true);
89 $mod->setValue($this->obj_lp->getCurrentMode());
90 $form->addItem($mod);
91
92 if (method_exists($this->obj_lp, 'initModeOptions')) {
97 $this->obj_lp->initModeOptions($mod);
98 } else {
99 foreach ($this->obj_lp->getValidModes() as $mode_key) {
100 $opt = new ilRadioOption(
101 $this->obj_lp->getModeText($mode_key),
102 $mode_key,
103 $this->obj_lp->getModeInfoText($mode_key)
104 );
105 $opt->setValue($mode_key);
106 $mod->addOption($opt);
107
108 // :TODO: Subitem for visits ?!
109 if ($mode_key == ilLPObjSettings::LP_MODE_VISITS) {
110 $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits');
111 $vis->setSize(3);
112 $vis->setMaxLength(4);
113 $vis->setInfo(sprintf(
114 $this->lng->txt('trac_visits_info'),
116 ));
117 $vis->setRequired(true);
118 $vis->setValue($this->obj_settings->getVisits());
119 $opt->addSubItem($vis);
120 }
121 }
122 }
123
124 $form->addCommandButton('saveSettings', $this->lng->txt('save'));
125
126 return $form;
127 }
128
133 protected function saveSettings()
134 {
135 $form = $this->initFormSettings();
136 if ($form->checkInput()) {
137 // anything changed?
138
139 // mode
140 if (method_exists($this->obj_lp, 'fetchModeOption')) {
145 $new_mode = (int) $this->obj_lp->fetchModeOption($form);
146 } else {
147 $new_mode = (int) $form->getInput('modus');
148 }
149 $old_mode = $this->obj_lp->getCurrentMode();
150 $mode_changed = ($old_mode != $new_mode);
151
152 // visits
153 $new_visits = null;
154 $visits_changed = null;
155 if ($new_mode == ilLPObjSettings::LP_MODE_VISITS) {
156 $new_visits = (int) $form->getInput('visits');
157 $old_visits = $this->obj_settings->getVisits();
158 $visits_changed = ($old_visits != $new_visits);
159 }
160
161 if ($mode_changed) {
162 // delete existing collection
163 $collection = $this->obj_lp->getCollectionInstance();
164 if ($collection) {
165 $collection->delete();
166 }
167 }
168
169 $refresh_lp = ($mode_changed || $visits_changed);
170
171 // has to be done before LP refresh!
172 $this->obj_lp->resetCaches();
173
174 $this->obj_settings->setMode($new_mode);
175 $this->obj_settings->setVisits($new_visits);
176 $this->obj_settings->update($refresh_lp);
177
178 if ($mode_changed &&
179 $this->obj_lp->getCollectionInstance() &&
180 $new_mode != ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR) { // #14819
181 ilUtil::sendInfo($this->lng->txt('trac_edit_collection'), true);
182 }
183 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
184 $this->ctrl->redirect($this, 'show');
185 }
186
187 $form->setValuesByPost();
188 ilUtil::sendFailure($this->lng->txt('err_check_input'));
189
190 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lp_obj_settings.html', 'Services/Tracking');
191 $this->tpl->setVariable('PROP_FORM', $form->getHTML());
192 $this->tpl->setVariable('COLLECTION_TABLE', $this->getTableByMode());
193 }
194
198 protected function getTableByMode()
199 {
200 $collection = $this->obj_lp->getCollectionInstance();
201 if ($collection && $collection->hasSelectableItems()) {
202 include_once "Services/Tracking/classes/repository_statistics/class.ilLPCollectionSettingsTableGUI.php";
203 $table = new ilLPCollectionSettingsTableGUI($this, 'show', $this->getRefId(), $this->obj_lp->getCurrentMode());
204 $table->parse($collection);
205 return $table->getHTML();
206 }
207 }
208
213 protected function assign()
214 {
215 if (!$_POST['item_ids']) {
216 ilUtil::sendFailure($this->lng->txt('select_one'), true);
217 $this->ctrl->redirect($this, 'show');
218 }
219 if (count($_POST['item_ids'])) {
220 $collection = $this->obj_lp->getCollectionInstance();
221 if ($collection && $collection->hasSelectableItems()) {
222 $collection->activateEntries($_POST['item_ids']);
223 }
224
225 // #15045 - has to be done before LP refresh!
226 $this->obj_lp->resetCaches();
227
228 // refresh learning progress
229 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
231 }
232 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
233 $this->ctrl->redirect($this, 'show');
234 }
235
240 protected function deassign()
241 {
242 if (!$_POST['item_ids']) {
243 ilUtil::sendFailure($this->lng->txt('select_one'), true);
244 $this->ctrl->redirect($this, 'show');
245 return false;
246 }
247 if (count($_POST['item_ids'])) {
248 $collection = $this->obj_lp->getCollectionInstance();
249 if ($collection && $collection->hasSelectableItems()) {
250 $collection->deactivateEntries($_POST['item_ids']);
251 }
252
253 // #15045 - has to be done before LP refresh!
254 $this->obj_lp->resetCaches();
255
256 // refresh learning progress
257 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
259 }
260 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
261 $this->ctrl->redirect($this, 'show');
262 }
263
267 protected function groupMaterials()
268 {
269 if (!count((array) $_POST['item_ids'])) {
270 ilUtil::sendFailure($this->lng->txt('select_one'), true);
271 $this->ctrl->redirect($this, 'show');
272 }
273
274 $collection = $this->obj_lp->getCollectionInstance();
275 if ($collection && $collection->hasSelectableItems()) {
276 // Assign new grouping id
277 $collection->createNewGrouping((array) $_POST['item_ids']);
278
279 // refresh learning progress
280 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
282 }
283
284 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
285 $this->ctrl->redirect($this, 'show');
286 }
287
291 protected function releaseMaterials()
292 {
293 if (!count((array) $_POST['item_ids'])) {
294 ilUtil::sendFailure($this->lng->txt('select_one'), true);
295 $this->ctrl->redirect($this, 'show');
296 }
297
298 $collection = $this->obj_lp->getCollectionInstance();
299 if ($collection && $collection->hasSelectableItems()) {
300 $collection->releaseGrouping((array) $_POST['item_ids']);
301
302 // refresh learning progress
303 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
305 }
306
307 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
308 $this->ctrl->redirect($this, 'show');
309 }
310
314 protected function saveObligatoryMaterials()
315 {
316 if (!is_array((array) $_POST['grp'])) {
317 ilUtil::sendFailure($this->lng->txt('select_one'), true);
318 $this->ctrl->redirect($this, 'show');
319 }
320
321 try {
322 $collection = $this->obj_lp->getCollectionInstance();
323 if ($collection && $collection->hasSelectableItems()) {
324 $collection->saveObligatoryMaterials((array) $_POST['grp']);
325
326 // refresh learning progress
327 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
329 }
330
331 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
332 $this->ctrl->redirect($this, 'show');
333 } catch (UnexpectedValueException $e) {
334 ilUtil::sendFailure($this->lng->txt('trac_grouped_material_obligatory_err'), true);
335 ilUtil::sendInfo($this->lng->txt('err_check_input'), true);
336 $this->ctrl->redirect($this, 'show');
337 }
338 }
339
340 protected function updateTLT()
341 {
342 include_once "Services/MetaData/classes/class.ilMD.php";
343 foreach ($_POST['tlt'] as $item_id => $item) {
344 $md_obj = new ilMD($this->getObjId(), $item_id, 'st');
345 if (!is_object($md_section = $md_obj->getEducational())) {
346 $md_section = $md_obj->addEducational();
347 $md_section->save();
348 }
349 $md_section->setPhysicalTypicalLearningTime(
350 (int) $item['mo'],
351 (int) $item['d'],
352 (int) $item['h'],
353 (int) $item['m'],
354 0
355 );
356 $md_section->update();
357 }
358
359 // refresh learning progress
360 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
362
363 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
364 $this->ctrl->redirect($this, 'show');
365 }
366
367
368 //
369 // USAGE INFO
370 //
371
379 protected function getLPPathInfo($a_ref_id, array &$a_res)
380 {
381 global $DIC;
382
383 $tree = $DIC['tree'];
384
385 $has_lp_parents = false;
386
387 $path = $tree->getNodePath($a_ref_id);
388 array_shift($path); // root
389 foreach ($path as $node) {
390 $supports_lp = ilObjectLP::isSupportedObjectType($node["type"]);
391
392 if ($supports_lp || $has_lp_parents) {
393 $a_res[$node["child"]]["node"] = array(
394 "type" => $node["type"]
395 ,"title" => $node["title"]
396 ,"obj_id" => $node["obj_id"]
397 ,"lp" => false
398 ,"active" => false
399 );
400 }
401
402 if (
403 $supports_lp &&
404 $node["child"] != $a_ref_id) {
405 $a_res[$node["child"]]["node"]["lp"] = true;
406 $has_lp_parents = true;
407
408 $parent_obj_id = $node['obj_id'];
409 $parent_obj_lp = \ilObjectLP::getInstance($parent_obj_id);
410 $parent_collection = $parent_obj_lp->getCollectionInstance();
411 if (
412 $parent_collection &&
413 $parent_collection->hasSelectableItems() &&
414 $parent_collection->isAssignedEntry($a_ref_id)
415 ) {
416 $a_res[$node['child']]['node']['active'] = true;
417 }
418 }
419 }
420 return $has_lp_parents;
421 }
422
423 protected function handleLPUsageInfo()
424 {
425 global $DIC;
426
427 $lng = $DIC['lng'];
428 $ilAccess = $DIC['ilAccess'];
429
430 $ref_id = $_GET["ref_id"];
431 if (!$ref_id) {
432 $ref_id = $_REQUEST["ref_id"];
433 }
434
435 $coll = array();
436 if ($ref_id &&
437 $this->getLPPathInfo($ref_id, $coll)) {
438 include_once "Services/Link/classes/class.ilLink.php";
439
440 $tpl = new ilTemplate("tpl.lp_obj_settings_tree_info.html", true, true, "Services/Tracking");
441
442 $margin = 0;
443 $has_active = false;
444 foreach ($coll as $parent_ref_id => $parts) {
445 $node = $parts["node"];
446 $params = array();
447 if ($node["lp"]) {
448 if ($node["active"]) {
449 $tpl->touchBlock("parent_active_bl");
450 $has_active = true;
451 }
452
453 $params["gotolp"] = 1;
454 }
455
456 if ($ilAccess->checkAccess("read", "", $parent_ref_id) &&
457 $parent_ref_id != $ref_id) { // #17170
458 $tpl->setCurrentBlock("parent_link_bl");
459 $tpl->setVariable("PARENT_LINK_TITLE", $node["title"]);
460 $tpl->setVariable("PARENT_URL", ilLink::_getLink($parent_ref_id, $node["type"], $params));
461 $tpl->parseCurrentBlock();
462 } else {
463 $tpl->setCurrentBlock("parent_nolink_bl");
464 $tpl->setVariable("PARENT_NOLINK_TITLE", $node["title"]);
465 $tpl->parseCurrentBlock();
466 }
467
468 $tpl->setCurrentBlock("parent_usage_bl");
469 $tpl->setVariable("PARENT_TYPE_URL", ilUtil::getTypeIconPath($node["type"], $node["obj_id"]));
470 $tpl->setVariable("PARENT_TYPE_ALT", $lng->txt("obj_" . $node["type"]));
471
472 $tpl->setVariable("PARENT_STYLE", $node["lp"]
473 ? ''
474 : ' class="ilLPParentInfoListLPUnsupported"');
475 $tpl->setVariable("MARGIN", $margin);
476 $tpl->parseCurrentBlock();
477
478 $margin += 25;
479 }
480
481 if ($has_active) {
482 $tpl->setVariable("LEGEND", sprintf(
483 $lng->txt("trac_lp_settings_info_parent_legend"),
485 ));
486 }
487
488 include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
489 $panel = ilPanelGUI::getInstance();
490 $panel->setPanelStyle(ilPanelGUI::PANEL_STYLE_SECONDARY);
491 $panel->setHeading($lng->txt("trac_lp_settings_info_parent_container"));
492 $panel->setBody($tpl->get());
493
494 return $panel->getHTML();
495 }
496 }
497}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilLPListOfSettingsGUI.
getLPPathInfo($a_ref_id, array &$a_res)
Gather LP data about parent objects.
initFormSettings()
Init property form.
assign()
Save material assignment.
saveObligatoryMaterials()
Save obligatory state per grouped materials.
saveSettings()
Save learning progress settings.
deassign()
save mterial assignment
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
This class represents a number property in a property form.
static isSupportedObjectType($a_type)
static getInstance($a_obj_id)
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
const PANEL_STYLE_SECONDARY
static getInstance()
Get instance.
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.
special template class to simplify handling of ITX/PEAR
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getTypeIconPath($a_type, $a_obj_id, $a_size='small')
Get type icon path path Return image path for icon_xxx.pngs Or (if enabled) path to custom icon Depre...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46