ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 include_once './Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
6 include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
7 
21 {
22  protected $obj_settings;
23  protected $obj_lp;
24 
25  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  function executeCommand()
39  {
40  switch($this->ctrl->getNextClass())
41  {
42  default:
43  $cmd = $this->__getDefaultCommand();
44  $this->$cmd();
45 
46  }
47  return true;
48  }
49 
53  protected function show()
54  {
55  global $ilHelp;
56 
57  $ilHelp->setSubScreenId("trac_settings");
58 
59  $info = $this->obj_lp->getSettingsInfo();
60  if($info)
61  {
63  }
64 
65  $form = $this->initFormSettings();
66  $this->tpl->setContent(
67  $this->handleLPUsageInfo().
68  $form->getHTML().
69  $this->getTableByMode());
70  }
71 
72 
78  protected function initFormSettings()
79  {
80  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
81  $form = new ilPropertyFormGUI();
82  $form->setTitle($this->lng->txt('tracking_settings'));
83  $form->setFormAction($this->ctrl->getFormAction($this));
84 
85  // Mode
86  $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus');
87  $mod->setRequired(true);
88  $mod->setValue($this->obj_lp->getCurrentMode());
89  $form->addItem($mod);
90 
91  foreach($this->obj_lp->getValidModes() as $mode_key)
92  {
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  {
104  $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits');
105  $vis->setSize(3);
106  $vis->setMaxLength(4);
107  $vis->setInfo(sprintf($this->lng->txt('trac_visits_info'),
109  $vis->setRequired(true);
110  $vis->setValue($this->obj_settings->getVisits());
111  $opt->addSubItem($vis);
112  }
113  }
114 
115  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
116 
117  return $form;
118  }
119 
124  protected function saveSettings()
125  {
126  $form = $this->initFormSettings();
127  if($form->checkInput())
128  {
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  {
141  $new_visits = (int)$form->getInput('visits');
142  $old_visits = $this->obj_settings->getVisits();
143  $visits_changed = ($old_visits != $new_visits);
144  }
145 
146  if($mode_changed)
147  {
148  // delete existing collection
149  $collection = $this->obj_lp->getCollectionInstance();
150  if($collection)
151  {
152  $collection->delete();
153  }
154  }
155 
156  $refresh_lp = ($mode_changed || $visits_changed);
157 
158  // has to be done before LP refresh!
159  $this->obj_lp->resetCaches();
160 
161  $this->obj_settings->setMode($new_mode);
162  $this->obj_settings->setVisits($new_visits);
163  $this->obj_settings->update($refresh_lp);
164 
165  if($mode_changed &&
166  $this->obj_lp->getCollectionInstance() &&
167  $new_mode != ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR) // #14819
168  {
169  ilUtil::sendInfo($this->lng->txt('trac_edit_collection'), true);
170  }
171  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
172  $this->ctrl->redirect($this, 'show');
173  }
174 
175  $form->setValuesByPost();
176  ilUtil::sendFailure($this->lng->txt('err_check_input'));
177 
178  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lp_obj_settings.html','Services/Tracking');
179  $this->tpl->setVariable('PROP_FORM',$form->getHTML());
180  $this->tpl->setVariable('COLLECTION_TABLE',$this->getTableByMode());
181  }
182 
186  protected function getTableByMode()
187  {
188  $collection = $this->obj_lp->getCollectionInstance();
189  if($collection && $collection->hasSelectableItems())
190  {
191  include_once "Services/Tracking/classes/repository_statistics/class.ilLPCollectionSettingsTableGUI.php";
192  $table = new ilLPCollectionSettingsTableGUI($this, 'show', $this->getRefId(), $this->obj_lp->getCurrentMode());
193  $table->parse($collection);
194  return $table->getHTML();
195  }
196  }
197 
202  protected function assign()
203  {
204  if(!$_POST['item_ids'])
205  {
206  ilUtil::sendFailure($this->lng->txt('select_one'),true);
207  $this->ctrl->redirect($this,'show');
208  }
209  if(count($_POST['item_ids']))
210  {
211  $collection = $this->obj_lp->getCollectionInstance();
212  if($collection && $collection->hasSelectableItems())
213  {
214  $collection->activateEntries($_POST['item_ids']);
215  }
216 
217  // #15045 - has to be done before LP refresh!
218  $this->obj_lp->resetCaches();
219 
220  // refresh learning progress
221  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
223  }
224  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
225  $this->ctrl->redirect($this,'show');
226  }
227 
232  protected function deassign()
233  {
234  if(!$_POST['item_ids'])
235  {
236  ilUtil::sendFailure($this->lng->txt('select_one'),true);
237  $this->ctrl->redirect($this,'show');
238  return false;
239  }
240  if(count($_POST['item_ids']))
241  {
242  $collection = $this->obj_lp->getCollectionInstance();
243  if($collection && $collection->hasSelectableItems())
244  {
245  $collection->deactivateEntries($_POST['item_ids']);
246  }
247 
248  // #15045 - has to be done before LP refresh!
249  $this->obj_lp->resetCaches();
250 
251  // refresh learning progress
252  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
254  }
255  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
256  $this->ctrl->redirect($this,'show');
257  }
258 
262  protected function groupMaterials()
263  {
264  if(!count((array) $_POST['item_ids']))
265  {
266  ilUtil::sendFailure($this->lng->txt('select_one'),true);
267  $this->ctrl->redirect($this,'show');
268  }
269 
270  $collection = $this->obj_lp->getCollectionInstance();
271  if($collection && $collection->hasSelectableItems())
272  {
273  // Assign new grouping id
274  $collection->createNewGrouping((array)$_POST['item_ids']);
275 
276  // refresh learning progress
277  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
279  }
280 
281  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
282  $this->ctrl->redirect($this,'show');
283  }
284 
288  protected function releaseMaterials()
289  {
290  if(!count((array) $_POST['item_ids']))
291  {
292  ilUtil::sendFailure($this->lng->txt('select_one'),true);
293  $this->ctrl->redirect($this,'show');
294  }
295 
296  $collection = $this->obj_lp->getCollectionInstance();
297  if($collection && $collection->hasSelectableItems())
298  {
299  $collection->releaseGrouping((array)$_POST['item_ids']);
300 
301  // refresh learning progress
302  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
304  }
305 
306  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
307  $this->ctrl->redirect($this,'show');
308  }
309 
313  protected function saveObligatoryMaterials()
314  {
315  if(!is_array((array) $_POST['grp']))
316  {
317  ilUtil::sendFailure($this->lng->txt('select_one'),true);
318  $this->ctrl->redirect($this,'show');
319  }
320 
321  try {
322 
323  $collection = $this->obj_lp->getCollectionInstance();
324  if($collection && $collection->hasSelectableItems())
325  {
326  $collection->saveObligatoryMaterials((array)$_POST['grp']);
327 
328  // refresh learning progress
329  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
331  }
332 
333  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
334  $this->ctrl->redirect($this,'show');
335  }
336  catch(UnexpectedValueException $e) {
337  ilUtil::sendFailure($this->lng->txt('trac_grouped_material_obligatory_err'), true);
338  ilUtil::sendInfo($this->lng->txt('err_check_input'),true);
339  $this->ctrl->redirect($this,'show');
340  }
341  }
342 
343  protected function updateTLT()
344  {
345  include_once "Services/MetaData/classes/class.ilMD.php";
346  foreach($_POST['tlt'] as $item_id => $item)
347  {
348  $md_obj = new ilMD($this->getObjId(),$item_id,'st');
349  if(!is_object($md_section = $md_obj->getEducational()))
350  {
351  $md_section = $md_obj->addEducational();
352  $md_section->save();
353  }
354  $md_section->setPhysicalTypicalLearningTime((int)$item['mo'],
355  (int)$item['d'],(int)$item['h'],(int)$item['m'],0);
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 $tree;
382 
383  $has_lp_parents = false;
384 
385  $path = $tree->getNodePath($a_ref_id);
386  array_shift($path); // root
387  foreach($path as $node)
388  {
389  $supports_lp = ilObjectLP::isSupportedObjectType($node["type"]);
390 
391  if($supports_lp || $has_lp_parents)
392  {
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($supports_lp &&
403  $node["child"] != $a_ref_id)
404  {
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 
411  // parse LP collection
412  $parent_collection = $parent_obj_lp->getCollectionInstance();
413  if($parent_collection &&
414  $parent_collection->hasSelectableItems() &&
415  $parent_collection->isAssignedEntry($a_ref_id))
416  {
417  $a_res[$node["child"]]["node"]["active"] = true;
418 
419  if($parent_collection instanceof ilLPCollectionOfRepositoryObjects)
420  {
421  $group = array();
422  foreach($parent_collection->getTableGUIData($node["parent"]) as $item)
423  {
424  $found = false;
425  $grp_tmp = array();
426  if($item["grouped"])
427  {
428  // parse grouped items
429  foreach($item["grouped"] as $group_item)
430  {
431  if($group_item["ref_id"] == $a_ref_id)
432  {
433  $found = true;
434  }
435  else
436  {
437  $grp_tmp[$group_item["ref_id"]] = array(
438  "type" => $group_item["type"]
439  ,"title" => $group_item["title"]
440  ,"obj_id" => $group_item["obj_id"]
441  );
442  }
443  }
444  }
445  if(sizeof($grp_tmp) ||
446  $found)
447  {
448  if($item["ref_id"] == $a_ref_id)
449  {
450  // group "parent" item is current object
451  $group = $grp_tmp;
452  }
453  else if($found)
454  {
455  // group "parent" item is not current object
456  // add group "parent" to grouped items
457  $group = $grp_tmp;
458  $group[$item["ref_id"]] = array(
459  "type" => $item["type"]
460  ,"title" => $item["title"]
461  ,"obj_id" => $item["obj_id"]
462  );
463  }
464  }
465  }
466  $a_res[$node["child"]]["group"] = $group;
467  }
468  }
469  }
470  }
471 
472  return $has_lp_parents;
473  }
474 
475  protected function handleLPUsageInfo()
476  {
477  global $lng, $ilAccess;
478 
479  $ref_id = $_GET["ref_id"];
480  if(!$ref_id)
481  {
482  $ref_id = $_REQUEST["ref_id"];
483  }
484 
485  $coll = array();
486  if($ref_id &&
487  $this->getLPPathInfo($ref_id, $coll))
488  {
489  include_once "Services/Link/classes/class.ilLink.php";
490 
491  $tpl = new ilTemplate("tpl.lp_obj_settings_tree_info.html", true, true, "Services/Tracking");
492 
493  $margin = 0;
494  $has_active = false;
495  foreach($coll as $parent_ref_id => $parts)
496  {
497  /* currently not used
498  if($parts["group"])
499  {
500  foreach($parts["group"] as $group_item_ref_id => $group_item)
501  {
502  if($ilAccess->checkAccess("read", "", $group_item_ref_id))
503  {
504  $tpl->setCurrentBlock("group_item_link_bl");
505  $tpl->setVariable("GROUP_ITEM_LINK_TITLE", $group_item["title"]);
506  $tpl->setVariable("GROUP_ITEM_URL", ilLink::_getLink($group_item_ref_id, $group_item["type"], array("gotolp" => 1)));
507  $tpl->parseCurrentBlock();
508  }
509  else
510  {
511  $tpl->setCurrentBlock("group_item_nolink_bl");
512  $tpl->setVariable("GROUP_ITEM_NOLINK_TITLE", $group_item["title"]);
513  $tpl->parseCurrentBlock();
514  }
515 
516  $tpl->setCurrentBlock("group_item_bl");
517  $tpl->setVariable("GROUP_ITEM_TYPE_URL", ilUtil::getTypeIconPath($group_item["type"], $group_item["obj_id"]));
518  $tpl->setVariable("GROUP_ITEM_TYPE_ALT", $lng->txt("obj_".$group_item["type"]));
519  $tpl->parseCurrentBlock();
520  }
521 
522  $tpl->setCurrentBlock("group_bl");
523  $tpl->setVariable("GROUP_INFO", $lng->txt("trac_lp_settings_info_parent_group"));
524  $tpl->parseCurrentBlock();
525  }
526  */
527 
528  $node = $parts["node"];
529 
530  $params = array();
531  if($node["lp"])
532  {
533  if($node["active"])
534  {
535  $tpl->touchBlock("parent_active_bl");
536  $has_active = true;
537  }
538 
539  $params["gotolp"] = 1;
540  }
541 
542  if($ilAccess->checkAccess("read", "", $parent_ref_id) &&
543  $parent_ref_id != $ref_id) // #17170
544  {
545  $tpl->setCurrentBlock("parent_link_bl");
546  $tpl->setVariable("PARENT_LINK_TITLE", $node["title"]);
547  $tpl->setVariable("PARENT_URL", ilLink::_getLink($parent_ref_id, $node["type"], $params));
548  $tpl->parseCurrentBlock();
549  }
550  else
551  {
552  $tpl->setCurrentBlock("parent_nolink_bl");
553  $tpl->setVariable("PARENT_NOLINK_TITLE", $node["title"]);
554  $tpl->parseCurrentBlock();
555  }
556 
557  $tpl->setCurrentBlock("parent_usage_bl");
558  $tpl->setVariable("PARENT_TYPE_URL", ilUtil::getTypeIconPath($node["type"], $node["obj_id"]));
559  $tpl->setVariable("PARENT_TYPE_ALT", $lng->txt("obj_".$node["type"]));
560 
561  $tpl->setVariable("PARENT_STYLE", $node["lp"]
562  ? ''
563  : ' class="ilLPParentInfoListLPUnsupported"');
564  $tpl->setVariable("MARGIN", $margin);
565  $tpl->parseCurrentBlock();
566 
567  $margin += 25;
568  }
569 
570  if($has_active)
571  {
572  $tpl->setVariable("LEGEND", sprintf(
573  $lng->txt("trac_lp_settings_info_parent_legend"),
575  ));
576  }
577 
578  include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
579  $panel = ilPanelGUI::getInstance();
580  $panel->setPanelStyle(ilPanelGUI::PANEL_STYLE_SECONDARY);
581  $panel->setHeading($lng->txt("trac_lp_settings_info_parent_container"));
582  $panel->setBody($tpl->get());
583 
584  return $panel->getHTML();
585  }
586  }
587 }
588 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
$path
Definition: aliased.php:25
getLPPathInfo($a_ref_id, array &$a_res)
Gather LP data about parent objects.
saveSettings()
Save learning progress settings.
This class represents a property form user interface.
deassign()
save mterial assignment
show()
Show settings tables.
$_GET["client_id"]
static isSupportedObjectType($a_type)
$cmd
Definition: sahs_server.php:35
Class ilLPListOfSettingsGUI.
initFormSettings()
Init property form.
static _lookupTitle($a_id)
lookup object title
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
parse(ilLPCollection $a_collection)
Read and parse items.
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...
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$info
Definition: example_052.php:80
This class represents a property in a property form.
setValue($a_value)
Set Value.
This class represents a number property in a property form.
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
saveObligatoryMaterials()
Save obligatory state per grouped materials.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
assign()
Save material assignment.
setSize($a_size)
Set Size.
getTableByMode()
Get tables by mode.
static getInstance()
Get instance.
const PANEL_STYLE_SECONDARY
static getInstance($a_obj_id)
$_POST["username"]
$params
Definition: example_049.php:96
setRequired($a_required)
Set Required.