ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
22  function executeCommand()
23  {
24  global $ilBench, $ilHelp, $ilAccess;
25 
26  $ilBench->start('LearningProgress','0000_Start');
27 
28  $this->ctrl->setReturn($this, "");
29 
30  // E.g personal desktop mode needs locator header icon ...
31  $this->__buildHeader();
32  switch($this->__getNextClass())
33  {
34  case 'illplistofprogressgui':
35  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfProgressGUI.php';
36 
37  $ilHelp->setScreenIdComponent("lp");
38 
39  $this->__setSubTabs(self::LP_ACTIVE_PROGRESS);
40  $this->__setCmdClass('illplistofprogressgui');
41  $lop_gui = new ilLPListOfProgressGUI($this->getMode(),$this->getRefId(),$this->getUserId());
42  $this->ctrl->forwardCommand($lop_gui);
43  break;
44 
45  case 'illplistofobjectsgui':
46  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
47  if($this->getRefId() &&
48  !ilLearningProgressAccess::checkPermission('read_learning_progress', $this->getRefId()))
49  {
50  return;
51  }
52 
53  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfObjectsGUI.php';
54  if(stristr($this->ctrl->getCmd(), "matrix"))
55  {
56  $this->__setSubTabs(self::LP_ACTIVE_MATRIX);
57  }
58  else if(stristr($this->ctrl->getCmd(), "summary"))
59  {
60  $this->__setSubTabs(self::LP_ACTIVE_SUMMARY);
61  }
62  else
63  {
64  $this->__setSubTabs(self::LP_ACTIVE_OBJECTS);
65  }
66  $loo_gui = new ilLPListOfObjectsGUI($this->getMode(),$this->getRefId());
67  $this->__setCmdClass('illplistofobjectsgui');
68  $this->ctrl->forwardCommand($loo_gui);
69  break;
70 
71  case 'illplistofsettingsgui':
72  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
73  if($this->getRefId() &&
74  !ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId()))
75  {
76  return;
77  }
78 
79  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfSettingsGUI.php';
80 
81  $this->__setSubTabs(self::LP_ACTIVE_SETTINGS);
82  $los_gui = new ilLPListOfSettingsGUI($this->getMode(),$this->getRefId());
83  $this->__setCmdClass('illplistofsettingsgui');
84  $this->ctrl->forwardCommand($los_gui);
85  break;
86 
87  case 'illpobjectstatisticsgui':
88  include_once 'Services/Tracking/classes/object_statistics/class.ilLPObjectStatisticsGUI.php';
89  if(stristr($this->ctrl->getCmd(), "access"))
90  {
91  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATACCESS);
92  }
93  else if(stristr($this->ctrl->getCmd(), "types"))
94  {
95  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATTYPES);
96  }
97  else if(stristr($this->ctrl->getCmd(), "daily"))
98  {
99  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATDAILY);
100  }
101  else
102  {
103  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATADMIN);
104  }
105  $this->__setCmdClass('illpobjectstatisticsgui');
106  $ost_gui = new ilLPObjectStatisticsGUI($this->getMode(),$this->getRefId());
107  $this->ctrl->forwardCommand($ost_gui);
108  break;
109 
110  default:
111  $cmd = $this->ctrl->getCmd();
112  if(!$cmd)
113  {
114  return;
115  }
116  $this->tpl->show(true);
117  break;
118  }
119 
120  // E.G personal desktop mode needs $tpl->show();
121  $this->__buildFooter();
122 
123 
124  $ilBench->stop('LearningProgress','0000_Start');
125 
126  return true;
127  }
128 
129  function __setCmdClass($a_class)
130  {
131  // If cmd class == 'illearningprogressgui' the cmd class is set to the the new forwarded class
132  // otherwise e.g illplistofprogressgui tries to forward (back) to illearningprogressgui.
133 
134  if($this->ctrl->getCmdClass() == strtolower(get_class($this)))
135  {
136  $this->ctrl->setCmdClass(strtolower($a_class));
137  }
138  return true;
139  }
140 
141  function __getNextClass()
142  {
143  global $ilAccess, $ilUser;
144 
145  // #9857
147  {
148  return;
149  }
150 
151  if(strlen($next_class = $this->ctrl->getNextClass()))
152  {
153  if($this->getMode() == self::LP_CONTEXT_PERSONAL_DESKTOP)
154  {
155  $_SESSION['il_lp_history'] = $next_class;
156  }
157  return $next_class;
158  }
159  switch($this->getMode())
160  {
161  case self::LP_CONTEXT_ADMINISTRATION:
162  return 'illplistofobjectsgui';
163 
164  case self::LP_CONTEXT_REPOSITORY:
165  $cmd = $this->ctrl->getCmd();
166  if(in_array($cmd, array("editmanual", "updatemanual", "showtlt")))
167  {
168  return "";
169  }
170 
171  // #12771
172  include_once './Services/Object/classes/class.ilObjectLP.php';
174  if(!$olp->isActive())
175  {
176  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
177  if(!($olp instanceof ilPluginLP) &&
178  ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId()))
179  {
180  return 'illplistofsettingsgui';
181  }
182  else
183  {
184  return '';
185  }
186  }
187 
188  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
189  if(!$this->anonymized &&
190  ilLearningProgressAccess::checkPermission('read_learning_progress', $this->getRefId()))
191  {
192  return 'illplistofobjectsgui';
193  }
194  if(
195  ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId()))
196  {
197  return 'illplistofsettingsgui';
198  }
199  return 'illplistofprogressgui';
200 
201  case self::LP_CONTEXT_PERSONAL_DESKTOP:
202 
203  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
206 
207  if($has_edit || $has_personal)
208  {
209  // default (#10928)
210  $tgt = null;
211  if($has_personal)
212  {
213  $tgt = 'illplistofprogressgui';
214  }
215  else if($has_edit)
216  {
217  $tgt = 'illplistofobjectsgui';
218  }
219 
220  // validate session
221  switch($_SESSION['il_lp_history'])
222  {
223  case 'illplistofobjectsgui':
224  if(!$has_edit)
225  {
226  $_SESSION['il_lp_history'] = null;
227  }
228  break;
229 
230  case 'illplistofprogressgui':
231  if(!$has_personal)
232  {
233  $_SESSION['il_lp_history'] = null;
234  }
235  break;
236  }
237 
238  if($_SESSION['il_lp_history'])
239  {
240  return $_SESSION['il_lp_history'];
241  }
242  else if($tgt)
243  {
244  return $tgt;
245  }
246  }
247 
248  // should not happen
249  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI");
250 
251  case self::LP_CONTEXT_USER_FOLDER:
252  case self::LP_CONTEXT_ORG_UNIT:
254  {
255  return 'illplistofprogressgui';
256  }
257  break;
258  }
259  }
260 
261  protected function editManual()
262  {
263  global $tpl;
264 
265  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
267  {
268  include_once './Services/Object/classes/class.ilObjectLP.php';
270  if($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL)
271  {
272  $form = $this->initCollectionManualForm();
273  $tpl->setContent($form->getHTML());
274  }
275  }
276  }
277 
278  protected function initCollectionManualForm()
279  {
280  global $lng, $ilCtrl;
281 
282  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
283  $form = new ilPropertyFormGUI();
284  $form->setFormAction($ilCtrl->getFormAction($this, "updatemanual"));
285  $form->setTitle($lng->txt("learning_progress"));
286  $form->setDescription($lng->txt("trac_collection_manual_learner_info"));
287 
288  $coll_items = array();
289 
290  include_once './Services/Object/classes/class.ilObjectLP.php';
291  $olp = ilObjectLP::getInstance($this->getObjId());
292  $collection = $olp->getCollectionInstance();
293  if($collection)
294  {
295  $coll_items = $collection->getItems();
296  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
297 
298  switch(ilObject::_lookupType($this->getObjId()))
299  {
300  case "lm":
301  $subitem_title = $lng->txt("objs_st");
302  $subitem_info = $lng->txt("trac_collection_manual_learner_lm_info");
303  break;
304  }
305  }
306 
307  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
309  $lp_data = $class::_getObjectStatus($this->getObjId(), $this->usr_id);
310 
311  $grp = new ilCheckboxGroupInputGUI($subitem_title, "sids");
312  $grp->setInfo($subitem_info);
313  $form->addItem($grp);
314 
315  // #14994 - using possible items for proper sorting
316 
317  $completed = array();
318  foreach(array_keys($possible_items) as $item_id)
319  {
320  if(!in_array($item_id, $coll_items))
321  {
322  continue;
323  }
324 
325  $info = null;
327 
328  if(isset($lp_data[$item_id]))
329  {
330  $changed = new ilDateTime($lp_data[$item_id][1], IL_CAL_UNIX);
331  $info = $lng->txt("trac_collection_manual_learner_changed_ts").": ".
333 
334  if($lp_data[$item_id][0])
335  {
337  $completed[] = $item_id;
338  }
339  }
340 
343  $icon = ilUtil::img($path, $text);
344 
345  $opt = new ilCheckboxOption($icon." ".$possible_items[$item_id]["title"], $item_id);
346  if($info)
347  {
348  $opt->setInfo($info);
349  }
350  $grp->addOption($opt);
351  }
352 
353  if($completed)
354  {
355  $grp->setValue($completed);
356  }
357 
358  $form->addCommandButton("updatemanual", $lng->txt("save"));
359 
360  return $form;
361  }
362 
363  protected function updateManual()
364  {
365  global $ilCtrl, $lng;
366 
367  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
369  {
370  include_once './Services/Object/classes/class.ilObjectLP.php';
372  if($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL)
373  {
374  $form = $this->initCollectionManualForm();
375  if($form->checkInput())
376  {
377  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
379  $class::_setObjectStatus($this->getObjId(), $this->usr_id, $form->getInput("sids"));
380 
381  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
382  }
383 
384  $ilCtrl->redirect($this, "editmanual");
385  }
386  }
387  }
388 
389  protected function showtlt()
390  {
391  global $lng, $ilCtrl, $tpl, $ilUser;
392 
393  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
394  $form = new ilPropertyFormGUI();
395  $form->setFormAction($ilCtrl->getFormAction($this, "showtlt"));
396  $form->setTitle($lng->txt("learning_progress"));
397  $form->setDescription($lng->txt("trac_collection_tlt_learner_info"));
398 
399  $coll_items = array();
400 
401  include_once './Services/Object/classes/class.ilObjectLP.php';
402  $olp = ilObjectLP::getInstance($this->getObjId());
403  $collection = $olp->getCollectionInstance();
404  if($collection)
405  {
406  $coll_items = $collection->getItems();
407  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
408  }
409 
410  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
412  $info = $class::_getStatusInfo($this->getObjId(), true);
413 
414  foreach($coll_items as $item_id)
415  {
416  // #16599 - deleted items should not be displayed
417  if(!array_key_exists($item_id, $possible_items))
418  {
419  continue;
420  }
421 
422  $field = new ilCustomInputGUI($possible_items[$item_id]["title"]);
423 
424  // lp status
426  if(isset($info["completed"][$item_id]) &&
427  in_array($ilUser->getId(), $info["completed"][$item_id]))
428  {
430  }
431  else if(isset($info["in_progress"][$item_id]) &&
432  in_array($ilUser->getId(), $info["in_progress"][$item_id]))
433  {
435  }
438  $field->setHtml(ilUtil::img($path, $text));
439 
440  // stats
441  $spent = 0;
442  if(isset($info["tlt_users"][$item_id][$ilUser->getId()]))
443  {
444  $spent = $info["tlt_users"][$item_id][$ilUser->getId()];
445  }
446  $needed = $info["tlt"][$item_id];
447  if($needed)
448  {
449  $field->setInfo(sprintf($lng->txt("trac_collection_tlt_learner_subitem"),
452  min(100, round(abs($spent)/$needed*100))));
453  }
454 
455  $form->addItem($field);
456  }
457 
458  $tpl->setContent($form->getHTML());
459  }
460 }
461 ?>
const LP_STATUS_COMPLETED_NUM
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$path
Definition: aliased.php:25
This class represents an option in a checkbox group.
$_SESSION["AccountId"]
static _getImagePathForStatus($a_status)
Get image path for status.
This class represents a property form user interface.
static _getStatusText($a_status, $a_lng=null)
Get status alt text.
$cmd
Definition: sahs_server.php:35
const LP_STATUS_IN_PROGRESS_NUM
Class ilLPListOfSettingsGUI.
const IL_CAL_UNIX
static checkPermission($a_permission, $a_ref_id, $a_user_id=null)
wrapper for rbac access checks
static _getClassById($a_obj_id, $a_mode=NULL)
global $ilCtrl
Definition: ilias.php:18
static checkAccess($a_ref_id, $a_allow_only_read=true)
check access to learning progress
static _enabledUserRelatedData()
check wether user related tracking is enabled or not
$info
Definition: example_052.php:80
static _enabledLearningProgress()
check wether learing progress is enabled or not
static secondsToString($seconds, $force_with_seconds=false, $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
static _lookupObjId($a_id)
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
$ilUser
Definition: imgupload.php:18
This class represents a property in a property form.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
const LP_STATUS_NOT_ATTEMPTED_NUM
This class represents a custom property in a property form.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $ilBench
Definition: ilias.php:18
$text
static redirect($a_script)
http redirect to other script
static getInstance($a_obj_id)
Class ilObjUserTrackingGUI.