ILIAS  Release_4_0_x_branch Revision 61816
 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 = ilRPCServerSettings::getInstance();
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  // display infopanel if something happened
277  }
278 
279  }
280 
284  function __insertPath(&$a_tpl,$a_ref_id)
285  {
286  global $tree;
287 
288  $path_arr = $tree->getPathFull($a_ref_id);
289  $counter = 0;
290  foreach($tree->getPathFull($a_ref_id) as $data)
291  {
292  if($counter++)
293  {
294  $path .= " -> ";
295  }
296  $path .= $data['title'];
297  }
298  $a_tpl->setCurrentBlock("path_item");
299  $a_tpl->setVariable("PATH_ITEM",$path);
300  $a_tpl->parseCurrentBlock();
301 
302  $a_tpl->setCurrentBlock("path");
303  $a_tpl->parseCurrentBlock();
304 
305  return $path;
306  }
307 
308  function __showImageByStatus(&$tpl,$a_status,$tpl_prefix = "")
309  {
310  return ilLearningProgressBaseGUI::_showImageByStatus($tpl,$a_status,$tpl_prefix);
311  }
312 
313  // we need this public in table classes
314  public static function _showImageByStatus(&$tpl,$a_status,$tpl_prefix = "")
315  {
316  global $lng;
317 
318  switch($a_status)
319  {
322  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/incomplete.gif'));
323  $tpl->setVariable($tpl_prefix."STATUS_ALT",$lng->txt($a_status));
324  break;
325 
326  case LP_STATUS_COMPLETED:
328  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/complete.gif'));
329  $tpl->setVariable($tpl_prefix."STATUS_ALT",$lng->txt($a_status));
330  break;
331 
335  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/not_attempted.gif'));
336  $tpl->setVariable($tpl_prefix."STATUS_ALT",$lng->txt($a_status));
337  break;
338 
339  case LP_STATUS_FAILED:
340  $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/failed.gif'));
341  $tpl->setVariable($tpl_prefix."STATUS_ALT",$lng->txt($a_status));
342  break;
343  }
344  return true;
345  }
346 
347 
348  // Protected Table gui methods
349  function &__initTableGUI()
350  {
351  include_once "./Services/Table/classes/class.ilTableGUI.php";
352 
353  return new ilTableGUI(0,false);
354  }
355 
356 
360  function __showObjectDetails(&$info,$item_id = 0)
361  {
362  global $ilObjDataCache;
363 
364  $details_id = $item_id ? $item_id : $this->details_id;
365 
366 
367  // Section object details
368  $info->addSection($this->lng->txt('details'));
369  $info->addProperty($this->lng->txt('title'),$ilObjDataCache->lookupTitle($details_id));
370  if(strlen($desc = $ilObjDataCache->lookupDescription($details_id)))
371  {
372  $info->addProperty($this->lng->txt('description'),$desc);
373  }
374  $info->addProperty($this->lng->txt('trac_mode'),ilLPObjSettings::_mode2Text(ilLPObjSettings::_lookupMode($details_id)));
375 
376  if(ilLPObjSettings::_lookupMode($details_id) == LP_MODE_VISITS)
377  {
378  $info->addProperty($this->lng->txt('trac_required_visits'),ilLPObjSettings::_lookupVisits($details_id));
379  }
380 
381  include_once './Services/MetaData/classes/class.ilMDEducational.php';
382  if($seconds = ilMDEducational::_getTypicalLearningTimeSeconds($details_id))
383  {
384  $info->addProperty($this->lng->txt('meta_typical_learning_time'),ilFormat::_secondsToString($seconds));
385  }
386  }
387 
388  function __appendLPDetails(&$info,$item_id,$user_id)
389  {
390  global $ilObjDataCache;
391 
392  $type = $ilObjDataCache->lookupType($item_id);
393 
394  // Section learning_progress
395  $info->addSection($this->lng->txt('trac_learning_progress'));
396 
397  switch($type)
398  {
399  case 'lm':
400  case 'htlm':
401  include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
402  $progress = ilLearningProgress::_getProgress($user_id,$item_id);
403 
404  if($progress['access_time'])
405  {
406  $info->addProperty($this->lng->txt('last_access'),
407  ilDatePresentation::formatDate(new ilDateTime($progress['access_time'],IL_CAL_DATETIME)));
408  }
409  else
410  {
411  $info->addProperty($this->lng->txt('last_access'),$this->lng->txt('trac_not_accessed'));
412  }
413  $info->addProperty($this->lng->txt('trac_visits'),(int) $progress['visits']);
414  if($type == 'lm')
415  {
416  $info->addProperty($this->lng->txt('trac_spent_time'),ilFormat::_secondsToString($progress['spent_seconds']));
417  }
418  $info->addProperty($this->lng->txt('trac_status'),$this->lng->txt($this->__readStatus($item_id,$user_id)));
419  break;
420 
421  case 'exc':
422  case 'tst':
423  case 'crs':
424  case 'sahs':
425  case 'grp':
426  $info->addProperty($this->lng->txt('trac_status'),$this->lng->txt($this->__readStatus($item_id,$user_id)));
427  break;
428 
429  }
430 
431  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
432  if(strlen($mark = ilLPMarks::_lookupMark($user_id,$item_id)))
433  {
434  $info->addProperty($this->lng->txt('trac_mark'),$mark);
435  }
436  if(strlen($comment = ilLPMarks::_lookupComment($user_id,$item_id)))
437  {
438  $info->addProperty($this->lng->txt('trac_comment'),$comment);
439  }
440  }
441 
442  function __readStatus($a_obj_id,$user_id)
443  {
444  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
445 
446  if(in_array($user_id,ilLPStatusWrapper::_getInProgress($a_obj_id)))
447  {
448  return $status = LP_STATUS_IN_PROGRESS;
449  }
450  elseif(in_array($user_id,ilLPStatusWrapper::_getCompleted($a_obj_id)))
451  {
452  return $status = LP_STATUS_COMPLETED;
453  }
454  elseif(in_array($user_id,ilLPStatusWrapper::_getFailed($a_obj_id)))
455  {
456  return $status = LP_STATUS_FAILED;
457  }
458  else
459  {
460  return $status = LP_STATUS_NOT_ATTEMPTED;
461  }
462  }
463 
464 
465  function __showButton($a_link,$a_text,$a_target = '')
466  {
467  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
468 
469  // display button
470  $this->tpl->setCurrentBlock("btn_cell");
471  $this->tpl->setVariable("BTN_LINK",$a_link);
472  $this->tpl->setVariable("BTN_TXT",$a_text);
473  if($a_target)
474  {
475  $this->tpl->setVariable("BTN_TARGET",$a_target);
476  }
477 
478  $this->tpl->parseCurrentBlock();
479  }
480 
481 
494  function __sort($a_ids,$a_table,$a_field,$a_id_name)
495  {
496  global $ilDB;
497 
498  if(!$a_ids)
499  {
500  return array();
501  }
502 
503  // comment by mjansen: Requesting database in gui classes?
504 
505  // use database to sort user array
506  $where = "WHERE ".$ilDB->in($a_id_name, $a_ids, false, 'integer')." ";
507 
508  $query = "SELECT ".$a_id_name." FROM ".$a_table." ".
509  $where.
510  "ORDER BY ".$a_field;
511 
512  $res = $ilDB->query($query);
513  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
514  {
515  $ids[] = $row->$a_id_name;
516  }
517  return $ids ? $ids : array();
518  }
519 
520  function __getPercent($max,$reached)
521  {
522  if(!$max)
523  {
524  return "0%";
525  }
526 
527  return sprintf("%d%%",$reached / $max * 100);
528  }
529 
530  function __readItemStatusInfo($a_items)
531  {
532  global $ilObjDataCache;
533 
534  foreach($a_items as $item_id)
535  {
536  $this->obj_data[$item_id]['mode'] = ilLPObjSettings::_lookupMode($item_id);
537  $this->obj_data[$item_id]['type'] = $ilObjDataCache->lookupType($item_id);
538  if($this->obj_data[$item_id]['mode'] == LP_MODE_TLT)
539  {
540  include_once './Services/MetaData/classes/class.ilMDEducational.php';
541  $this->obj_data[$item_id]['tlt'] = ilMDEducational::_getTypicalLearningTimeSeconds($item_id);
542  }
543  if($this->obj_data[$item_id]['mode'] == LP_MODE_VISITS)
544  {
545  include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
546  $this->obj_data[$item_id]['visits'] = ilLPObjSettings::_lookupVisits($item_id);
547  }
548  if($this->obj_data[$item_id]['mode'] == LP_MODE_SCORM)
549  {
550  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
551  $this->obj_data[$item_id]['scos'] = count(ilLPCollectionCache::_getItems($item_id));
552  }
553  }
554  }
555 
556  function __getLegendHTML()
557  {
558  global $lng;
559 
560  $tpl = new ilTemplate("tpl.lp_legend.html", true, true, "Services/Tracking");
561  $tpl->setVariable("IMG_NOT_ATTEMPTED",
562  ilUtil::getImagePath("scorm/not_attempted.gif"));
563  $tpl->setVariable("IMG_IN_PROGRESS",
564  ilUtil::getImagePath("scorm/incomplete.gif"));
565  $tpl->setVariable("IMG_COMPLETED",
566  ilUtil::getImagePath("scorm/completed.gif"));
567  $tpl->setVariable("IMG_FAILED",
568  ilUtil::getImagePath("scorm/failed.gif"));
569  $tpl->setVariable("TXT_NOT_ATTEMPTED",
570  $lng->txt("trac_not_attempted"));
571  $tpl->setVariable("TXT_IN_PROGRESS",
572  $lng->txt("trac_in_progress"));
573  $tpl->setVariable("TXT_COMPLETED",
574  $lng->txt("trac_completed"));
575  $tpl->setVariable("TXT_FAILED",
576  $lng->txt("trac_failed"));
577  return $tpl->get();
578  }
579 }
580 ?>