ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  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 $ilHelp;
55 
56  $ilHelp->setSubScreenId("trac_settings");
57 
58  $info = $this->obj_lp->getSettingsInfo();
59  if ($info) {
61  }
62 
63  $form = $this->initFormSettings();
64  $this->tpl->setContent(
65  $this->handleLPUsageInfo() .
66  $form->getHTML() .
67  $this->getTableByMode()
68  );
69  }
70 
71 
77  protected function initFormSettings()
78  {
79  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
80  $form = new ilPropertyFormGUI();
81  $form->setTitle($this->lng->txt('tracking_settings'));
82  $form->setFormAction($this->ctrl->getFormAction($this));
83 
84  // Mode
85  $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus');
86  $mod->setRequired(true);
87  $mod->setValue($this->obj_lp->getCurrentMode());
88  $form->addItem($mod);
89 
90  foreach ($this->obj_lp->getValidModes() as $mode_key) {
91  $opt = new ilRadioOption(
92  $this->obj_lp->getModeText($mode_key),
93  $mode_key,
94  $this->obj_lp->getModeInfoText($mode_key)
95  );
96  $opt->setValue($mode_key);
97  $mod->addOption($opt);
98 
99  // :TODO: Subitem for visits ?!
100  if ($mode_key == ilLPObjSettings::LP_MODE_VISITS) {
101  $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits');
102  $vis->setSize(3);
103  $vis->setMaxLength(4);
104  $vis->setInfo(sprintf(
105  $this->lng->txt('trac_visits_info'),
107  ));
108  $vis->setRequired(true);
109  $vis->setValue($this->obj_settings->getVisits());
110  $opt->addSubItem($vis);
111  }
112  }
113 
114  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
115 
116  return $form;
117  }
118 
123  protected function saveSettings()
124  {
125  $form = $this->initFormSettings();
126  if ($form->checkInput()) {
127  // anything changed?
128 
129  // mode
130  $new_mode = (int) $form->getInput('modus');
131  $old_mode = $this->obj_lp->getCurrentMode();
132  $mode_changed = ($old_mode != $new_mode);
133 
134  // visits
135  $new_visits = null;
136  $visits_changed = null;
137  if ($new_mode == ilLPObjSettings::LP_MODE_VISITS) {
138  $new_visits = (int) $form->getInput('visits');
139  $old_visits = $this->obj_settings->getVisits();
140  $visits_changed = ($old_visits != $new_visits);
141  }
142 
143  if ($mode_changed) {
144  // delete existing collection
145  $collection = $this->obj_lp->getCollectionInstance();
146  if ($collection) {
147  $collection->delete();
148  }
149  }
150 
151  $refresh_lp = ($mode_changed || $visits_changed);
152 
153  // has to be done before LP refresh!
154  $this->obj_lp->resetCaches();
155 
156  $this->obj_settings->setMode($new_mode);
157  $this->obj_settings->setVisits($new_visits);
158  $this->obj_settings->update($refresh_lp);
159 
160  if ($mode_changed &&
161  $this->obj_lp->getCollectionInstance() &&
162  $new_mode != ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR) { // #14819
163  ilUtil::sendInfo($this->lng->txt('trac_edit_collection'), true);
164  }
165  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
166  $this->ctrl->redirect($this, 'show');
167  }
168 
169  $form->setValuesByPost();
170  ilUtil::sendFailure($this->lng->txt('err_check_input'));
171 
172  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lp_obj_settings.html', 'Services/Tracking');
173  $this->tpl->setVariable('PROP_FORM', $form->getHTML());
174  $this->tpl->setVariable('COLLECTION_TABLE', $this->getTableByMode());
175  }
176 
180  protected function getTableByMode()
181  {
182  $collection = $this->obj_lp->getCollectionInstance();
183  if ($collection && $collection->hasSelectableItems()) {
184  include_once "Services/Tracking/classes/repository_statistics/class.ilLPCollectionSettingsTableGUI.php";
185  $table = new ilLPCollectionSettingsTableGUI($this, 'show', $this->getRefId(), $this->obj_lp->getCurrentMode());
186  $table->parse($collection);
187  return $table->getHTML();
188  }
189  }
190 
195  protected function assign()
196  {
197  if (!$_POST['item_ids']) {
198  ilUtil::sendFailure($this->lng->txt('select_one'), true);
199  $this->ctrl->redirect($this, 'show');
200  }
201  if (count($_POST['item_ids'])) {
202  $collection = $this->obj_lp->getCollectionInstance();
203  if ($collection && $collection->hasSelectableItems()) {
204  $collection->activateEntries($_POST['item_ids']);
205  }
206 
207  // #15045 - has to be done before LP refresh!
208  $this->obj_lp->resetCaches();
209 
210  // refresh learning progress
211  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
213  }
214  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
215  $this->ctrl->redirect($this, 'show');
216  }
217 
222  protected function deassign()
223  {
224  if (!$_POST['item_ids']) {
225  ilUtil::sendFailure($this->lng->txt('select_one'), true);
226  $this->ctrl->redirect($this, 'show');
227  return false;
228  }
229  if (count($_POST['item_ids'])) {
230  $collection = $this->obj_lp->getCollectionInstance();
231  if ($collection && $collection->hasSelectableItems()) {
232  $collection->deactivateEntries($_POST['item_ids']);
233  }
234 
235  // #15045 - has to be done before LP refresh!
236  $this->obj_lp->resetCaches();
237 
238  // refresh learning progress
239  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
241  }
242  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
243  $this->ctrl->redirect($this, 'show');
244  }
245 
249  protected function groupMaterials()
250  {
251  if (!count((array) $_POST['item_ids'])) {
252  ilUtil::sendFailure($this->lng->txt('select_one'), true);
253  $this->ctrl->redirect($this, 'show');
254  }
255 
256  $collection = $this->obj_lp->getCollectionInstance();
257  if ($collection && $collection->hasSelectableItems()) {
258  // Assign new grouping id
259  $collection->createNewGrouping((array) $_POST['item_ids']);
260 
261  // refresh learning progress
262  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
264  }
265 
266  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
267  $this->ctrl->redirect($this, 'show');
268  }
269 
273  protected function releaseMaterials()
274  {
275  if (!count((array) $_POST['item_ids'])) {
276  ilUtil::sendFailure($this->lng->txt('select_one'), true);
277  $this->ctrl->redirect($this, 'show');
278  }
279 
280  $collection = $this->obj_lp->getCollectionInstance();
281  if ($collection && $collection->hasSelectableItems()) {
282  $collection->releaseGrouping((array) $_POST['item_ids']);
283 
284  // refresh learning progress
285  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
287  }
288 
289  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
290  $this->ctrl->redirect($this, 'show');
291  }
292 
296  protected function saveObligatoryMaterials()
297  {
298  if (!is_array((array) $_POST['grp'])) {
299  ilUtil::sendFailure($this->lng->txt('select_one'), true);
300  $this->ctrl->redirect($this, 'show');
301  }
302 
303  try {
304  $collection = $this->obj_lp->getCollectionInstance();
305  if ($collection && $collection->hasSelectableItems()) {
306  $collection->saveObligatoryMaterials((array) $_POST['grp']);
307 
308  // refresh learning progress
309  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
311  }
312 
313  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
314  $this->ctrl->redirect($this, 'show');
315  } catch (UnexpectedValueException $e) {
316  ilUtil::sendFailure($this->lng->txt('trac_grouped_material_obligatory_err'), true);
317  ilUtil::sendInfo($this->lng->txt('err_check_input'), true);
318  $this->ctrl->redirect($this, 'show');
319  }
320  }
321 
322  protected function updateTLT()
323  {
324  include_once "Services/MetaData/classes/class.ilMD.php";
325  foreach ($_POST['tlt'] as $item_id => $item) {
326  $md_obj = new ilMD($this->getObjId(), $item_id, 'st');
327  if (!is_object($md_section = $md_obj->getEducational())) {
328  $md_section = $md_obj->addEducational();
329  $md_section->save();
330  }
331  $md_section->setPhysicalTypicalLearningTime(
332  (int) $item['mo'],
333  (int) $item['d'],
334  (int) $item['h'],
335  (int) $item['m'],
336  0
337  );
338  $md_section->update();
339  }
340 
341  // refresh learning progress
342  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
344 
345  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
346  $this->ctrl->redirect($this, 'show');
347  }
348 
349 
350  //
351  // USAGE INFO
352  //
353 
361  protected function getLPPathInfo($a_ref_id, array &$a_res)
362  {
363  global $tree;
364 
365  $has_lp_parents = false;
366 
367  $path = $tree->getNodePath($a_ref_id);
368  array_shift($path); // root
369  foreach ($path as $node) {
370  $supports_lp = ilObjectLP::isSupportedObjectType($node["type"]);
371 
372  if ($supports_lp || $has_lp_parents) {
373  $a_res[$node["child"]]["node"] = array(
374  "type" => $node["type"]
375  ,"title" => $node["title"]
376  ,"obj_id" => $node["obj_id"]
377  ,"lp" => false
378  ,"active" => false
379  );
380  }
381 
382  if ($supports_lp &&
383  $node["child"] != $a_ref_id) {
384  $a_res[$node["child"]]["node"]["lp"] = true;
385  $has_lp_parents = true;
386 
387  $parent_obj_id = $node["obj_id"];
388  $parent_obj_lp = ilObjectLP::getInstance($parent_obj_id);
389 
390  // parse LP collection
391  $parent_collection = $parent_obj_lp->getCollectionInstance();
392  if ($parent_collection &&
393  $parent_collection->hasSelectableItems() &&
394  $parent_collection->isAssignedEntry($a_ref_id)) {
395  $a_res[$node["child"]]["node"]["active"] = true;
396 
397  if ($parent_collection instanceof ilLPCollectionOfRepositoryObjects) {
398  $group = array();
399  foreach ($parent_collection->getTableGUIData($node["parent"]) as $item) {
400  $found = false;
401  $grp_tmp = array();
402  if ($item["grouped"]) {
403  // parse grouped items
404  foreach ($item["grouped"] as $group_item) {
405  if ($group_item["ref_id"] == $a_ref_id) {
406  $found = true;
407  } else {
408  $grp_tmp[$group_item["ref_id"]] = array(
409  "type" => $group_item["type"]
410  ,"title" => $group_item["title"]
411  ,"obj_id" => $group_item["obj_id"]
412  );
413  }
414  }
415  }
416  if (sizeof($grp_tmp) ||
417  $found) {
418  if ($item["ref_id"] == $a_ref_id) {
419  // group "parent" item is current object
420  $group = $grp_tmp;
421  } elseif ($found) {
422  // group "parent" item is not current object
423  // add group "parent" to grouped items
424  $group = $grp_tmp;
425  $group[$item["ref_id"]] = array(
426  "type" => $item["type"]
427  ,"title" => $item["title"]
428  ,"obj_id" => $item["obj_id"]
429  );
430  }
431  }
432  }
433  $a_res[$node["child"]]["group"] = $group;
434  }
435  }
436  }
437  }
438 
439  return $has_lp_parents;
440  }
441 
442  protected function handleLPUsageInfo()
443  {
444  global $lng, $ilAccess;
445 
446  $ref_id = $_GET["ref_id"];
447  if (!$ref_id) {
448  $ref_id = $_REQUEST["ref_id"];
449  }
450 
451  $coll = array();
452  if ($ref_id &&
453  $this->getLPPathInfo($ref_id, $coll)) {
454  include_once "Services/Link/classes/class.ilLink.php";
455 
456  $tpl = new ilTemplate("tpl.lp_obj_settings_tree_info.html", true, true, "Services/Tracking");
457 
458  $margin = 0;
459  $has_active = false;
460  foreach ($coll as $parent_ref_id => $parts) {
461  /* currently not used
462  if($parts["group"])
463  {
464  foreach($parts["group"] as $group_item_ref_id => $group_item)
465  {
466  if($ilAccess->checkAccess("read", "", $group_item_ref_id))
467  {
468  $tpl->setCurrentBlock("group_item_link_bl");
469  $tpl->setVariable("GROUP_ITEM_LINK_TITLE", $group_item["title"]);
470  $tpl->setVariable("GROUP_ITEM_URL", ilLink::_getLink($group_item_ref_id, $group_item["type"], array("gotolp" => 1)));
471  $tpl->parseCurrentBlock();
472  }
473  else
474  {
475  $tpl->setCurrentBlock("group_item_nolink_bl");
476  $tpl->setVariable("GROUP_ITEM_NOLINK_TITLE", $group_item["title"]);
477  $tpl->parseCurrentBlock();
478  }
479 
480  $tpl->setCurrentBlock("group_item_bl");
481  $tpl->setVariable("GROUP_ITEM_TYPE_URL", ilUtil::getTypeIconPath($group_item["type"], $group_item["obj_id"]));
482  $tpl->setVariable("GROUP_ITEM_TYPE_ALT", $lng->txt("obj_".$group_item["type"]));
483  $tpl->parseCurrentBlock();
484  }
485 
486  $tpl->setCurrentBlock("group_bl");
487  $tpl->setVariable("GROUP_INFO", $lng->txt("trac_lp_settings_info_parent_group"));
488  $tpl->parseCurrentBlock();
489  }
490  */
491 
492  $node = $parts["node"];
493 
494  $params = array();
495  if ($node["lp"]) {
496  if ($node["active"]) {
497  $tpl->touchBlock("parent_active_bl");
498  $has_active = true;
499  }
500 
501  $params["gotolp"] = 1;
502  }
503 
504  if ($ilAccess->checkAccess("read", "", $parent_ref_id) &&
505  $parent_ref_id != $ref_id) { // #17170
506  $tpl->setCurrentBlock("parent_link_bl");
507  $tpl->setVariable("PARENT_LINK_TITLE", $node["title"]);
508  $tpl->setVariable("PARENT_URL", ilLink::_getLink($parent_ref_id, $node["type"], $params));
509  $tpl->parseCurrentBlock();
510  } else {
511  $tpl->setCurrentBlock("parent_nolink_bl");
512  $tpl->setVariable("PARENT_NOLINK_TITLE", $node["title"]);
513  $tpl->parseCurrentBlock();
514  }
515 
516  $tpl->setCurrentBlock("parent_usage_bl");
517  $tpl->setVariable("PARENT_TYPE_URL", ilUtil::getTypeIconPath($node["type"], $node["obj_id"]));
518  $tpl->setVariable("PARENT_TYPE_ALT", $lng->txt("obj_" . $node["type"]));
519 
520  $tpl->setVariable("PARENT_STYLE", $node["lp"]
521  ? ''
522  : ' class="ilLPParentInfoListLPUnsupported"');
523  $tpl->setVariable("MARGIN", $margin);
524  $tpl->parseCurrentBlock();
525 
526  $margin += 25;
527  }
528 
529  if ($has_active) {
530  $tpl->setVariable("LEGEND", sprintf(
531  $lng->txt("trac_lp_settings_info_parent_legend"),
533  ));
534  }
535 
536  include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
537  $panel = ilPanelGUI::getInstance();
538  $panel->setPanelStyle(ilPanelGUI::PANEL_STYLE_SECONDARY);
539  $panel->setHeading($lng->txt("trac_lp_settings_info_parent_container"));
540  $panel->setBody($tpl->get());
541 
542  return $panel->getHTML();
543  }
544  }
545 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$params
Definition: disable.php:11
This class represents an option in a radio group.
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)
Class ilLPListOfSettingsGUI.
initFormSettings()
Init property form.
static _lookupTitle($a_id)
lookup object title
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
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.
This class represents a property in a property form.
setValue($a_value)
Set Value.
if(isset($_POST['submit'])) $form
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
if(empty($password)) $table
Definition: pwgen.php:24
$info
Definition: index.php:5
static getInstance($a_obj_id)
$_POST["username"]
setRequired($a_required)
Set Required.