ILIAS  Release_4_1_x_branch Revision 61804
 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)
98  {
99  global $ilObjDataCache;
100 
101  include_once './Services/Search/classes/class.ilQueryParser.php';
102 
103  $query_parser =& new ilQueryParser($filter["query"]);
104  $query_parser->setMinWordLength(0);
105  $query_parser->setCombination(QP_COMBINATION_OR);
106  $query_parser->parse();
107  if(!$query_parser->validate())
108  {
109  // echo $query_parser->getMessage();
110  return false;
111  }
112 
113  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
114  $object_search =& new ilLikeObjectSearch($query_parser);
115  $object_search->setFilter($filter["type"]);
116  $res =& $object_search->performSearch();
117  $res->setRequiredPermission($permission);
118  $res->setMaxHits(1000);
119  $res->addObserver($this, "searchFilterListener");
120 
121  if(!$this->filter["area"])
122  {
123  $res->filter(ROOT_FOLDER_ID, false);
124  }
125  else
126  {
127  $res->filter($this->filter["area"], false);
128  }
129 
130  $objects = array();
131  foreach($res->getResults() as $obj_data)
132  {
133  $objects[$obj_data['obj_id']][] = $obj_data['ref_id'];
134  }
135 
136  // Check if search max hits is reached
137  $this->limit_reached = $res->isLimitReached();
138 
139  return $objects ? $objects : array();
140  }
141 
147  public function searchFilterListener($a_ref_id, $a_data)
148  {
149  if(is_array($this->filter["hide"]) && in_array($a_data["obj_id"], $this->filter["hide"]))
150  {
151  return false;
152  }
153  // :TODO: mode does not have to be set in db
154  if(ilLPObjSettings::_lookupMode($a_data["obj_id"]) == LP_MODE_DEACTIVATED)
155  {
156  return false;
157  }
158  return true;
159  }
160 
164  public function initFilter()
165  {
166  global $lng, $ilObjDataCache;
167 
168  $this->setDisableFilterHiding(true);
169 
170  // object type selection
171  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
172  $si = new ilSelectInputGUI($this->lng->txt("obj_type"), "type");
173  $si->setOptions($this->getPossibleTypes());
174  $this->addFilterItem($si);
175  $si->readFromSession();
176  if(!$si->getValue())
177  {
178  $si->setValue("crs");
179  }
180  $this->filter["type"] = $si->getValue();
181 
182  // hidden items
183  include_once("./Services/Form/classes/class.ilMultiSelectInputGUI.php");
184  $msi = new ilMultiSelectInputGUI($lng->txt("trac_filter_hidden"), "hide");
185  $this->addFilterItem($msi);
186  $msi->readFromSession();
187  $this->filter["hide"] = $msi->getValue();
188  if($this->filter["hide"])
189  {
190  // create options from current value
191  $types = $this->getCurrentFilter(true);
192  $types = $types["type"];
193  $options = array();
194  foreach($this->filter["hide"] as $obj_id)
195  {
196  if(in_array($ilObjDataCache->lookupType($obj_id), $types))
197  {
198  $options[$obj_id] = $ilObjDataCache->lookupTitle($obj_id);
199  }
200  }
201  $msi->setOptions($options);
202  }
203 
204  // title/description
205  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
206  $ti = new ilTextInputGUI($lng->txt("trac_title_description"), "query");
207  $ti->setMaxLength(64);
208  $ti->setSize(20);
209  $this->addFilterItem($ti);
210  $ti->readFromSession();
211  $this->filter["query"] = $ti->getValue();
212 
213  // repository area selection
214  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
215  $rs = new ilRepositorySelectorInputGUI($lng->txt("trac_filter_area"), "area");
216  $rs->setSelectText($lng->txt("trac_select_area"));
217  $this->addFilterItem($rs);
218  $rs->readFromSession();
219  $this->filter["area"] = $rs->getValue();
220  }
221 
228  protected function buildPath($ref_ids)
229  {
230  global $tree, $ilCtrl;
231 
232  include_once 'classes/class.ilLink.php';
233 
234  if(!count($ref_ids))
235  {
236  return false;
237  }
238  foreach($ref_ids as $ref_id)
239  {
240  $path = "...";
241  $counter = 0;
242  $path_full = $tree->getPathFull($ref_id);
243  foreach($path_full as $data)
244  {
245  if(++$counter < (count($path_full)-1))
246  {
247  continue;
248  }
249  $path .= " &raquo; ";
250  if($ref_id != $data['ref_id'])
251  {
252  $path .= $data['title'];
253  }
254  else
255  {
256  $path .= ('<a target="_top" href="'.
257  ilLink::_getLink($data['ref_id'],$data['type']).'">'.
258  $data['title'].'</a>');
259  }
260  }
261 
262  $result[] = $path;
263  }
264  return $result;
265  }
266 
270  protected function getPossibleTypes()
271  {
272  global $lng;
273 
274  return array('crs' => $lng->txt('objs_crs'),
275  'grp' => $lng->txt('objs_grp'),
276  'lm' => $lng->txt('learning_resources'),
277  'exc' => $lng->txt('objs_exc'),
278  'tst' => $lng->txt('objs_tst'));
279  }
280 
281  protected function parseValue($id, $value, $type)
282  {
283  global $lng;
284 
285  // get rid of aggregation
286  $pos = strrpos($id, "_");
287  if($pos !== false)
288  {
289  $function = strtoupper(substr($id, $pos+1));
290  if(in_array($function, array("MIN", "MAX", "SUM", "AVG", "COUNT")))
291  {
292  $id = substr($id, 0, $pos);
293  }
294  }
295 
296  if(trim($value) == "" && $id != "status")
297  {
298  if($id == "title" && get_class($this) != "ilTrObjectUsersPropsTableGUI")
299  {
300  return "--".$lng->txt("none")."--";
301  }
302  return " ";
303  }
304 
305  switch($id)
306  {
307  case "first_access":
308  case "create_date":
310  break;
311 
312  case "last_access":
314  break;
315 
316  case "birthday":
317  $value = ilDatePresentation::formatDate(new ilDate($value, IL_CAL_DATE));
318  break;
319 
320  case "spent_seconds":
321  if(in_array($type, array("exc")))
322  {
323  $value = "-";
324  }
325  else
326  {
327  include_once("./classes/class.ilFormat.php");
328  $value = ilFormat::_secondsToString($value);
329  }
330  break;
331 
332  case "percentage":
333  /* :TODO:
334  if(in_array(strtolower($this->status_class),
335  array("illpstatusmanual", "illpstatusscormpackage", "illpstatustestfinished")) ||
336  $type == "exc"))
337  */
338  if(false)
339  {
340  $value = "-";
341  }
342  else
343  {
344  $value = $value."%";
345  }
346  break;
347 
348  case "mark":
349  if(in_array($type, array("lm", "dbk")))
350  {
351  $value = "-";
352  }
353  break;
354 
355  case "gender":
356  $value = $lng->txt("gender_".$value);
357  break;
358 
359  case "status":
360  include_once("./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php");
363  $value = ilUtil::img($path, $text);
364  break;
365 
366  case "language":
367  $value = $lng->txt("lang_".$value);
368  break;
369 
370  case "sel_country":
371  $value = $lng->txt("meta_c_".$value);
372  break;
373  }
374 
375  return $value;
376  }
377 
378  public function getCurrentFilter($as_query = false)
379  {
380  $result = array();
381  foreach($this->filter as $id => $value)
382  {
383  $item = $this->getFilterItemByPostVar($id);
384  switch($id)
385  {
386  case "type":
387  switch($value)
388  {
389  case 'lm':
390  $result["type"] = array('lm','sahs','htlm','dbk');
391  break;
392 
393  default:
394  $result["type"] = array($value);
395  break;
396  }
397  break;
398 
399  case "title":
400  case "country":
401  case "gender":
402  case "city":
403  case "language":
404  case "login":
405  case "firstname":
406  case "lastname":
407  case "mark":
408  case "u_comment":
409  case "institution":
410  case "department":
411  case "title":
412  case "street":
413  case "zipcode":
414  case "email":
415  case "matriculation":
416  case "sel_country":
417  case "query":
418  if($value)
419  {
420  $result[$id] = $value;
421  }
422  break;
423 
424  case "status":
425  if($value !== false)
426  {
427  $result[$id] = $value;
428  }
429  break;
430 
431  case "user_total":
432  case "read_count":
433  case "percentage":
434  case "hidden":
435  case "spent_seconds":
436  if(is_array($value) && implode("", $value))
437  {
438  $result[$id] = $value;
439  }
440  break;
441 
442  case "registration":
443  case "create_date":
444  case "first_access":
445  case "last_access":
446  case "birthday":
447  if($value)
448  {
449  if($value["from"])
450  {
451  $result[$id]["from"] = $value["from"]->get(IL_CAL_DATETIME);
452  $result[$id]["from"] = substr($result[$id]["from"], 0, -8)."00:00:00";
453  }
454  if($value["to"])
455  {
456  $result[$id]["to"] = $value["to"]->get(IL_CAL_DATETIME);
457  $result[$id]["to"] = substr($result[$id]["to"], 0, -8)."23:59:59";
458  }
459  }
460  break;
461  }
462  }
463 
464  return $result;
465  }
466 
467  protected function isPercentageAvailable($a_obj_id)
468  {
469  include_once("./Services/Tracking/classes/class.ilLPObjSettings.php");
470  $mode = ilLPObjSettings::_lookupMode($a_obj_id);
471  if(in_array($mode, array(LP_MODE_TLT, LP_MODE_VISITS, LP_MODE_OBJECTIVES, LP_MODE_SCORM,
473  {
474  return true;
475  }
476  return false;
477  }
478 
479  protected function parseTitle($a_obj_id, $action, $a_user_id = false)
480  {
481  global $lng, $ilObjDataCache, $ilUser;
482 
483  $user = "";
484  if($a_user_id)
485  {
486  if($a_user_id != $ilUser->getId())
487  {
488  $a_user = ilObjectFactory::getInstanceByObjId($a_user_id);
489  }
490  else
491  {
492  $a_user = $ilUser;
493  }
494  $user .= ", ".$a_user->getFullName(); // " [".$a_user->getLogin()."]";
495  }
496 
497  $this->setTitle($lng->txt($action).": ".$ilObjDataCache->lookupTitle($a_obj_id).$user);
498  $this->setDescription($this->lng->txt('trac_mode').": ".ilLPObjSettings::_mode2Text(ilLPObjSettings::_lookupMode($a_obj_id)));
499  }
500 
506  protected function getExportMeta()
507  {
508  global $lng, $ilObjDataCache, $ilUser, $ilClientIniFile;
509 
510  /* see spec
511  Name of installation
512  Name of the course
513  Permalink to course
514  Owner of course object
515  Date of report generation
516  Reporting period
517  Name of person who generated the report.
518  */
519 
521  include_once './classes/class.ilLink.php';
522 
523  $data = array(
524  $lng->txt("trac_name_of_installation") => $ilClientIniFile->readVariable('client', 'name'),
525  $lng->txt("trac_object_name") => $ilObjDataCache->lookupTitle($this->obj_id),
526  $lng->txt("trac_object_link") => ilLink::_getLink($this->ref_id, ilObject::_lookupType($this->obj_id)),
527  $lng->txt("trac_object_owner") => ilObjUser::_lookupFullname(ilObject::_lookupOwner($this->obj_id)),
528  $lng->txt("trac_report_date") =>
530  $lng->txt("trac_report_owner") => $ilUser->getFullName()
531  );
532  return $data;
533  }
534 
535  protected function fillMetaExcel($worksheet, &$a_row)
536  {
537  foreach($this->getExportMeta() as $caption => $value)
538  {
539  $worksheet->write($a_row, 0, $caption);
540  $worksheet->write($a_row, 1, $value);
541  $a_row++;
542  }
543  $a_row++;
544  }
545 
546  protected function fillMetaCSV($a_csv)
547  {
548  foreach($this->getExportMeta() as $caption => $value)
549  {
550  $a_csv->addColumn(strip_tags($caption));
551  $a_csv->addColumn(strip_tags($value));
552  $a_csv->addRow();
553  }
554  $a_csv->addRow();
555  }
556 
557  protected function showTimingsWarning($a_ref_id, $a_user_id)
558  {
559  include_once 'Modules/Course/classes/Timings/class.ilTimingCache.php';
560  if(ilTimingCache::_showWarning($a_ref_id, $a_user_id))
561  {
562  $timings = ilTimingCache::_getTimings($a_ref_id);
563  if($timings['item']['changeable'] and $timings['user'][$a_usr_id]['end'])
564  {
565  $end = $timings['user'][$a_usr_id]['end'];
566  }
567  else if ($timings['item']['suggestion_end'])
568  {
569  $end = $timings['item']['suggestion_end'];
570  }
571  else
572  {
573  $end = true;
574  }
575  return $end;
576  }
577  }
578 }
579 
580 ?>