ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLearningProgressGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
5 
18 {
19  function ilLearningProgressGUI($a_mode,$a_ref_id = 0,$a_user_id = 0)
20  {
21  parent::ilLearningProgressBaseGUI($a_mode,$a_ref_id,$a_user_id);
22  }
23 
27  function &executeCommand()
28  {
29  global $ilBench, $ilHelp, $ilAccess;
30 
31  $ilBench->start('LearningProgress','0000_Start');
32 
33 
34  $this->ctrl->setReturn($this, "");
35 
36  // E.g personal desktop mode needs locator header icon ...
37  $this->__buildHeader();
38  switch($this->__getNextClass())
39  {
40  case 'illplistofprogressgui':
41  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfProgressGUI.php';
42 
43  $ilHelp->setScreenIdComponent("lp");
44 
45  $this->__setSubTabs(self::LP_ACTIVE_PROGRESS);
46  $this->__setCmdClass('illplistofprogressgui');
47  $lop_gui = new ilLPListOfProgressGUI($this->getMode(),$this->getRefId(),$this->getUserId());
48  $this->ctrl->forwardCommand($lop_gui);
49  break;
50 
51  case 'illplistofobjectsgui':
52  if($this->getRefId() &&
53  !$ilAccess->checkAccess('read_learning_progress', '', $this->getRefId()))
54  {
55  return;
56  }
57 
58  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfObjectsGUI.php';
59  if(stristr($this->ctrl->getCmd(), "matrix"))
60  {
61  $this->__setSubTabs(self::LP_ACTIVE_MATRIX);
62  }
63  else if(stristr($this->ctrl->getCmd(), "summary"))
64  {
65  $this->__setSubTabs(self::LP_ACTIVE_SUMMARY);
66  }
67  else
68  {
69  $this->__setSubTabs(self::LP_ACTIVE_OBJECTS);
70  }
71  $loo_gui = new ilLPListOfObjectsGUI($this->getMode(),$this->getRefId());
72  $this->__setCmdClass('illplistofobjectsgui');
73  $this->ctrl->forwardCommand($loo_gui);
74  break;
75 
76  case 'illplistofsettingsgui':
77  if($this->getRefId() &&
78  !$ilAccess->checkAccess('edit_learning_progress', '', $this->getRefId()))
79  {
80  return;
81  }
82 
83  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfSettingsGUI.php';
84 
85  $this->__setSubTabs(self::LP_ACTIVE_SETTINGS);
86  $los_gui = new ilLPListOfSettingsGUI($this->getMode(),$this->getRefId());
87  $this->__setCmdClass('illplistofsettingsgui');
88  $this->ctrl->forwardCommand($los_gui);
89  break;
90 
91  case 'illpobjectstatisticsgui':
92  include_once 'Services/Tracking/classes/object_statistics/class.ilLPObjectStatisticsGUI.php';
93  if(stristr($this->ctrl->getCmd(), "access"))
94  {
95  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATACCESS);
96  }
97  else if(stristr($this->ctrl->getCmd(), "types"))
98  {
99  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATTYPES);
100  }
101  else if(stristr($this->ctrl->getCmd(), "daily"))
102  {
103  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATDAILY);
104  }
105  else
106  {
107  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATADMIN);
108  }
109  $this->__setCmdClass('illpobjectstatisticsgui');
110  $ost_gui = new ilLPObjectStatisticsGUI($this->getMode(),$this->getRefId());
111  $this->ctrl->forwardCommand($ost_gui);
112  break;
113 
114  default:
115  $cmd = $this->ctrl->getCmd();
116  $this->$cmd();
117  $this->tpl->show(true);
118  break;
119  }
120 
121  // E.G personal desktop mode needs $tpl->show();
122  $this->__buildFooter();
123 
124 
125  $ilBench->stop('LearningProgress','0000_Start');
126 
127  return true;
128  }
129 
130  function __setCmdClass($a_class)
131  {
132  // If cmd class == 'illearningprogressgui' the cmd class is set to the the new forwarded class
133  // otherwise e.g illplistofprogressgui tries to forward (back) to illearningprogressgui.
134 
135  if($this->ctrl->getCmdClass() == strtolower(get_class($this)))
136  {
137  $this->ctrl->setCmdClass(strtolower($a_class));
138  }
139  return true;
140  }
141 
142  function __getNextClass()
143  {
144  global $ilAccess, $ilUser;
145 
146  // #9857
148  {
149  return;
150  }
151 
152  if(strlen($next_class = $this->ctrl->getNextClass()))
153  {
155  {
156  $_SESSION['il_lp_history'] = $next_class;
157  }
158  return $next_class;
159  }
160  switch($this->getMode())
161  {
162  case self::LP_CONTEXT_ADMINISTRATION:
163  return 'illplistofobjectsgui';
164 
165  case self::LP_CONTEXT_REPOSITORY:
166  $cmd = $this->ctrl->getCmd();
167  if(in_array($cmd, array("editmanual", "updatemanual", "showtlt")))
168  {
169  return "";
170  }
171 
172  // #12771
173  include_once './Services/Object/classes/class.ilObjectLP.php';
175  if(!$olp->isActive())
176  {
177  if(!($olp instanceof ilPluginLP) &&
178  $ilAccess->checkAccess('edit_learning_progress','',$this->getRefId()))
179  {
180  return 'illplistofsettingsgui';
181  }
182  else
183  {
184  return '';
185  }
186  }
187 
188  if(!$this->anonymized &&
189  $ilAccess->checkAccess('read_learning_progress','',$this->getRefId()))
190  {
191  return 'illplistofobjectsgui';
192  }
193  if($ilAccess->checkAccess('edit_learning_progress','',$this->getRefId()))
194  {
195  return 'illplistofsettingsgui';
196  }
197  return 'illplistofprogressgui';
198 
199  case self::LP_CONTEXT_PERSONAL_DESKTOP:
200 
201  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
204 
205  if($has_edit || $has_personal)
206  {
207  // default (#10928)
208  $tgt = null;
209  if($has_personal)
210  {
211  $tgt = 'illplistofprogressgui';
212  }
213  else if($has_edit)
214  {
215  $tgt = 'illplistofobjectsgui';
216  }
217 
218  // validate session
219  switch($_SESSION['il_lp_history'])
220  {
221  case 'illplistofobjectsgui':
222  if(!$has_edit)
223  {
224  $_SESSION['il_lp_history'] = null;
225  }
226  break;
227 
228  case 'illplistofprogressgui':
229  if(!$has_personal)
230  {
231  $_SESSION['il_lp_history'] = null;
232  }
233  break;
234  }
235 
236  if($_SESSION['il_lp_history'])
237  {
238  return $_SESSION['il_lp_history'];
239  }
240  else if($tgt)
241  {
242  return $tgt;
243  }
244  }
245 
246  // should not happen
247  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI");
248 
249  case self::LP_CONTEXT_USER_FOLDER:
250  case self::LP_CONTEXT_ORG_UNIT:
252  {
253  return 'illplistofprogressgui';
254  }
255  break;
256  }
257  }
258 
259  protected function editManual()
260  {
261  global $tpl;
262 
263  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
265  {
266  include_once './Services/Object/classes/class.ilObjectLP.php';
268  if($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL)
269  {
270  $form = $this->initCollectionManualForm();
271  $tpl->setContent($form->getHTML());
272  }
273  }
274  }
275 
276  protected function initCollectionManualForm()
277  {
278  global $lng, $ilCtrl;
279 
280  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
281  $form = new ilPropertyFormGUI();
282  $form->setFormAction($ilCtrl->getFormAction($this, "updatemanual"));
283  $form->setTitle($lng->txt("learning_progress"));
284  $form->setDescription($lng->txt("trac_collection_manual_learner_info"));
285 
286  $coll_items = array();
287 
288  include_once './Services/Object/classes/class.ilObjectLP.php';
289  $olp = ilObjectLP::getInstance($this->getObjId());
290  $collection = $olp->getCollectionInstance();
291  if($collection)
292  {
293  $coll_items = $collection->getItems();
294  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
295 
296  switch(ilObject::_lookupType($this->getObjId()))
297  {
298  case "lm":
299  $subitem_title = $lng->txt("objs_st");
300  $subitem_info = $lng->txt("trac_collection_manual_learner_lm_info");
301  break;
302  }
303  }
304 
305  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
307  $lp_data = $class::_getObjectStatus($this->getObjId(), $this->usr_id);
308 
309  $grp = new ilCheckboxGroupInputGUI($subitem_title, "sids");
310  $grp->setInfo($subitem_info);
311  $form->addItem($grp);
312 
313  // #14994 - using possible items for proper sorting
314 
315  $completed = array();
316  foreach(array_keys($possible_items) as $item_id)
317  {
318  if(!in_array($item_id, $coll_items))
319  {
320  continue;
321  }
322 
323  $info = null;
325 
326  if(isset($lp_data[$item_id]))
327  {
328  $changed = new ilDateTime($lp_data[$item_id][1], IL_CAL_UNIX);
329  $info = $lng->txt("trac_collection_manual_learner_changed_ts").": ".
331 
332  if($lp_data[$item_id][0])
333  {
335  $completed[] = $item_id;
336  }
337  }
338 
341  $icon = ilUtil::img($path, $text);
342 
343  $opt = new ilCheckboxOption($icon." ".$possible_items[$item_id]["title"], $item_id);
344  if($info)
345  {
346  $opt->setInfo($info);
347  }
348  $grp->addOption($opt);
349  }
350 
351  if($completed)
352  {
353  $grp->setValue($completed);
354  }
355 
356  $form->addCommandButton("updatemanual", $lng->txt("save"));
357 
358  return $form;
359  }
360 
361  protected function updateManual()
362  {
363  global $ilCtrl, $lng;
364 
365  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
367  {
368  include_once './Services/Object/classes/class.ilObjectLP.php';
370  if($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL)
371  {
372  $form = $this->initCollectionManualForm();
373  if($form->checkInput())
374  {
375  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
377  $class::_setObjectStatus($this->getObjId(), $this->usr_id, $form->getInput("sids"));
378 
379  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
380  }
381 
382  $ilCtrl->redirect($this, "editmanual");
383  }
384  }
385  }
386 
387  protected function showtlt()
388  {
389  global $lng, $ilCtrl, $tpl, $ilUser;
390 
391  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
392  $form = new ilPropertyFormGUI();
393  $form->setFormAction($ilCtrl->getFormAction($this, "showtlt"));
394  $form->setTitle($lng->txt("learning_progress"));
395  $form->setDescription($lng->txt("trac_collection_tlt_learner_info"));
396 
397  $coll_items = array();
398 
399  include_once './Services/Object/classes/class.ilObjectLP.php';
400  $olp = ilObjectLP::getInstance($this->getObjId());
401  $collection = $olp->getCollectionInstance();
402  if($collection)
403  {
404  $coll_items = $collection->getItems();
405  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
406  }
407 
408  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
410  $info = $class::_getStatusInfo($this->getObjId(), true);
411 
412  foreach($coll_items as $item_id)
413  {
414  // #16599 - deleted items should not be displayed
415  if(!array_key_exists($item_id, $possible_items))
416  {
417  continue;
418  }
419 
420  $field = new ilCustomInputGUI($possible_items[$item_id]["title"]);
421 
422  // lp status
424  if(isset($info["completed"][$item_id]) &&
425  in_array($ilUser->getId(), $info["completed"][$item_id]))
426  {
428  }
429  else if(isset($info["in_progress"][$item_id]) &&
430  in_array($ilUser->getId(), $info["in_progress"][$item_id]))
431  {
433  }
436  $field->setHtml(ilUtil::img($path, $text));
437 
438  // stats
439  $spent = 0;
440  if(isset($info["tlt_users"][$item_id][$ilUser->getId()]))
441  {
442  $spent = $info["tlt_users"][$item_id][$ilUser->getId()];
443  }
444  $needed = $info["tlt"][$item_id];
445  if($needed)
446  {
447  $field->setInfo(sprintf($lng->txt("trac_collection_tlt_learner_subitem"),
449  ilFormat::_secondsToString($needed),
450  min(100, round(abs($spent)/$needed*100))));
451  }
452 
453  $form->addItem($field);
454  }
455 
456  $tpl->setContent($form->getHTML());
457  }
458 }
459 ?>