ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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) {
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';
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 foreach ($this->obj_lp->getValidModes() as $mode_key) {
93 $opt = new ilRadioOption(
94 $this->obj_lp->getModeText($mode_key),
95 $mode_key,
96 $this->obj_lp->getModeInfoText($mode_key)
97 );
98 $opt->setValue($mode_key);
99 $mod->addOption($opt);
100
101 // :TODO: Subitem for visits ?!
102 if ($mode_key == ilLPObjSettings::LP_MODE_VISITS) {
103 $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits');
104 $vis->setSize(3);
105 $vis->setMaxLength(4);
106 $vis->setInfo(sprintf(
107 $this->lng->txt('trac_visits_info'),
109 ));
110 $vis->setRequired(true);
111 $vis->setValue($this->obj_settings->getVisits());
112 $opt->addSubItem($vis);
113 }
114 }
115
116 $form->addCommandButton('saveSettings', $this->lng->txt('save'));
117
118 return $form;
119 }
120
125 protected function saveSettings()
126 {
127 $form = $this->initFormSettings();
128 if ($form->checkInput()) {
129 // anything changed?
130
131 // mode
132 $new_mode = (int) $form->getInput('modus');
133 $old_mode = $this->obj_lp->getCurrentMode();
134 $mode_changed = ($old_mode != $new_mode);
135
136 // visits
137 $new_visits = null;
138 $visits_changed = null;
139 if ($new_mode == ilLPObjSettings::LP_MODE_VISITS) {
140 $new_visits = (int) $form->getInput('visits');
141 $old_visits = $this->obj_settings->getVisits();
142 $visits_changed = ($old_visits != $new_visits);
143 }
144
145 if ($mode_changed) {
146 // delete existing collection
147 $collection = $this->obj_lp->getCollectionInstance();
148 if ($collection) {
149 $collection->delete();
150 }
151 }
152
153 $refresh_lp = ($mode_changed || $visits_changed);
154
155 // has to be done before LP refresh!
156 $this->obj_lp->resetCaches();
157
158 $this->obj_settings->setMode($new_mode);
159 $this->obj_settings->setVisits($new_visits);
160 $this->obj_settings->update($refresh_lp);
161
162 if ($mode_changed &&
163 $this->obj_lp->getCollectionInstance() &&
164 $new_mode != ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR) { // #14819
165 ilUtil::sendInfo($this->lng->txt('trac_edit_collection'), true);
166 }
167 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
168 $this->ctrl->redirect($this, 'show');
169 }
170
171 $form->setValuesByPost();
172 ilUtil::sendFailure($this->lng->txt('err_check_input'));
173
174 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lp_obj_settings.html', 'Services/Tracking');
175 $this->tpl->setVariable('PROP_FORM', $form->getHTML());
176 $this->tpl->setVariable('COLLECTION_TABLE', $this->getTableByMode());
177 }
178
182 protected function getTableByMode()
183 {
184 $collection = $this->obj_lp->getCollectionInstance();
185 if ($collection && $collection->hasSelectableItems()) {
186 include_once "Services/Tracking/classes/repository_statistics/class.ilLPCollectionSettingsTableGUI.php";
187 $table = new ilLPCollectionSettingsTableGUI($this, 'show', $this->getRefId(), $this->obj_lp->getCurrentMode());
188 $table->parse($collection);
189 return $table->getHTML();
190 }
191 }
192
197 protected function assign()
198 {
199 if (!$_POST['item_ids']) {
200 ilUtil::sendFailure($this->lng->txt('select_one'), true);
201 $this->ctrl->redirect($this, 'show');
202 }
203 if (count($_POST['item_ids'])) {
204 $collection = $this->obj_lp->getCollectionInstance();
205 if ($collection && $collection->hasSelectableItems()) {
206 $collection->activateEntries($_POST['item_ids']);
207 }
208
209 // #15045 - has to be done before LP refresh!
210 $this->obj_lp->resetCaches();
211
212 // refresh learning progress
213 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
215 }
216 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
217 $this->ctrl->redirect($this, 'show');
218 }
219
224 protected function deassign()
225 {
226 if (!$_POST['item_ids']) {
227 ilUtil::sendFailure($this->lng->txt('select_one'), true);
228 $this->ctrl->redirect($this, 'show');
229 return false;
230 }
231 if (count($_POST['item_ids'])) {
232 $collection = $this->obj_lp->getCollectionInstance();
233 if ($collection && $collection->hasSelectableItems()) {
234 $collection->deactivateEntries($_POST['item_ids']);
235 }
236
237 // #15045 - has to be done before LP refresh!
238 $this->obj_lp->resetCaches();
239
240 // refresh learning progress
241 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
243 }
244 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
245 $this->ctrl->redirect($this, 'show');
246 }
247
251 protected function groupMaterials()
252 {
253 if (!count((array) $_POST['item_ids'])) {
254 ilUtil::sendFailure($this->lng->txt('select_one'), true);
255 $this->ctrl->redirect($this, 'show');
256 }
257
258 $collection = $this->obj_lp->getCollectionInstance();
259 if ($collection && $collection->hasSelectableItems()) {
260 // Assign new grouping id
261 $collection->createNewGrouping((array) $_POST['item_ids']);
262
263 // refresh learning progress
264 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
266 }
267
268 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
269 $this->ctrl->redirect($this, 'show');
270 }
271
275 protected function releaseMaterials()
276 {
277 if (!count((array) $_POST['item_ids'])) {
278 ilUtil::sendFailure($this->lng->txt('select_one'), true);
279 $this->ctrl->redirect($this, 'show');
280 }
281
282 $collection = $this->obj_lp->getCollectionInstance();
283 if ($collection && $collection->hasSelectableItems()) {
284 $collection->releaseGrouping((array) $_POST['item_ids']);
285
286 // refresh learning progress
287 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
289 }
290
291 ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
292 $this->ctrl->redirect($this, 'show');
293 }
294
298 protected function saveObligatoryMaterials()
299 {
300 if (!is_array((array) $_POST['grp'])) {
301 ilUtil::sendFailure($this->lng->txt('select_one'), true);
302 $this->ctrl->redirect($this, 'show');
303 }
304
305 try {
306 $collection = $this->obj_lp->getCollectionInstance();
307 if ($collection && $collection->hasSelectableItems()) {
308 $collection->saveObligatoryMaterials((array) $_POST['grp']);
309
310 // refresh learning progress
311 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
313 }
314
315 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
316 $this->ctrl->redirect($this, 'show');
317 } catch (UnexpectedValueException $e) {
318 ilUtil::sendFailure($this->lng->txt('trac_grouped_material_obligatory_err'), true);
319 ilUtil::sendInfo($this->lng->txt('err_check_input'), true);
320 $this->ctrl->redirect($this, 'show');
321 }
322 }
323
324 protected function updateTLT()
325 {
326 include_once "Services/MetaData/classes/class.ilMD.php";
327 foreach ($_POST['tlt'] as $item_id => $item) {
328 $md_obj = new ilMD($this->getObjId(), $item_id, 'st');
329 if (!is_object($md_section = $md_obj->getEducational())) {
330 $md_section = $md_obj->addEducational();
331 $md_section->save();
332 }
333 $md_section->setPhysicalTypicalLearningTime(
334 (int) $item['mo'],
335 (int) $item['d'],
336 (int) $item['h'],
337 (int) $item['m'],
338 0
339 );
340 $md_section->update();
341 }
342
343 // refresh learning progress
344 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
346
347 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
348 $this->ctrl->redirect($this, 'show');
349 }
350
351
352 //
353 // USAGE INFO
354 //
355
363 protected function getLPPathInfo($a_ref_id, array &$a_res)
364 {
365 global $DIC;
366
367 $tree = $DIC['tree'];
368
369 $has_lp_parents = false;
370
371 $path = $tree->getNodePath($a_ref_id);
372 array_shift($path); // root
373 foreach ($path as $node) {
374 $supports_lp = ilObjectLP::isSupportedObjectType($node["type"]);
375
376 if ($supports_lp || $has_lp_parents) {
377 $a_res[$node["child"]]["node"] = array(
378 "type" => $node["type"]
379 ,"title" => $node["title"]
380 ,"obj_id" => $node["obj_id"]
381 ,"lp" => false
382 ,"active" => false
383 );
384 }
385
386 if (
387 $supports_lp &&
388 $node["child"] != $a_ref_id) {
389 $a_res[$node["child"]]["node"]["lp"] = true;
390 $has_lp_parents = true;
391
392 $parent_obj_id = $node['obj_id'];
393 $parent_obj_lp = \ilObjectLP::getInstance($parent_obj_id);
394 $parent_collection = $parent_obj_lp->getCollectionInstance();
395 if (
396 $parent_collection &&
397 $parent_collection->hasSelectableItems() &&
398 $parent_collection->isAssignedEntry($a_ref_id)
399 ) {
400 $a_res[$node['child']]['node']['active'] = true;
401 }
402 }
403 }
404 return $has_lp_parents;
405 }
406
407 protected function handleLPUsageInfo()
408 {
409 global $DIC;
410
411 $lng = $DIC['lng'];
412 $ilAccess = $DIC['ilAccess'];
413
414 $ref_id = $_GET["ref_id"];
415 if (!$ref_id) {
416 $ref_id = $_REQUEST["ref_id"];
417 }
418
419 $coll = array();
420 if ($ref_id &&
421 $this->getLPPathInfo($ref_id, $coll)) {
422 include_once "Services/Link/classes/class.ilLink.php";
423
424 $tpl = new ilTemplate("tpl.lp_obj_settings_tree_info.html", true, true, "Services/Tracking");
425
426 $margin = 0;
427 $has_active = false;
428 foreach ($coll as $parent_ref_id => $parts) {
429 $node = $parts["node"];
430 $params = array();
431 if ($node["lp"]) {
432 if ($node["active"]) {
433 $tpl->touchBlock("parent_active_bl");
434 $has_active = true;
435 }
436
437 $params["gotolp"] = 1;
438 }
439
440 if ($ilAccess->checkAccess("read", "", $parent_ref_id) &&
441 $parent_ref_id != $ref_id) { // #17170
442 $tpl->setCurrentBlock("parent_link_bl");
443 $tpl->setVariable("PARENT_LINK_TITLE", $node["title"]);
444 $tpl->setVariable("PARENT_URL", ilLink::_getLink($parent_ref_id, $node["type"], $params));
445 $tpl->parseCurrentBlock();
446 } else {
447 $tpl->setCurrentBlock("parent_nolink_bl");
448 $tpl->setVariable("PARENT_NOLINK_TITLE", $node["title"]);
449 $tpl->parseCurrentBlock();
450 }
451
452 $tpl->setCurrentBlock("parent_usage_bl");
453 $tpl->setVariable("PARENT_TYPE_URL", ilUtil::getTypeIconPath($node["type"], $node["obj_id"]));
454 $tpl->setVariable("PARENT_TYPE_ALT", $lng->txt("obj_" . $node["type"]));
455
456 $tpl->setVariable("PARENT_STYLE", $node["lp"]
457 ? ''
458 : ' class="ilLPParentInfoListLPUnsupported"');
459 $tpl->setVariable("MARGIN", $margin);
460 $tpl->parseCurrentBlock();
461
462 $margin += 25;
463 }
464
465 if ($has_active) {
466 $tpl->setVariable("LEGEND", sprintf(
467 $lng->txt("trac_lp_settings_info_parent_legend"),
469 ));
470 }
471
472 include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
473 $panel = ilPanelGUI::getInstance();
474 $panel->setPanelStyle(ilPanelGUI::PANEL_STYLE_SECONDARY);
475 $panel->setHeading($lng->txt("trac_lp_settings_info_parent_container"));
476 $panel->setBody($tpl->get());
477
478 return $panel->getHTML();
479 }
480 }
481}
$path
Definition: aliased.php:25
$_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...
$info
Definition: index.php:5
if(empty($password)) $table
Definition: pwgen.php:24
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7