ILIAS  Release_4_4_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('edit_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 'illmstatisticsgui':
92  include_once 'Services/Tracking/classes/class.ilLMStatisticsGUI.php';
93 
94  $this->__setSubTabs(self::LP_ACTIVE_LM_STATISTICS);
95  $los_gui = new ilLMStatisticsGUI($this->getMode(),$this->getRefId());
96  $this->__setCmdClass('illmstatisticsgui');
97  $this->ctrl->forwardCommand($los_gui);
98  break;
99 
100  case 'illpobjectstatisticsgui':
101  include_once 'Services/Tracking/classes/object_statistics/class.ilLPObjectStatisticsGUI.php';
102  if(stristr($this->ctrl->getCmd(), "access"))
103  {
104  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATACCESS);
105  }
106  else if(stristr($this->ctrl->getCmd(), "types"))
107  {
108  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATTYPES);
109  }
110  else if(stristr($this->ctrl->getCmd(), "daily"))
111  {
112  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATDAILY);
113  }
114  else
115  {
116  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATADMIN);
117  }
118  $this->__setCmdClass('illpobjectstatisticsgui');
119  $ost_gui = new ilLPObjectStatisticsGUI($this->getMode(),$this->getRefId());
120  $this->ctrl->forwardCommand($ost_gui);
121  break;
122 
123  default:
124  $cmd = $this->ctrl->getCmd();
125  $this->$cmd();
126  $this->tpl->show(true);
127  break;
128  }
129 
130  // E.G personal desktop mode needs $tpl->show();
131  $this->__buildFooter();
132 
133 
134  $ilBench->stop('LearningProgress','0000_Start');
135 
136  return true;
137  }
138 
139  function __setCmdClass($a_class)
140  {
141  // If cmd class == 'illearningprogressgui' the cmd class is set to the the new forwarded class
142  // otherwise e.g illplistofprogressgui tries to forward (back) to illearningprogressgui.
143 
144  if($this->ctrl->getCmdClass() == strtolower(get_class($this)))
145  {
146  $this->ctrl->setCmdClass(strtolower($a_class));
147  }
148  return true;
149  }
150 
151  function __getNextClass()
152  {
153  global $ilAccess, $ilUser;
154 
155  // #9857
157  {
158  return;
159  }
160 
161  if(strlen($next_class = $this->ctrl->getNextClass()))
162  {
164  {
165  $_SESSION['il_lp_history'] = $next_class;
166  }
167  return $next_class;
168  }
169  switch($this->getMode())
170  {
171  case self::LP_CONTEXT_ADMINISTRATION:
172  return 'illplistofobjectsgui';
173 
174  case self::LP_CONTEXT_REPOSITORY:
175  $cmd = $this->ctrl->getCmd();
176  if(in_array($cmd, array("editmanual", "updatemanual", "showtlt")))
177  {
178  return "";
179  }
180 
181  // #12771
182  include_once './Services/Object/classes/class.ilObjectLP.php';
184  if(!$olp->isActive())
185  {
186  return 'illplistofsettingsgui';
187  }
188 
189  if(!$this->anonymized and
190  $ilAccess->checkAccess('edit_learning_progress','',$this->getRefId()))
191  {
192  return 'illplistofobjectsgui';
193  }
194  return 'illplistofprogressgui';
195 
196  case self::LP_CONTEXT_PERSONAL_DESKTOP:
197 
198  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
201 
202  if($has_edit || $has_personal)
203  {
204  // default (#10928)
205  $tgt = null;
206  if($has_personal)
207  {
208  $tgt = 'illplistofprogressgui';
209  }
210  else if($has_edit)
211  {
212  $tgt = 'illplistofobjectsgui';
213  }
214 
215  // validate session
216  switch($_SESSION['il_lp_history'])
217  {
218  case 'illplistofobjectsgui':
219  if(!$has_edit)
220  {
221  $_SESSION['il_lp_history'] = null;
222  }
223  break;
224 
225  case 'illplistofprogressgui':
226  if(!$has_personal)
227  {
228  $_SESSION['il_lp_history'] = null;
229  }
230  break;
231  }
232 
233  if($_SESSION['il_lp_history'])
234  {
235  return $_SESSION['il_lp_history'];
236  }
237  else if($tgt)
238  {
239  return $tgt;
240  }
241  }
242 
243  // should not happen
244  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI");
245 
246  case self::LP_CONTEXT_USER_FOLDER:
247  case self::LP_CONTEXT_ORG_UNIT:
249  {
250  return 'illplistofprogressgui';
251  }
252  }
253  }
254 
255  protected function editManual()
256  {
257  global $tpl;
258 
259  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
261  {
262  include_once './Services/Object/classes/class.ilObjectLP.php';
264  if($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL)
265  {
266  $form = $this->initCollectionManualForm();
267  $tpl->setContent($form->getHTML());
268  }
269  }
270  }
271 
272  protected function initCollectionManualForm()
273  {
274  global $lng, $ilCtrl;
275 
276  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
277  $form = new ilPropertyFormGUI();
278  $form->setFormAction($ilCtrl->getFormAction($this, "updatemanual"));
279  $form->setTitle($lng->txt("learning_progress"));
280  $form->setDescription($lng->txt("trac_collection_manual_learner_info"));
281 
282  $coll_items = array();
283 
284  include_once './Services/Object/classes/class.ilObjectLP.php';
285  $olp = ilObjectLP::getInstance($this->getObjId());
286  $collection = $olp->getCollectionInstance();
287  if($collection)
288  {
289  $coll_items = $collection->getItems();
290  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
291 
292  switch(ilObject::_lookupType($this->getObjId()))
293  {
294  case "lm":
295  $subitem_title = $lng->txt("objs_st");
296  $subitem_info = $lng->txt("trac_collection_manual_learner_lm_info");
297  break;
298  }
299  }
300 
301  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
303  $lp_data = $class::_getObjectStatus($this->getObjId(), $this->usr_id);
304 
305  $grp = new ilCheckboxGroupInputGUI($subitem_title, "sids");
306  $grp->setInfo($subitem_info);
307  $form->addItem($grp);
308 
309  $completed = array();
310  foreach($coll_items as $item_id)
311  {
312  $info = null;
314 
315  if(isset($lp_data[$item_id]))
316  {
317  $changed = new ilDateTime($lp_data[$item_id][1], IL_CAL_UNIX);
318  $info = $lng->txt("trac_collection_manual_learner_changed_ts").": ".
320 
321  if($lp_data[$item_id][0])
322  {
324  $completed[] = $item_id;
325  }
326  }
327 
330  $icon = ilUtil::img($path, $text);
331 
332  $opt = new ilCheckboxOption($icon." ".$possible_items[$item_id]["title"], $item_id);
333  if($info)
334  {
335  $opt->setInfo($info);
336  }
337  $grp->addOption($opt);
338  }
339 
340  if($completed)
341  {
342  $grp->setValue($completed);
343  }
344 
345  $form->addCommandButton("updatemanual", $lng->txt("save"));
346 
347  return $form;
348  }
349 
350  protected function updateManual()
351  {
352  global $ilCtrl, $lng;
353 
354  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
356  {
357  include_once './Services/Object/classes/class.ilObjectLP.php';
359  if($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL)
360  {
361  $form = $this->initCollectionManualForm();
362  if($form->checkInput())
363  {
364  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
366  $class::_setObjectStatus($this->getObjId(), $this->usr_id, $form->getInput("sids"));
367 
368  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
369  }
370 
371  $ilCtrl->redirect($this, "editmanual");
372  }
373  }
374  }
375 
376  protected function showtlt()
377  {
378  global $lng, $ilCtrl, $tpl, $ilUser;
379 
380  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
381  $form = new ilPropertyFormGUI();
382  $form->setFormAction($ilCtrl->getFormAction($this, "showtlt"));
383  $form->setTitle($lng->txt("learning_progress"));
384  $form->setDescription($lng->txt("trac_collection_tlt_learner_info"));
385 
386  $coll_items = array();
387 
388  include_once './Services/Object/classes/class.ilObjectLP.php';
389  $olp = ilObjectLP::getInstance($this->getObjId());
390  $collection = $olp->getCollectionInstance();
391  if($collection)
392  {
393  $coll_items = $collection->getItems();
394  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
395  }
396 
397  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
399  $info = $class::_getStatusInfo($this->getObjId(), true);
400 
401  foreach($coll_items as $item_id)
402  {
403  // #16599 - deleted items should not be displayed
404  if(!array_key_exists($item_id, $possible_items))
405  {
406  continue;
407  }
408 
409  $field = new ilCustomInputGUI($possible_items[$item_id]["title"]);
410 
411  // lp status
413  if(isset($info["completed"][$item_id]) &&
414  in_array($ilUser->getId(), $info["completed"][$item_id]))
415  {
417  }
418  else if(isset($info["in_progress"][$item_id]) &&
419  in_array($ilUser->getId(), $info["in_progress"][$item_id]))
420  {
422  }
425  $field->setHtml(ilUtil::img($path, $text));
426 
427  // stats
428  $spent = 0;
429  if(isset($info["tlt_users"][$item_id][$ilUser->getId()]))
430  {
431  $spent = $info["tlt_users"][$item_id][$ilUser->getId()];
432  }
433  $needed = $info["tlt"][$item_id];
434  if($needed)
435  {
436  $field->setInfo(sprintf($lng->txt("trac_collection_tlt_learner_subitem"),
438  ilFormat::_secondsToString($needed),
439  min(100, round($spent/$needed*100))));
440  }
441 
442  $form->addItem($field);
443  }
444 
445  $tpl->setContent($form->getHTML());
446  }
447 }
448 ?>