ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function executeCommand()
23  {
24  global $DIC;
25 
26  $ilHelp = $DIC['ilHelp'];
27  $ilAccess = $DIC['ilAccess'];
28 
29  $this->ctrl->setReturn($this, "");
30 
31  // E.g personal desktop mode needs locator header icon ...
32  $this->__buildHeader();
33  switch ($this->__getNextClass()) {
34  case 'illplistofprogressgui':
35  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfProgressGUI.php';
36 
37  $ilHelp->setScreenIdComponent("lp_" . ilObject::_lookupType($this->getRefId(), true));
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  return;
50  }
51 
52  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfObjectsGUI.php';
53  if (stristr($this->ctrl->getCmd(), "matrix")) {
54  $this->__setSubTabs(self::LP_ACTIVE_MATRIX);
55  } elseif (stristr($this->ctrl->getCmd(), "summary")) {
56  $this->__setSubTabs(self::LP_ACTIVE_SUMMARY);
57  } else {
58  $this->__setSubTabs(self::LP_ACTIVE_OBJECTS);
59  }
60  $loo_gui = new ilLPListOfObjectsGUI($this->getMode(), $this->getRefId());
61  $this->__setCmdClass('illplistofobjectsgui');
62  $this->ctrl->forwardCommand($loo_gui);
63  break;
64 
65  case 'illplistofsettingsgui':
66  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
67  if ($this->getRefId() &&
68  !ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId())) {
69  return;
70  }
71 
72  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfSettingsGUI.php';
73 
74  $this->__setSubTabs(self::LP_ACTIVE_SETTINGS);
75  $los_gui = new ilLPListOfSettingsGUI($this->getMode(), $this->getRefId());
76  $this->__setCmdClass('illplistofsettingsgui');
77  $this->ctrl->forwardCommand($los_gui);
78  break;
79 
80  case 'illpobjectstatisticsgui':
81  include_once 'Services/Tracking/classes/object_statistics/class.ilLPObjectStatisticsGUI.php';
82  if (stristr($this->ctrl->getCmd(), "access")) {
83  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATACCESS);
84  } elseif (stristr($this->ctrl->getCmd(), "types")) {
85  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATTYPES);
86  } elseif (stristr($this->ctrl->getCmd(), "daily")) {
87  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATDAILY);
88  } else {
89  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATADMIN);
90  }
91  $this->__setCmdClass('illpobjectstatisticsgui');
92  $ost_gui = new ilLPObjectStatisticsGUI($this->getMode(), $this->getRefId());
93  $this->ctrl->forwardCommand($ost_gui);
94  break;
95 
96  default:
97  $cmd = $this->ctrl->getCmd();
98  if (!$cmd) {
99  return;
100  }
101  $this->$cmd();
102  $this->tpl->show(true);
103  break;
104  }
105 
106  // E.G personal desktop mode needs $tpl->show();
107  $this->__buildFooter();
108 
109 
110  return true;
111  }
112 
113  public function __setCmdClass($a_class)
114  {
115  // If cmd class == 'illearningprogressgui' the cmd class is set to the the new forwarded class
116  // otherwise e.g illplistofprogressgui tries to forward (back) to illearningprogressgui.
117 
118  if ($this->ctrl->getCmdClass() == strtolower(get_class($this))) {
119  $this->ctrl->setCmdClass(strtolower($a_class));
120  }
121  return true;
122  }
123 
124  public function __getNextClass()
125  {
126  global $DIC;
127 
128  $ilAccess = $DIC['ilAccess'];
129  $ilUser = $DIC['ilUser'];
130 
131  // #9857
133  return;
134  }
135 
136  if (strlen($next_class = $this->ctrl->getNextClass())) {
137  if ($this->getMode() == self::LP_CONTEXT_PERSONAL_DESKTOP) {
138  $_SESSION['il_lp_history'] = $next_class;
139  }
140  return $next_class;
141  }
142  switch ($this->getMode()) {
143  case self::LP_CONTEXT_ADMINISTRATION:
144  return 'illplistofobjectsgui';
145 
146  case self::LP_CONTEXT_REPOSITORY:
147  $cmd = $this->ctrl->getCmd();
148  if (in_array($cmd, array("editManual", "updatemanual", "showtlt"))) {
149  return "";
150  }
151 
152  // #12771
153  include_once './Services/Object/classes/class.ilObjectLP.php';
155  if (!$olp->isActive()) {
156  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
157  if (!($olp instanceof ilPluginLP) &&
158  ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId())) {
159  return 'illplistofsettingsgui';
160  } else {
161  return '';
162  }
163  }
164 
165  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
166  if (!$this->anonymized &&
167  ilLearningProgressAccess::checkPermission('read_learning_progress', $this->getRefId())) {
168  return 'illplistofobjectsgui';
169  }
170  if (
171  ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId())) {
172  return 'illplistofsettingsgui';
173  }
174  return 'illplistofprogressgui';
175 
176  case self::LP_CONTEXT_PERSONAL_DESKTOP:
177 
178  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
181 
182  if ($has_edit || $has_personal) {
183  // default (#10928)
184  $tgt = null;
185  if ($has_personal) {
186  $tgt = 'illplistofprogressgui';
187  } elseif ($has_edit) {
188  $tgt = 'illplistofobjectsgui';
189  }
190 
191  // validate session
192  switch ($_SESSION['il_lp_history']) {
193  case 'illplistofobjectsgui':
194  if (!$has_edit) {
195  $_SESSION['il_lp_history'] = null;
196  }
197  break;
198 
199  case 'illplistofprogressgui':
200  if (!$has_personal) {
201  $_SESSION['il_lp_history'] = null;
202  }
203  break;
204  }
205 
206  if ($_SESSION['il_lp_history']) {
207  return $_SESSION['il_lp_history'];
208  } elseif ($tgt) {
209  return $tgt;
210  }
211  }
212 
213  // should not happen
214  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI");
215 
216  // no break
217  case self::LP_CONTEXT_USER_FOLDER:
218  case self::LP_CONTEXT_ORG_UNIT:
220  return 'illplistofprogressgui';
221  }
222  break;
223  }
224  }
225 
230  protected function editManual()
231  {
232  global $DIC;
233 
234  $tpl = $DIC['tpl'];
235 
238  if ($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL) {
239  $form = $this->initCollectionManualForm();
240  $tpl->setContent($form->getHTML());
241  }
242  }
243  }
244 
245  protected function initCollectionManualForm()
246  {
247  global $DIC;
248 
249  $lng = $DIC['lng'];
250  $ilCtrl = $DIC['ilCtrl'];
251 
252  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
253  $form = new ilPropertyFormGUI();
254  $form->setFormAction($ilCtrl->getFormAction($this, "updatemanual"));
255  $form->setTitle($lng->txt("learning_progress"));
256  $form->setDescription($lng->txt("trac_collection_manual_learner_info"));
257 
258  $coll_items = array();
259 
260  include_once './Services/Object/classes/class.ilObjectLP.php';
261  $olp = ilObjectLP::getInstance($this->getObjId());
262  $collection = $olp->getCollectionInstance();
263  if ($collection) {
264  $coll_items = $collection->getItems();
265  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
266 
267  switch (ilObject::_lookupType($this->getObjId())) {
268  case "lm":
269  $subitem_title = $lng->txt("objs_st");
270  $subitem_info = $lng->txt("trac_collection_manual_learner_lm_info");
271  break;
272  }
273  }
274 
275  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
277  $lp_data = $class::_getObjectStatus($this->getObjId(), $this->usr_id);
278 
279  $grp = new ilCheckboxGroupInputGUI($subitem_title, "sids");
280  $grp->setInfo($subitem_info);
281  $form->addItem($grp);
282 
283  // #14994 - using possible items for proper sorting
284 
285  $completed = array();
286  foreach (array_keys($possible_items) as $item_id) {
287  if (!in_array($item_id, $coll_items)) {
288  continue;
289  }
290 
291  $info = null;
293 
294  if (isset($lp_data[$item_id])) {
295  $changed = new ilDateTime($lp_data[$item_id][1], IL_CAL_UNIX);
296  $info = $lng->txt("trac_collection_manual_learner_changed_ts") . ": " .
298 
299  if ($lp_data[$item_id][0]) {
301  $completed[] = $item_id;
302  }
303  }
304 
307  $icon = ilUtil::img($path, $text);
308 
309  $opt = new ilCheckboxOption($icon . " " . $possible_items[$item_id]["title"], $item_id);
310  if ($info) {
311  $opt->setInfo($info);
312  }
313  $grp->addOption($opt);
314  }
315 
316  if ($completed) {
317  $grp->setValue($completed);
318  }
319 
320  $form->addCommandButton("updatemanual", $lng->txt("save"));
321 
322  return $form;
323  }
324 
325  protected function updateManual()
326  {
327  global $DIC;
328 
329  $ilCtrl = $DIC['ilCtrl'];
330  $lng = $DIC['lng'];
331 
332  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
334  include_once './Services/Object/classes/class.ilObjectLP.php';
336  if ($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL) {
337  $form = $this->initCollectionManualForm();
338  if ($form->checkInput()) {
339  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
341  $class::_setObjectStatus($this->getObjId(), $this->usr_id, $form->getInput("sids"));
342 
343  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
344  }
345 
346  $ilCtrl->redirect($this, "editManual");
347  }
348  }
349  }
350 
351  protected function showtlt()
352  {
353  global $DIC;
354 
355  $lng = $DIC['lng'];
356  $ilCtrl = $DIC['ilCtrl'];
357  $tpl = $DIC['tpl'];
358  $ilUser = $DIC['ilUser'];
359 
360  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
361  $form = new ilPropertyFormGUI();
362  $form->setFormAction($ilCtrl->getFormAction($this, "showtlt"));
363  $form->setTitle($lng->txt("learning_progress"));
364  $form->setDescription($lng->txt("trac_collection_tlt_learner_info"));
365 
366  $coll_items = array();
367 
368  include_once './Services/Object/classes/class.ilObjectLP.php';
369  $olp = ilObjectLP::getInstance($this->getObjId());
370  $collection = $olp->getCollectionInstance();
371  if ($collection) {
372  $coll_items = $collection->getItems();
373  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
374  }
375 
376  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
378  $info = $class::_getStatusInfo($this->getObjId(), true);
379 
380  foreach ($coll_items as $item_id) {
381  // #16599 - deleted items should not be displayed
382  if (!array_key_exists($item_id, $possible_items)) {
383  continue;
384  }
385 
386  $field = new ilCustomInputGUI($possible_items[$item_id]["title"]);
387 
388  // lp status
390  if (isset($info["completed"][$item_id]) &&
391  in_array($ilUser->getId(), $info["completed"][$item_id])) {
393  } elseif (isset($info["in_progress"][$item_id]) &&
394  in_array($ilUser->getId(), $info["in_progress"][$item_id])) {
396  }
399  $field->setHtml(ilUtil::img($path, $text));
400 
401  // stats
402  $spent = 0;
403  if (isset($info["tlt_users"][$item_id][$ilUser->getId()])) {
404  $spent = $info["tlt_users"][$item_id][$ilUser->getId()];
405  }
406  $needed = $info["tlt"][$item_id];
407  if ($needed) {
408  $field->setInfo(sprintf(
409  $lng->txt("trac_collection_tlt_learner_subitem"),
412  min(100, round(abs($spent) / $needed * 100))
413  ));
414  }
415 
416  $form->addItem($field);
417  }
418 
419  $tpl->setContent($form->getHTML());
420  }
421 }
const LP_STATUS_COMPLETED_NUM
$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.
global $DIC
Definition: saml.php:7
static _getStatusText($a_status, $a_lng=null)
Get status alt text.
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 formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
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
static _enabledLearningProgress()
check wether learing progress is enabled or not
editManual()
Show progress screen for "edit manual" type $tpl.
static secondsToString($seconds, $force_with_seconds=false, $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
if(isset($_POST['submit'])) $form
static _lookupObjId($a_id)
$text
Definition: errorreport.php:18
Date and time handling
$ilUser
Definition: imgupload.php:18
This class represents a property in a property form.
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
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.
$info
Definition: index.php:5
static redirect($a_script)
static getInstance($a_obj_id)
Class ilObjUserTrackingGUI.