ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLearningProgressBaseGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 define("LP_MODE_PERSONAL_DESKTOP",1);
36 define("LP_MODE_ADMINISTRATION",2);
37 define("LP_MODE_REPOSITORY",3);
38 define("LP_MODE_USER_FOLDER",4);
39 
40 define("LP_ACTIVE_SETTINGS",1);
41 define("LP_ACTIVE_OBJECTS",2);
42 define("LP_ACTIVE_PROGRESS",3);
43 define("LP_ACTIVE_LM_STATISTICS",4);
44 
45 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
46 
47 /* Base class for all Learning progress gui classes.
48  * Defines modes for presentation according to the context in which it was called
49  * E.g: mode LP_MODE_PERSONAL_DESKTOP displays only listOfObjects.
50  */
51 
53 {
54  var $tpl = null;
55  var $ctrl = null;
56  var $lng = null;
57 
58  var $ref_id = 0;
59 
60  var $mode = 0;
61 
62  var $statistics_activated = false; // show sub tab for access statistics
63 
64  function ilLearningProgressBaseGUI($a_mode,$a_ref_id = 0,$a_usr_id = 0)
65  {
66  global $tpl,$ilCtrl,$lng,$ilObjDataCache,$ilTabs;
67 
68  $this->tpl =& $tpl;
69  $this->ctrl =& $ilCtrl;
70  $this->lng =& $lng;
71  $this->lng->loadLanguageModule('trac');
72  $this->tabs_gui =& $ilTabs;
73 
74  $this->mode = $a_mode;
75  $this->ref_id = $a_ref_id;
76  $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
77  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
78  $this->usr_id = $a_usr_id;
79 
80  $this->anonymized = (bool) !ilObjUserTracking::_enabledUserRelatedData();
81  }
82 
83  function activePDF()
84  {
85  return $this->active_pdf;
86  }
87 
88  function __checkPDF()
89  {
90  include_once 'Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
91  $rpc_server = new ilRPCServerSettings();
92  $this->active_pdf = $rpc_server->getHost() ? true : false;
93  }
94 
95  function isAnonymized()
96  {
97  return $this->anonymized;
98  }
99 
101  {
102  switch($this->obj_type)
103  {
104  case 'tst':
105  include_once './Modules/Test/classes/class.ilObjTest.php';
106  if(ilObjTest::_lookupAnonymity($this->obj_id))
107  {
108  return true;
109  }
110  default:
111  return false;
112  }
113  return false;
114  }
115 
116  function getMode()
117  {
118  return $this->mode;
119  }
120 
121  function getRefId()
122  {
123  return $this->ref_id;
124  }
125 
126  function getObjId()
127  {
128  return $this->obj_id;
129  }
130 
131  function getUserId()
132  {
133  if($this->usr_id)
134  {
135  return $this->usr_id;
136  }
137  if((int) $_GET['user_id'])
138  {
139  return (int) $_GET['user_id'];
140  }
141  return 0;
142  }
143 
144  function activateStatistics($a_act = true)
145  {
146  $this->statistics_activated = $a_act;
147  }
148 
149  // Protected
151  {
152  if(strlen($cmd = $this->ctrl->getCmd()))
153  {
154  return $cmd;
155  }
156  return 'show';
157  }
158 
159  function __setSubTabs($a_active)
160  {
161  global $rbacsystem,$ilObjDataCache;
162 
163 
164 
165  switch($this->getMode())
166  {
168 
169  $this->tabs_gui->addSubTabTarget('trac_progress',
170  $this->ctrl->getLinkTargetByClass('illplistofprogressgui',''),
171  "","","",$a_active == LP_ACTIVE_PROGRESS);
172  $this->tabs_gui->addSubTabTarget('trac_objects',
173  $this->ctrl->getLinkTargetByClass("illplistofobjectsgui",''),
174  "","","",$a_active == LP_ACTIVE_OBJECTS);
175  break;
176 
177 
178  case LP_MODE_REPOSITORY:
179 
180  if($rbacsystem->checkAccess('edit_learning_progress',$this->getRefId()))
181  {
182  if($this->isAnonymized())
183  {
184  $this->ctrl->setParameterByClass('illplistofprogressgui','user_id',$this->getUserId());
185  $this->tabs_gui->addSubTabTarget('trac_progress',
186  $this->ctrl->getLinkTargetByClass('illplistofprogressgui',''),
187  "","","",$a_active == LP_ACTIVE_PROGRESS);
188  }
189  if(!$this->isAnonymized())
190  {
191  // Check if it is a course
192  $sub_tab = ($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->getRefId())) == 'crs') ?
193  'trac_crs_objects' :
194  'trac_objects';
195 
196  $this->tabs_gui->addSubTabTarget($sub_tab,
197  $this->ctrl->getLinkTargetByClass("illplistofobjectsgui",''),
198  "","","",$a_active == LP_ACTIVE_OBJECTS);
199  }
200 
201  if ($this->statistics_activated)
202  {
203  $this->tabs_gui->addSubTabTarget('trac_lm_statistics',
204  $this->ctrl->getLinkTargetByClass('illmstatisticsgui',''),
205  "","","",$a_active == LP_ACTIVE_LM_STATISTICS);
206  }
207 
208  $this->tabs_gui->addSubTabTarget('trac_settings',
209  $this->ctrl->getLinkTargetByClass('illplistofsettingsgui',''),
210  "","","",$a_active == LP_ACTIVE_SETTINGS);
211 
212  }
213  break;
214 
216 
217  $this->tabs_gui->addSubTabTarget('trac_progress',
218  $this->ctrl->getLinkTargetByClass('illplistofprogressgui',''),
219  "","","",$a_active == LP_ACTIVE_PROGRESS);
220  $this->tabs_gui->addSubTabTarget('trac_objects',
221  $this->ctrl->getLinkTargetByClass("illplistofobjectsgui",''),
222  "","","",$a_active == LP_ACTIVE_OBJECTS);
223  break;
224 
225  case LP_MODE_USER_FOLDER:
226 
227  // No tabs default class is lpprogressgui
228  break;
229 
230  default:
231  die ('No valid mode given');
232  break;
233  }
234 
235  return true;
236  }
237 
238  function __buildFooter()
239  {
240  switch($this->getMode())
241  {
243 
244  $this->tpl->show(true);
245  }
246  }
247 
248  function __buildHeader()
249  {
250  if($this->getMode() == LP_MODE_PERSONAL_DESKTOP)
251  {
252  $this->tpl->setCurrentBlock("header_image");
253  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_pd_b.gif"));
254  $this->tpl->parseCurrentBlock();
255  $this->tpl->setVariable("HEADER",$this->lng->txt("personal_desktop"));
256 
257  // set locator
258 /*
259  $this->tpl->setVariable("TXT_LOCATOR", $this->lng->txt("locator"));
260  $this->tpl->touchBlock("locator_separator");
261  $this->tpl->touchBlock("locator_item");
262  //$this->tpl->setCurrentBlock("locator_item");
263  //$this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
264  //$this->tpl->setVariable("LINK_ITEM",
265  // $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
266  //$this->tpl->parseCurrentBlock();
267 
268  $this->tpl->setCurrentBlock("locator_item");
269  $this->tpl->setVariable("ITEM", $this->lng->txt("learning_progress"));
270  $this->tpl->setVariable("LINK_ITEM",
271  $this->ctrl->getLinkTargetByClass('illearningprogressgui'));
272  $this->tpl->parseCurrentBlock();
273 */
274 
275  // catch feedback message
277  // display infopanel if something happened
279  }
280 
281  }
282 
286  function __insertPath(&$a_tpl,$a_ref_id)
287  {
288  global $tree;
289 
290  $path_arr = $tree->getPathFull($a_ref_id);
291  $counter = 0;
292  foreach($tree->getPathFull($a_ref_id) as $data)
293  {
294  if($counter++)
295  {
296  $path .= " -> ";
297  }
298  $path .= $data['title'];
299  }
300  $a_tpl->setCurrentBlock("path_item");
301  $a_tpl->setVariable("PATH_ITEM",$path);
302  $a_tpl->parseCurrentBlock();
303 
304  $a_tpl->setCurrentBlock("path");
305  $a_tpl->parseCurrentBlock();
306 
307  return $path;
308  }
309 
310  function __showImageByStatus(&$tpl,$a_status,$tpl_prefix = "")
311  {
312  switch($a_status)
313  {
316  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/incomplete.gif'));
317  $tpl->setVariable($tpl_prefix."STATUS_ALT",$this->lng->txt($a_status));
318  break;
319 
320  case LP_STATUS_COMPLETED:
322  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/complete.gif'));
323  $tpl->setVariable($tpl_prefix."STATUS_ALT",$this->lng->txt($a_status));
324  break;
325 
329  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/not_attempted.gif'));
330  $tpl->setVariable($tpl_prefix."STATUS_ALT",$this->lng->txt($a_status));
331  break;
332 
333  case LP_STATUS_FAILED:
334  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/failed.gif'));
335  $tpl->setVariable($tpl_prefix."STATUS_ALT",$this->lng->txt($a_status));
336  break;
337  }
338  return true;
339  }
340 
341 
342  // Protected Table gui methods
343  function &__initTableGUI()
344  {
345  include_once "./Services/Table/classes/class.ilTableGUI.php";
346 
347  return new ilTableGUI(0,false);
348  }
349 
350 
354  function __showObjectDetails(&$info,$item_id = 0)
355  {
356  global $ilObjDataCache;
357 
358  $details_id = $item_id ? $item_id : $this->details_id;
359 
360 
361  // Section object details
362  $info->addSection($this->lng->txt('details'));
363  $info->addProperty($this->lng->txt('title'),$ilObjDataCache->lookupTitle($details_id));
364  if(strlen($desc = $ilObjDataCache->lookupDescription($details_id)))
365  {
366  $info->addProperty($this->lng->txt('description'),$desc);
367  }
368  $info->addProperty($this->lng->txt('trac_mode'),ilLPObjSettings::_mode2Text(ilLPObjSettings::_lookupMode($details_id)));
369 
370  if(ilLPObjSettings::_lookupMode($details_id) == LP_MODE_VISITS)
371  {
372  $info->addProperty($this->lng->txt('trac_required_visits'),ilLPObjSettings::_lookupVisits($details_id));
373  }
374 
375  include_once './Services/MetaData/classes/class.ilMDEducational.php';
376  if($seconds = ilMDEducational::_getTypicalLearningTimeSeconds($details_id))
377  {
378  $info->addProperty($this->lng->txt('meta_typical_learning_time'),ilFormat::_secondsToString($seconds));
379  }
380  }
381 
382  function __appendLPDetails(&$info,$item_id,$user_id)
383  {
384  global $ilObjDataCache;
385 
386  $type = $ilObjDataCache->lookupType($item_id);
387 
388  // Section learning_progress
389  $info->addSection($this->lng->txt('trac_learning_progress'));
390 
391  switch($type)
392  {
393  case 'lm':
394  case 'htlm':
395  include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
396  $progress = ilLearningProgress::_getProgress($user_id,$item_id);
397 
398  if($progress['access_time'])
399  {
400  $info->addProperty($this->lng->txt('last_access'),
401  ilDatePresentation::formatDate(new ilDateTime($progress['access_time'],IL_CAL_DATETIME)));
402  }
403  else
404  {
405  $info->addProperty($this->lng->txt('last_access'),$this->lng->txt('trac_not_accessed'));
406  }
407  $info->addProperty($this->lng->txt('trac_visits'),(int) $progress['visits']);
408  if($type == 'lm')
409  {
410  $info->addProperty($this->lng->txt('trac_spent_time'),ilFormat::_secondsToString($progress['spent_seconds']));
411  }
412  $info->addProperty($this->lng->txt('trac_status'),$this->lng->txt($this->__readStatus($item_id,$user_id)));
413  break;
414 
415  case 'exc':
416  case 'tst':
417  case 'crs':
418  case 'sahs':
419  case 'grp':
420  $info->addProperty($this->lng->txt('trac_status'),$this->lng->txt($this->__readStatus($item_id,$user_id)));
421  break;
422 
423  }
424 
425  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
426  if(strlen($mark = ilLPMarks::_lookupMark($user_id,$item_id)))
427  {
428  $info->addProperty($this->lng->txt('trac_mark'),$mark);
429  }
430  if(strlen($comment = ilLPMarks::_lookupComment($user_id,$item_id)))
431  {
432  $info->addProperty($this->lng->txt('trac_comment'),$comment);
433  }
434  }
435 
436  function __readStatus($a_obj_id,$user_id)
437  {
438  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
439 
440  if(in_array($user_id,ilLPStatusWrapper::_getInProgress($a_obj_id)))
441  {
442  return $status = LP_STATUS_IN_PROGRESS;
443  }
444  elseif(in_array($user_id,ilLPStatusWrapper::_getCompleted($a_obj_id)))
445  {
446  return $status = LP_STATUS_COMPLETED;
447  }
448  elseif(in_array($user_id,ilLPStatusWrapper::_getFailed($a_obj_id)))
449  {
450  return $status = LP_STATUS_FAILED;
451  }
452  else
453  {
454  return $status = LP_STATUS_NOT_ATTEMPTED;
455  }
456  }
457 
458 
459  function __showButton($a_link,$a_text,$a_target = '')
460  {
461  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
462 
463  // display button
464  $this->tpl->setCurrentBlock("btn_cell");
465  $this->tpl->setVariable("BTN_LINK",$a_link);
466  $this->tpl->setVariable("BTN_TXT",$a_text);
467  if($a_target)
468  {
469  $this->tpl->setVariable("BTN_TARGET",$a_target);
470  }
471 
472  $this->tpl->parseCurrentBlock();
473  }
474 
475 
488  function __sort($a_ids,$a_table,$a_field,$a_id_name)
489  {
490  global $ilDB;
491 
492  if(!$a_ids)
493  {
494  return array();
495  }
496 
497  // use database to sort user array
498  $where = "WHERE ".$a_id_name." IN ('";
499  $where .= implode("','",$a_ids);
500  $where .= "') ";
501 
502  $query = "SELECT ".$a_id_name." FROM ".$a_table." ".
503  $where.
504  "ORDER BY ".$a_field;
505 
506  $res = $ilDB->query($query);
507  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
508  {
509  $ids[] = $row->$a_id_name;
510  }
511  return $ids ? $ids : array();
512  }
513 
514  function __getPercent($max,$reached)
515  {
516  if(!$max)
517  {
518  return "0%";
519  }
520 
521  return sprintf("%.2f%%",$reached / $max * 100);
522  }
523 
524  function __readItemStatusInfo($a_items)
525  {
526  global $ilObjDataCache;
527 
528  foreach($a_items as $item_id)
529  {
530  $this->obj_data[$item_id]['mode'] = ilLPObjSettings::_lookupMode($item_id);
531  $this->obj_data[$item_id]['type'] = $ilObjDataCache->lookupType($item_id);
532  if($this->obj_data[$item_id]['mode'] == LP_MODE_TLT)
533  {
534  include_once './Services/MetaData/classes/class.ilMDEducational.php';
535  $this->obj_data[$item_id]['tlt'] = ilMDEducational::_getTypicalLearningTimeSeconds($item_id);
536  }
537  if($this->obj_data[$item_id]['mode'] == LP_MODE_VISITS)
538  {
539  include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
540  $this->obj_data[$item_id]['visits'] = ilLPObjSettings::_lookupVisits($item_id);
541  }
542  if($this->obj_data[$item_id]['mode'] == LP_MODE_SCORM)
543  {
544  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
545  $this->obj_data[$item_id]['scos'] = count(ilLPCollectionCache::_getItems($item_id));
546  }
547  }
548  }
549 
550  function __getLegendHTML()
551  {
552  global $lng;
553 
554  $tpl = new ilTemplate("tpl.lp_legend.html", true, true, "Services/Tracking");
555  $tpl->setVariable("IMG_NOT_ATTEMPTED",
556  ilUtil::getImagePath("scorm/not_attempted.gif"));
557  $tpl->setVariable("IMG_IN_PROGRESS",
558  ilUtil::getImagePath("scorm/incomplete.gif"));
559  $tpl->setVariable("IMG_COMPLETED",
560  ilUtil::getImagePath("scorm/completed.gif"));
561  $tpl->setVariable("IMG_FAILED",
562  ilUtil::getImagePath("scorm/failed.gif"));
563  $tpl->setVariable("TXT_NOT_ATTEMPTED",
564  $lng->txt("trac_not_attempted"));
565  $tpl->setVariable("TXT_IN_PROGRESS",
566  $lng->txt("trac_in_progress"));
567  $tpl->setVariable("TXT_COMPLETED",
568  $lng->txt("trac_completed"));
569  $tpl->setVariable("TXT_FAILED",
570  $lng->txt("trac_failed"));
571  return $tpl->get();
572  }
573 }
574 ?>