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