ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $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  case 'illplistofprogressgui':
34  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfProgressGUI.php';
35 
36  $ilHelp->setScreenIdComponent("lp_" . ilObject::_lookupType($this->getRefId(), true));
37 
38  $this->__setSubTabs(self::LP_ACTIVE_PROGRESS);
39  $this->__setCmdClass('illplistofprogressgui');
40  $lop_gui = new ilLPListOfProgressGUI($this->getMode(), $this->getRefId(), $this->getUserId());
41  $this->ctrl->forwardCommand($lop_gui);
42  break;
43 
44  case 'illplistofobjectsgui':
45  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
46  if ($this->getRefId() &&
47  !ilLearningProgressAccess::checkPermission('read_learning_progress', $this->getRefId())) {
48  return;
49  }
50 
51  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfObjectsGUI.php';
52  if (stristr($this->ctrl->getCmd(), "matrix")) {
53  $this->__setSubTabs(self::LP_ACTIVE_MATRIX);
54  } elseif (stristr($this->ctrl->getCmd(), "summary")) {
55  $this->__setSubTabs(self::LP_ACTIVE_SUMMARY);
56  } else {
57  $this->__setSubTabs(self::LP_ACTIVE_OBJECTS);
58  }
59  $loo_gui = new ilLPListOfObjectsGUI($this->getMode(), $this->getRefId());
60  $this->__setCmdClass('illplistofobjectsgui');
61  $this->ctrl->forwardCommand($loo_gui);
62  break;
63 
64  case 'illplistofsettingsgui':
65  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
66  if ($this->getRefId() &&
67  !ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId())) {
68  return;
69  }
70 
71  include_once 'Services/Tracking/classes/repository_statistics/class.ilLPListOfSettingsGUI.php';
72 
73  $this->__setSubTabs(self::LP_ACTIVE_SETTINGS);
74  $los_gui = new ilLPListOfSettingsGUI($this->getMode(), $this->getRefId());
75  $this->__setCmdClass('illplistofsettingsgui');
76  $this->ctrl->forwardCommand($los_gui);
77  break;
78 
79  case 'illpobjectstatisticsgui':
80  include_once 'Services/Tracking/classes/object_statistics/class.ilLPObjectStatisticsGUI.php';
81  if (stristr($this->ctrl->getCmd(), "access")) {
82  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATACCESS);
83  } elseif (stristr($this->ctrl->getCmd(), "types")) {
84  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATTYPES);
85  } elseif (stristr($this->ctrl->getCmd(), "daily")) {
86  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATDAILY);
87  } else {
88  $this->__setSubTabs(self::LP_ACTIVE_OBJSTATADMIN);
89  }
90  $this->__setCmdClass('illpobjectstatisticsgui');
91  $ost_gui = new ilLPObjectStatisticsGUI($this->getMode(), $this->getRefId());
92  $this->ctrl->forwardCommand($ost_gui);
93  break;
94 
95  default:
96  $cmd = $this->ctrl->getCmd();
97  if (!$cmd) {
98  return;
99  }
100  $this->$cmd();
101  $this->tpl->show(true);
102  break;
103  }
104 
105  // E.G personal desktop mode needs $tpl->show();
106  $this->__buildFooter();
107 
108 
109  $ilBench->stop('LearningProgress', '0000_Start');
110 
111  return true;
112  }
113 
114  public function __setCmdClass($a_class)
115  {
116  // If cmd class == 'illearningprogressgui' the cmd class is set to the the new forwarded class
117  // otherwise e.g illplistofprogressgui tries to forward (back) to illearningprogressgui.
118 
119  if ($this->ctrl->getCmdClass() == strtolower(get_class($this))) {
120  $this->ctrl->setCmdClass(strtolower($a_class));
121  }
122  return true;
123  }
124 
125  public function __getNextClass()
126  {
127  global $ilAccess, $ilUser;
128 
129  // #9857
131  return;
132  }
133 
134  if (strlen($next_class = $this->ctrl->getNextClass())) {
135  if ($this->getMode() == self::LP_CONTEXT_PERSONAL_DESKTOP) {
136  $_SESSION['il_lp_history'] = $next_class;
137  }
138  return $next_class;
139  }
140  switch ($this->getMode()) {
141  case self::LP_CONTEXT_ADMINISTRATION:
142  return 'illplistofobjectsgui';
143 
144  case self::LP_CONTEXT_REPOSITORY:
145  $cmd = $this->ctrl->getCmd();
146  if (in_array($cmd, array("editManual", "updatemanual", "showtlt"))) {
147  return "";
148  }
149 
150  // #12771
151  include_once './Services/Object/classes/class.ilObjectLP.php';
153  if (!$olp->isActive()) {
154  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
155  if (!($olp instanceof ilPluginLP) &&
156  ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId())) {
157  return 'illplistofsettingsgui';
158  } else {
159  return '';
160  }
161  }
162 
163  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
164  if (!$this->anonymized &&
165  ilLearningProgressAccess::checkPermission('read_learning_progress', $this->getRefId())) {
166  return 'illplistofobjectsgui';
167  }
168  if (
169  ilLearningProgressAccess::checkPermission('edit_learning_progress', $this->getRefId())) {
170  return 'illplistofsettingsgui';
171  }
172  return 'illplistofprogressgui';
173 
174  case self::LP_CONTEXT_PERSONAL_DESKTOP:
175 
176  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
179 
180  if ($has_edit || $has_personal) {
181  // default (#10928)
182  $tgt = null;
183  if ($has_personal) {
184  $tgt = 'illplistofprogressgui';
185  } elseif ($has_edit) {
186  $tgt = 'illplistofobjectsgui';
187  }
188 
189  // validate session
190  switch ($_SESSION['il_lp_history']) {
191  case 'illplistofobjectsgui':
192  if (!$has_edit) {
193  $_SESSION['il_lp_history'] = null;
194  }
195  break;
196 
197  case 'illplistofprogressgui':
198  if (!$has_personal) {
199  $_SESSION['il_lp_history'] = null;
200  }
201  break;
202  }
203 
204  if ($_SESSION['il_lp_history']) {
205  return $_SESSION['il_lp_history'];
206  } elseif ($tgt) {
207  return $tgt;
208  }
209  }
210 
211  // should not happen
212  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI");
213 
214  // no break
215  case self::LP_CONTEXT_USER_FOLDER:
216  case self::LP_CONTEXT_ORG_UNIT:
218  return 'illplistofprogressgui';
219  }
220  break;
221  }
222  }
223 
228  protected function editManual()
229  {
230  global $tpl;
231 
234  if ($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL) {
235  $form = $this->initCollectionManualForm();
236  $tpl->setContent($form->getHTML());
237  }
238  }
239  }
240 
241  protected function initCollectionManualForm()
242  {
243  global $lng, $ilCtrl;
244 
245  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
246  $form = new ilPropertyFormGUI();
247  $form->setFormAction($ilCtrl->getFormAction($this, "updatemanual"));
248  $form->setTitle($lng->txt("learning_progress"));
249  $form->setDescription($lng->txt("trac_collection_manual_learner_info"));
250 
251  $coll_items = array();
252 
253  include_once './Services/Object/classes/class.ilObjectLP.php';
254  $olp = ilObjectLP::getInstance($this->getObjId());
255  $collection = $olp->getCollectionInstance();
256  if ($collection) {
257  $coll_items = $collection->getItems();
258  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
259 
260  switch (ilObject::_lookupType($this->getObjId())) {
261  case "lm":
262  $subitem_title = $lng->txt("objs_st");
263  $subitem_info = $lng->txt("trac_collection_manual_learner_lm_info");
264  break;
265  }
266  }
267 
268  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
270  $lp_data = $class::_getObjectStatus($this->getObjId(), $this->usr_id);
271 
272  $grp = new ilCheckboxGroupInputGUI($subitem_title, "sids");
273  $grp->setInfo($subitem_info);
274  $form->addItem($grp);
275 
276  // #14994 - using possible items for proper sorting
277 
278  $completed = array();
279  foreach (array_keys($possible_items) as $item_id) {
280  if (!in_array($item_id, $coll_items)) {
281  continue;
282  }
283 
284  $info = null;
286 
287  if (isset($lp_data[$item_id])) {
288  $changed = new ilDateTime($lp_data[$item_id][1], IL_CAL_UNIX);
289  $info = $lng->txt("trac_collection_manual_learner_changed_ts") . ": " .
291 
292  if ($lp_data[$item_id][0]) {
294  $completed[] = $item_id;
295  }
296  }
297 
300  $icon = ilUtil::img($path, $text);
301 
302  $opt = new ilCheckboxOption($icon . " " . $possible_items[$item_id]["title"], $item_id);
303  if ($info) {
304  $opt->setInfo($info);
305  }
306  $grp->addOption($opt);
307  }
308 
309  if ($completed) {
310  $grp->setValue($completed);
311  }
312 
313  $form->addCommandButton("updatemanual", $lng->txt("save"));
314 
315  return $form;
316  }
317 
318  protected function updateManual()
319  {
320  global $ilCtrl, $lng;
321 
322  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
324  include_once './Services/Object/classes/class.ilObjectLP.php';
326  if ($olp->getCurrentMode() == ilLPObjSettings::LP_MODE_COLLECTION_MANUAL) {
327  $form = $this->initCollectionManualForm();
328  if ($form->checkInput()) {
329  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
331  $class::_setObjectStatus($this->getObjId(), $this->usr_id, $form->getInput("sids"));
332 
333  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
334  }
335 
336  $ilCtrl->redirect($this, "editManual");
337  }
338  }
339  }
340 
341  protected function showtlt()
342  {
343  global $lng, $ilCtrl, $tpl, $ilUser;
344 
345  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
346  $form = new ilPropertyFormGUI();
347  $form->setFormAction($ilCtrl->getFormAction($this, "showtlt"));
348  $form->setTitle($lng->txt("learning_progress"));
349  $form->setDescription($lng->txt("trac_collection_tlt_learner_info"));
350 
351  $coll_items = array();
352 
353  include_once './Services/Object/classes/class.ilObjectLP.php';
354  $olp = ilObjectLP::getInstance($this->getObjId());
355  $collection = $olp->getCollectionInstance();
356  if ($collection) {
357  $coll_items = $collection->getItems();
358  $possible_items = $collection->getPossibleItems($this->getRefId()); // for titles
359  }
360 
361  include_once "Services/Tracking/classes/class.ilLPStatusFactory.php";
363  $info = $class::_getStatusInfo($this->getObjId(), true);
364 
365  foreach ($coll_items as $item_id) {
366  // #16599 - deleted items should not be displayed
367  if (!array_key_exists($item_id, $possible_items)) {
368  continue;
369  }
370 
371  $field = new ilCustomInputGUI($possible_items[$item_id]["title"]);
372 
373  // lp status
375  if (isset($info["completed"][$item_id]) &&
376  in_array($ilUser->getId(), $info["completed"][$item_id])) {
378  } elseif (isset($info["in_progress"][$item_id]) &&
379  in_array($ilUser->getId(), $info["in_progress"][$item_id])) {
381  }
384  $field->setHtml(ilUtil::img($path, $text));
385 
386  // stats
387  $spent = 0;
388  if (isset($info["tlt_users"][$item_id][$ilUser->getId()])) {
389  $spent = $info["tlt_users"][$item_id][$ilUser->getId()];
390  }
391  $needed = $info["tlt"][$item_id];
392  if ($needed) {
393  $field->setInfo(sprintf(
394  $lng->txt("trac_collection_tlt_learner_subitem"),
397  min(100, round(abs($spent)/$needed*100))
398  ));
399  }
400 
401  $form->addItem($field);
402  }
403 
404  $tpl->setContent($form->getHTML());
405  }
406 }
const LP_STATUS_COMPLETED_NUM
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
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
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.
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
$info
Definition: index.php:5
static redirect($a_script)
static getInstance($a_obj_id)
Class ilObjUserTrackingGUI.