ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPTableBaseGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 include_once './Services/Search/classes/class.ilSearchSettings.php';
6 
16 {
17  protected $filter; // array
18 
19  public function __construct($a_parent_obj, $a_parent_cmd = "", $a_template_context = "")
20  {
21  parent::__construct($a_parent_obj, $a_parent_cmd, $a_template_context);
22 
23  // country names
24  $this->lng->loadLanguageModule("meta");
25  }
26 
27  public function executeCommand()
28  {
29  global $ilCtrl;
30 
31  $this->determineSelectedFilters();
32 
33  if(!$ilCtrl->getNextClass($this))
34  {
35  $to_hide = false;
36 
37  switch($ilCtrl->getCmd())
38  {
39  case "applyFilter":
40  $this->resetOffset();
41  $this->writeFilterToSession();
42  break;
43 
44  case "resetFilter":
45  $this->resetOffset();
46  $this->resetFilter();
47  break;
48 
49  case "hideSelected":
50  $to_hide = $_POST["item_id"];
51  break;
52 
53  case "hide":
54  $to_hide = array((int)$_GET["hide"]);
55  break;
56 
57  // page selector
58  default:
59  $this->determineOffsetAndOrder();
60  $this->storeNavParameter();
61  break;
62  }
63 
64  if($to_hide)
65  {
66  $obj = $this->getFilterItemByPostVar("hide");
67  $value = array_unique(array_merge((array)$obj->getValue(), $to_hide));
68  $obj->setValue($value);
69  $obj->writeToSession();
70  }
71 
72  if(isset($_POST["tbltplcrt"]))
73  {
74  $ilCtrl->setParameter($this->parent_obj, "tbltplcrt", $_POST["tbltplcrt"]);
75  }
76  if(isset($_POST["tbltpldel"]))
77  {
78  $ilCtrl->setParameter($this->parent_obj, "tbltpldel", $_POST["tbltpldel"]);
79  }
80 
81  $ilCtrl->redirect($this->parent_obj, $this->parent_cmd);
82  }
83  else
84  {
85  // e.g. repository selector
86  return parent::executeCommand();
87  }
88  }
89 
97  protected function searchObjects(array $filter, $permission, array $preset_obj_ids = null)
98  {
99  global $ilObjDataCache;
100 
101  /* for performance issues: fast search WITHOUT any permission checks
102  include_once "Services/Tracking/classes/class.ilTrQuery.php";
103  return ilTrQuery::searchObjects($filter["type"], $filter["query"], $filter["area"]);
104  */
105 
106  include_once './Services/Search/classes/class.ilQueryParser.php';
107 
108  $query_parser =& new ilQueryParser($filter["query"]);
109  $query_parser->setMinWordLength(0);
110  $query_parser->setCombination(QP_COMBINATION_AND);
111  $query_parser->parse();
112  if(!$query_parser->validate())
113  {
114  // echo $query_parser->getMessage();
115  return false;
116  }
117 
118  if($filter["type"] == "lres")
119  {
120  $filter["type"] = array('lm','sahs','htlm','dbk');
121  }
122  else
123  {
124  $filter["type"] = array($filter["type"]);
125  }
126 
127  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
128  $object_search =& new ilLikeObjectSearch($query_parser);
129  $object_search->setFilter($filter["type"]);
130  if($preset_obj_ids)
131  {
132  $object_search->setIdFilter($preset_obj_ids);
133  }
134  $res =& $object_search->performSearch();
135  $res->setRequiredPermission($permission);
136  $res->setMaxHits(1000);
137  $res->addObserver($this, "searchFilterListener");
138 
139  if(!$this->filter["area"])
140  {
141  $res->filter(ROOT_FOLDER_ID, false);
142  }
143  else
144  {
145  $res->filter($this->filter["area"], false);
146  }
147 
148  $objects = array();
149  foreach($res->getResults() as $obj_data)
150  {
151  $objects[$obj_data['obj_id']][] = $obj_data['ref_id'];
152  }
153 
154  // Check if search max hits is reached
155  $this->limit_reached = $res->isLimitReached();
156 
157  return $objects ? $objects : array();
158  }
159 
165  public function searchFilterListener($a_ref_id, $a_data)
166  {
167  if(is_array($this->filter["hide"]) && in_array($a_data["obj_id"], $this->filter["hide"]))
168  {
169  return false;
170  }
171  // :TODO: mode does not have to be set in db
172  if(ilLPObjSettings::_lookupMode($a_data["obj_id"]) == LP_MODE_DEACTIVATED)
173  {
174  return false;
175  }
176  return true;
177  }
178 
184  public function initFilter($a_split_learning_resources = false)
185  {
186  global $lng, $ilObjDataCache;
187 
188  $this->setDisableFilterHiding(true);
189 
190  // object type selection
191  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
192  $si = new ilSelectInputGUI($this->lng->txt("obj_type"), "type");
193  $si->setOptions($this->getPossibleTypes($a_split_learning_resources));
194  $this->addFilterItem($si);
195  $si->readFromSession();
196  if(!$si->getValue())
197  {
198  $si->setValue("crs");
199  }
200  $this->filter["type"] = $si->getValue();
201 
202  // hidden items
203  include_once("./Services/Form/classes/class.ilMultiSelectInputGUI.php");
204  $msi = new ilMultiSelectInputGUI($lng->txt("trac_filter_hidden"), "hide");
205  $this->addFilterItem($msi);
206  $msi->readFromSession();
207  $this->filter["hide"] = $msi->getValue();
208  if($this->filter["hide"])
209  {
210  // create options from current value
211  $types = $this->getCurrentFilter(true);
212  $type = $types["type"];
213  $options = array();
214  if($type == 'lres')
215  {
216  $type = array('lm','sahs','htlm','dbk');
217  }
218  else
219  {
220  $type = array($type);
221  }
222  foreach($this->filter["hide"] as $obj_id)
223  {
224  if(in_array($ilObjDataCache->lookupType($obj_id), $type))
225  {
226  $options[$obj_id] = $ilObjDataCache->lookupTitle($obj_id);
227  }
228  }
229  $msi->setOptions($options);
230  }
231 
232  // title/description
233  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
234  $ti = new ilTextInputGUI($lng->txt("trac_title_description"), "query");
235  $ti->setMaxLength(64);
236  $ti->setSize(20);
237  $this->addFilterItem($ti);
238  $ti->readFromSession();
239  $this->filter["query"] = $ti->getValue();
240 
241  // repository area selection
242  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
243  $rs = new ilRepositorySelectorInputGUI($lng->txt("trac_filter_area"), "area");
244  $rs->setSelectText($lng->txt("trac_select_area"));
245  $this->addFilterItem($rs);
246  $rs->readFromSession();
247  $this->filter["area"] = $rs->getValue();
248  }
249 
258  protected function buildPath($ref_ids, $as_link = true, $only_parents = false)
259  {
260  global $tree;
261 
262  include_once 'classes/class.ilLink.php';
263 
264  if(!count($ref_ids))
265  {
266  return false;
267  }
268 
269  $result = array();
270  foreach($ref_ids as $ref_id)
271  {
272  $path = "...";
273  $counter = 0;
274  $path_full = $tree->getPathFull($ref_id);
275  foreach($path_full as $data)
276  {
277  if(++$counter < (count($path_full)-1))
278  {
279  continue;
280  }
281  if($ref_id != $data['ref_id'] || !$only_parents)
282  {
283  $path .= " &raquo; ";
284  if($ref_id != $data['ref_id'] || !$as_link)
285  {
286  $path .= $data['title'];
287  }
288  else
289  {
290  $path .= ('<a target="_top" href="'.
291  ilLink::_getLink($data['ref_id'],$data['type']).'">'.
292  $data['title'].'</a>');
293  }
294  }
295  }
296 
297  $result[$ref_id] = $path;
298  }
299  return $result;
300  }
301 
309  protected function getPossibleTypes($a_split_learning_resources = false, $a_include_digilib = false, $a_allow_undefined_lp = false)
310  {
311  global $lng;
312 
313  $options = array();
314 
315  if($a_split_learning_resources)
316  {
317  $options['lm'] = $lng->txt('objs_lm');
318  $options['sahs'] = $lng->txt('objs_sahs');
319  $options['htlm'] = $lng->txt('objs_htlm');
320 
321  if($a_include_digilib)
322  {
323  $options['dbk'] = $lng->txt('objs_dbk');
324  }
325  }
326  else
327  {
328  $options['lres'] = $lng->txt('learning_resources');
329  }
330 
331  $options['crs'] = $lng->txt('objs_crs');
332  $options['grp'] = $lng->txt('objs_grp');
333  $options['exc'] = $lng->txt('objs_exc');
334  $options['tst'] = $lng->txt('objs_tst');
335 
336  if($a_allow_undefined_lp)
337  {
338  $options["file"] = $lng->txt("objs_file");
339  $options["webr"] = $lng->txt("objs_webr");
340  $options["wiki"] = $lng->txt("objs_wiki");
341  }
342 
343  asort($options);
344  return $options;
345  }
346 
347  protected function parseValue($id, $value, $type)
348  {
349  global $lng;
350 
351  // get rid of aggregation
352  $pos = strrpos($id, "_");
353  if($pos !== false)
354  {
355  $function = strtoupper(substr($id, $pos+1));
356  if(in_array($function, array("MIN", "MAX", "SUM", "AVG", "COUNT")))
357  {
358  $id = substr($id, 0, $pos);
359  }
360  }
361 
362  if(trim($value) == "" && $id != "status")
363  {
364  if($id == "title" && get_class($this) != "ilTrObjectUsersPropsTableGUI")
365  {
366  return "--".$lng->txt("none")."--";
367  }
368  return " ";
369  }
370 
371  switch($id)
372  {
373  case "first_access":
374  case "create_date":
375  case 'status_changed':
377  break;
378 
379  case "last_access":
381  break;
382 
383  case "birthday":
384  $value = ilDatePresentation::formatDate(new ilDate($value, IL_CAL_DATE));
385  break;
386 
387  case "spent_seconds":
388  if(in_array($type, array("exc")))
389  {
390  $value = "-";
391  }
392  else
393  {
394  include_once("./classes/class.ilFormat.php");
395  $value = ilFormat::_secondsToString($value);
396  }
397  break;
398 
399  case "percentage":
400  /* :TODO:
401  if(in_array(strtolower($this->status_class),
402  array("illpstatusmanual", "illpstatusscormpackage", "illpstatustestfinished")) ||
403  $type == "exc"))
404  */
405  if(false)
406  {
407  $value = "-";
408  }
409  else
410  {
411  $value = $value."%";
412  }
413  break;
414 
415  case "mark":
416  if(in_array($type, array("lm", "dbk")))
417  {
418  $value = "-";
419  }
420  break;
421 
422  case "gender":
423  $value = $lng->txt("gender_".$value);
424  break;
425 
426  case "status":
427  include_once("./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php");
430  $value = ilUtil::img($path, $text);
431  break;
432 
433  case "language":
434  $value = $lng->txt("lang_".$value);
435  break;
436 
437  case "sel_country":
438  $value = $lng->txt("meta_c_".$value);
439  break;
440  }
441 
442  return $value;
443  }
444 
445  public function getCurrentFilter($as_query = false)
446  {
447  $result = array();
448  foreach($this->filter as $id => $value)
449  {
450  $item = $this->getFilterItemByPostVar($id);
451  switch($id)
452  {
453  case "title":
454  case "country":
455  case "gender":
456  case "city":
457  case "language":
458  case "login":
459  case "firstname":
460  case "lastname":
461  case "mark":
462  case "u_comment":
463  case "institution":
464  case "department":
465  case "title":
466  case "street":
467  case "zipcode":
468  case "email":
469  case "matriculation":
470  case "sel_country":
471  case "query":
472  case "type":
473  case "area":
474  if($value)
475  {
476  $result[$id] = $value;
477  }
478  break;
479 
480  case "status":
481  if($value !== false)
482  {
483  $result[$id] = $value;
484  }
485  break;
486 
487  case "user_total":
488  case "read_count":
489  case "percentage":
490  case "hidden":
491  case "spent_seconds":
492  if(is_array($value) && implode("", $value))
493  {
494  $result[$id] = $value;
495  }
496  break;
497 
498  case "registration":
499  case "create_date":
500  case "first_access":
501  case "last_access":
502  case "birthday":
503  case 'status_changed':
504  if($value)
505  {
506  if($value["from"])
507  {
508  $result[$id]["from"] = $value["from"]->get(IL_CAL_DATETIME);
509  $result[$id]["from"] = substr($result[$id]["from"], 0, -8)."00:00:00";
510  }
511  if($value["to"])
512  {
513  $result[$id]["to"] = $value["to"]->get(IL_CAL_DATETIME);
514  $result[$id]["to"] = substr($result[$id]["to"], 0, -8)."23:59:59";
515  }
516  }
517  break;
518  }
519  }
520 
521  return $result;
522  }
523 
524  protected function isPercentageAvailable($a_obj_id)
525  {
526  include_once("./Services/Tracking/classes/class.ilLPObjSettings.php");
527  $mode = ilLPObjSettings::_lookupMode($a_obj_id);
528  if(in_array($mode, array(LP_MODE_TLT, LP_MODE_VISITS, LP_MODE_OBJECTIVES, LP_MODE_SCORM,
530  {
531  return true;
532  }
533  return false;
534  }
535 
536  protected function parseTitle($a_obj_id, $action, $a_user_id = false)
537  {
538  global $lng, $ilObjDataCache, $ilUser;
539 
540  $user = "";
541  if($a_user_id)
542  {
543  if($a_user_id != $ilUser->getId())
544  {
545  $a_user = ilObjectFactory::getInstanceByObjId($a_user_id);
546  }
547  else
548  {
549  $a_user = $ilUser;
550  }
551  $user .= ", ".$a_user->getFullName(); // " [".$a_user->getLogin()."]";
552  }
553 
554  if($a_obj_id != ROOT_FOLDER_ID)
555  {
556  $this->setTitle($lng->txt($action).": ".$ilObjDataCache->lookupTitle($a_obj_id).$user);
557  $this->setDescription($this->lng->txt('trac_mode').": ".ilLPObjSettings::_mode2Text(ilLPObjSettings::_lookupMode($a_obj_id)));
558  }
559  else
560  {
561  $this->setTitle($lng->txt($action));
562  }
563  }
564 
570  protected function getExportMeta()
571  {
572  global $lng, $ilObjDataCache, $ilUser, $ilClientIniFile;
573 
574  /* see spec
575  Name of installation
576  Name of the course
577  Permalink to course
578  Owner of course object
579  Date of report generation
580  Reporting period
581  Name of person who generated the report.
582  */
583 
585  include_once './classes/class.ilLink.php';
586 
587  $data = array(
588  $lng->txt("trac_name_of_installation") => $ilClientIniFile->readVariable('client', 'name'),
589  $lng->txt("trac_object_name") => $ilObjDataCache->lookupTitle($this->obj_id),
590  $lng->txt("trac_object_link") => ilLink::_getLink($this->ref_id, ilObject::_lookupType($this->obj_id)),
591  $lng->txt("trac_object_owner") => ilObjUser::_lookupFullname(ilObject::_lookupOwner($this->obj_id)),
592  $lng->txt("trac_report_date") =>
594  $lng->txt("trac_report_owner") => $ilUser->getFullName()
595  );
596  return $data;
597  }
598 
599  protected function fillMetaExcel($worksheet, &$a_row)
600  {
601  foreach($this->getExportMeta() as $caption => $value)
602  {
603  $worksheet->write($a_row, 0, $caption);
604  $worksheet->write($a_row, 1, $value);
605  $a_row++;
606  }
607  $a_row++;
608  }
609 
610  protected function fillMetaCSV($a_csv)
611  {
612  foreach($this->getExportMeta() as $caption => $value)
613  {
614  $a_csv->addColumn(strip_tags($caption));
615  $a_csv->addColumn(strip_tags($value));
616  $a_csv->addRow();
617  }
618  $a_csv->addRow();
619  }
620 
621  protected function showTimingsWarning($a_ref_id, $a_user_id)
622  {
623  include_once 'Modules/Course/classes/Timings/class.ilTimingCache.php';
624  if(ilTimingCache::_showWarning($a_ref_id, $a_user_id))
625  {
626  $timings = ilTimingCache::_getTimings($a_ref_id);
627  if($timings['item']['changeable'] and $timings['user'][$a_usr_id]['end'])
628  {
629  $end = $timings['user'][$a_usr_id]['end'];
630  }
631  else if ($timings['item']['suggestion_end'])
632  {
633  $end = $timings['item']['suggestion_end'];
634  }
635  else
636  {
637  $end = true;
638  }
639  return $end;
640  }
641  }
642 
643  protected function formatSeconds($seconds, $a_shorten_zero = false)
644  {
645  $seconds = $seconds ? $seconds : 0;
646  if($a_shorten_zero && !$seconds)
647  {
648  return "-";
649  }
650 
651  $hours = floor($seconds / 3600);
652  $rest = $seconds % 3600;
653 
654  $minutes = floor($rest / 60);
655  $rest = $rest % 60;
656 
657  if($rest)
658  {
659  $minutes++;
660  }
661 
662  return sprintf("%dh%02dm",$hours,$minutes);
663  }
664 
665  protected function anonymizeValue($a_value, $a_force_number = false)
666  {
667  // currently inactive
668  return $a_value;
669 
670  if(is_numeric($a_value))
671  {
672  $threshold = 3;
673  $a_value = (int)$a_value;
674  if($a_value <= $threshold)
675  {
676  if(!$a_force_number)
677  {
678  return "0-".$threshold;
679  }
680  else
681  {
682  return $threshold;
683  }
684  }
685  }
686  return $a_value;
687  }
688 
689  protected function buildValueScale($a_max_value, $a_anonymize = false, $a_format_seconds = false)
690  {
691  $step = 0;
692  if($a_max_value)
693  {
694  $step = $a_max_value / 10;
695  $base = ceil(log($step, 10));
696  $fac = ceil($step / pow(10, ($base - 1)));
697  $step = pow(10, $base - 1) * $fac;
698  }
699  if ($step <= 1)
700  {
701  $step = 1;
702  }
703  $ticks = range(0, $a_max_value+$step, $step);
704 
705  $value_ticks = array(0 => 0);
706  foreach($ticks as $tick)
707  {
708  $value = $tvalue = $tick;
709  if($a_anonymize)
710  {
711  $value = $this->anonymizeValue($value, true);
712  $tvalue = $this->anonymizeValue($tvalue);
713  }
714  if($a_format_seconds)
715  {
716  $tvalue = $this->formatSeconds($value);
717  }
718  $value_ticks[$value] = $tvalue;
719  }
720 
721  return $value_ticks;
722  }
723 }
724 
725 ?>