ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTrUserObjectsPropsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Tracking/classes/class.ilLPTableBaseGUI.php");
5 
16 {
20  function __construct($a_parent_obj, $a_parent_cmd, $a_user_id, $a_obj_id, $a_ref_id, $a_print_view = false)
21  {
22  global $ilCtrl, $lng, $ilAccess, $lng, $rbacsystem;
23 
24  $this->setId("truop");
25  $this->user_id = $a_user_id;
26  $this->obj_id = $a_obj_id;
27  $this->ref_id = $a_ref_id;
28 
29  parent::__construct($a_parent_obj, $a_parent_cmd);
30  $this->setLimit(9999);
31 
32  $this->parseTitle($this->obj_id, "details", $this->user_id);
33 
34  if($a_print_view)
35  {
36  $this->setPrintMode(true);
37  }
38 
39  $this->addColumn($this->lng->txt("title"), "title");
40 
41  foreach ($this->getSelectedColumns() as $c)
42  {
43  $l = $c;
44  if (in_array($l, array("last_access", "first_access", "read_count", "spent_seconds", "mark", "status", "percentage")))
45  {
46  $l = "trac_".$l;
47  }
48  if ($l == "u_comment")
49  {
50  $l = "trac_comment";
51  }
52  $this->addColumn($this->lng->txt($l), $c);
53  }
54 
55  if(!$this->getPrintMode())
56  {
57  $this->addColumn($this->lng->txt("actions"), "");
58  }
59 
60  $this->setExternalSorting(true);
61  $this->setExternalSegmentation(true);
62  $this->setEnableHeader(true);
63  $this->setFormAction($ilCtrl->getFormActionByClass(get_class($this)));
64  $this->setRowTemplate("tpl.user_objects_props_row.html", "Services/Tracking");
65  $this->setEnableTitle(true);
66  $this->setDefaultOrderField("title");
67  $this->setDefaultOrderDirection("asc");
68  $this->setShowTemplates(true);
69 
70  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
71 
72  $this->initFilter();
73 
74  $this->getItems();
75  }
76 
84  {
85  global $lng;
86 
87  // default fields
88  $cols = array();
89 
90  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
91  $tracking = new ilObjUserTracking();
92  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
93  {
94  $cols["first_access"] = array(
95  "txt" => $lng->txt("trac_first_access"),
96  "default" => true);
97  $cols["last_access"] = array(
98  "txt" => $lng->txt("trac_last_access"),
99  "default" => true);
100  }
101  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_READ_COUNT))
102  {
103  $cols["read_count"] = array(
104  "txt" => $lng->txt("trac_read_count"),
105  "default" => true);
106  }
107  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS))
108  {
109  $cols["spent_seconds"] = array(
110  "txt" => $lng->txt("trac_spent_seconds"),
111  "default" => true);
112  }
113 
114  $cols["percentage"] = array(
115  "txt" => $lng->txt("trac_percentage"),
116  "default" => true);
117  $cols["status"] = array(
118  "txt" => $lng->txt("trac_status"),
119  "default" => true);
120  $cols["mark"] = array(
121  "txt" => $lng->txt("trac_mark"),
122  "default" => true);
123  $cols["u_comment"] = array(
124  "txt" => $lng->txt("trac_comment"),
125  "default" => false);
126 
127  return $cols;
128  }
129 
133  function getItems()
134  {
135  global $lng, $tree;
136 
137  $this->determineOffsetAndOrder();
138 
139  $additional_fields = $this->getSelectedColumns();
140 
141  include_once("./Services/Tracking/classes/class.ilTrQuery.php");
142 
144  $this->user_id,
145  $this->obj_id,
146  $this->ref_id,
150  ilUtil::stripSlashes($this->getLimit()),
151  $this->filter,
152  $additional_fields,
153  $this->filter["view_mode"]);
154 
155  if (count($tr_data["set"]) == 0 && $this->getOffset() > 0)
156  {
157  $this->resetOffset();
159  $this->user_id,
160  $this->obj_id,
161  $this->ref_id,
165  ilUtil::stripSlashes($this->getLimit()),
166  $this->filter,
167  $additional_fields,
168  $this->filter["view_mode"]);
169  }
170 
171  $this->setMaxCount($tr_data["cnt"]);
172 
173  if($this->getOrderField() == "title")
174  {
175  // sort alphabetically, move parent object to 1st position
176  $set = array();
177  $parent = false;
178  foreach($tr_data["set"] as $idx => $row)
179  {
180  if($row['obj_id'] == $this->obj_id)
181  {
182  $parent = $row;
183  }
184  else if(isset($row["sort_title"]))
185  {
186  $set[strtolower($row["sort_title"])."__".$idx] = $row;
187  }
188  else
189  {
190  $set[strtolower($row["title"])."__".$idx] = $row;
191  }
192  }
193  unset($tr_data["set"]);
194  if($this->getOrderDirection() == "asc")
195  {
196  ksort($set);
197  }
198  else
199  {
200  krsort($set);
201  }
202  $set = array_values($set);
203  if($parent)
204  {
205  array_unshift($set, $parent);
206  }
207 
208  $this->setData($set);
209  }
210  else
211  {
212  $this->setData($tr_data["set"]);
213  }
214  }
215 
216 
222  function getObjectHierarchy($a_parent_id, array &$result)
223  {
224  include_once 'Services/Tracking/classes/class.ilLPCollectionCache.php';
225  foreach(ilLPCollectionCache::_getItems($a_parent_id) as $child_ref_id)
226  {
227  $child_id = ilObject::_lookupObjId($child_ref_id);
228  $result[] = $child_id;
229  $this->getObjectHierarchy($child_id, $result);
230  }
231  }
232 
233 
237  function initFilter()
238  {
239  global $lng, $rbacreview, $ilUser;
240 
241  // for scorm and objectives this filter does not make sense / is not implemented
242  include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
243  $mode = ilLPObjSettings::_lookupMode($this->obj_id);
244  if($mode == LP_MODE_SCORM || $mode == LP_MODE_OBJECTIVES)
245  {
246  return;
247  }
248 
249  include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
250  include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
251 
252  // show collection only/all
253  include_once("./Services/Form/classes/class.ilRadioGroupInputGUI.php");
254  include_once("./Services/Form/classes/class.ilRadioOption.php");
255  $ti = new ilRadioGroupInputGUI($lng->txt("trac_view_mode"), "view_mode");
256  $ti->addOption(new ilRadioOption($lng->txt("trac_view_mode_all"), ""));
257  $ti->addOption(new ilRadioOption($lng->txt("trac_view_mode_collection"), "coll"));
258  $this->addFilterItem($ti);
259  $ti->readFromSession();
260  $this->filter["view_mode"] = $ti->getValue();
261 
262  }
263 
267  protected function fillRow($data)
268  {
269  global $ilCtrl, $lng;
270 
271  if(!$this->isPercentageAvailable($data["obj_id"]))
272  {
273  $data["percentage"] = NULL;
274  }
275 
276  foreach ($this->getSelectedColumns() as $c)
277  {
278  $val = (trim($data[$c]) == "")
279  ? " "
280  : $data[$c];
281 
282  if ($data[$c] != "" || $c == "status")
283  {
284  switch ($c)
285  {
286  case "first_access":
288  break;
289 
290  case "last_access":
292  break;
293 
294  case "status":
295  include_once("./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php");
298  $val = ilUtil::img($path, $text);
299 
300  if($data["type"] != "lobj" && $data["type"] != "sco")
301  {
302  $timing = $this->showTimingsWarning($data["ref_id"], $this->user_id);
303  if($timing)
304  {
305  if($timing !== true)
306  {
307  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
308  }
309  else
310  {
311  $timing = "";
312  }
313  $this->tpl->setCurrentBlock('warning_img');
314  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.gif'));
315  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
316  $this->tpl->parseCurrentBlock();
317  }
318  }
319  break;
320 
321  case "spent_seconds":
322  include_once("./classes/class.ilFormat.php");
323  $val = ilFormat::_secondsToString($data[$c]);
324  break;
325 
326  case "percentage":
327  $val = $data[$c]."%";
328  break;
329 
330  }
331  }
332  if ($c == "mark" && in_array($this->type, array("lm", "dbk")))
333  {
334  $val = "-";
335  }
336  if ($c == "spent_seconds" && in_array($this->type, array("exc")))
337  {
338  $val = "-";
339  }
340  if ($c == "percentage" &&
341  (in_array(strtolower($this->status_class),
342  array("illpstatusmanual", "illpstatusscormpackage", "illpstatustestfinished")) ||
343  $this->type == "exc"))
344  {
345  $val = "-";
346  }
347 
348  $this->tpl->setCurrentBlock("user_field");
349  $this->tpl->setVariable("VAL_UF", $val);
350  $this->tpl->parseCurrentBlock();
351  }
352 
353  if($data["title"] == "")
354  {
355  $data["title"] = "--".$lng->txt("none")."--";
356  }
357  $this->tpl->setVariable("ICON", ilUtil::getTypeIconPath($data["type"], $data["obj_id"], "tiny"));
358  $this->tpl->setVariable("ICON_ALT", $lng->txt($data["type"]));
359 
360  if(in_array($data['type'], array('fold', 'grp')) && $data['obj_id'] != $this->obj_id)
361  {
362  if($data['type'] == 'fold')
363  {
364  $object_gui = 'ilobjfoldergui';
365  }
366  else
367  {
368  $object_gui = 'ilobjgroupgui';
369  }
370  $this->tpl->setCurrentBlock('title_linked');
371 
372  // link structure gets too complicated
373  if($_GET["baseClass"] != "ilPersonalDesktopGUI" && $_GET["baseClass"] != "ilAdministrationGUI")
374  {
375  $old = $ilCtrl->getParameterArrayByClass('illplistofobjectsgui');
376  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'ref_id', $data["ref_id"]);
377  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'details_id', $data["ref_id"]);
378  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'user_id', $this->user_id);
379  $url = $ilCtrl->getLinkTargetByClass(array('ilrepositorygui', $object_gui, 'illearningprogressgui', 'illplistofobjectsgui'), 'userdetails');
380  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'ref_id', $old["ref_id"]);
381  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'details_id', $old["details_id"]);
382  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'user_id', $old["user_id"]);
383  }
384  else
385  {
386  $url = "#";
387  }
388 
389  $this->tpl->setVariable("URL_TITLE", $url);
390  $this->tpl->setVariable("VAL_TITLE", $data["title"]);
391  $this->tpl->parseCurrentBlock();
392  }
393  else
394  {
395  $this->tpl->setCurrentBlock('title_plain');
396  $this->tpl->setVariable("VAL_TITLE", $data["title"]);
397  $this->tpl->parseCurrentBlock();
398  }
399 
400  if(!in_array($data["type"], array("sco", "lobj")) && !$this->getPrintMode())
401  {
402  $this->tpl->setCurrentBlock("item_command");
403  $ilCtrl->setParameterByClass("illplistofobjectsgui", "userdetails_id", $data["ref_id"]);
404  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", 'edituser'));
405  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('edit'));
406  $ilCtrl->setParameterByClass("illplistofobjectsgui", "userdetails_id", "");
407  $this->tpl->parseCurrentBlock();
408  }
409  }
410 
411  protected function fillHeaderExcel($worksheet, &$a_row)
412  {
413  $worksheet->write($a_row, 0, $this->lng->txt("type"));
414  $worksheet->write($a_row, 1, $this->lng->txt("title"));
415 
416  $labels = $this->getSelectableColumns();
417  $cnt = 2;
418  foreach ($this->getSelectedColumns() as $c)
419  {
420  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
421  $cnt++;
422  }
423  }
424 
425  protected function fillRowExcel($worksheet, &$a_row, $a_set)
426  {
427  $worksheet->write($a_row, 0, $this->lng->txt($a_set["type"]));
428  $worksheet->write($a_row, 1, $a_set["title"]);
429 
430  $cnt = 2;
431  foreach ($this->getSelectedColumns() as $c)
432  {
433  if($c != 'status')
434  {
435  $val = $this->parseValue($c, $a_set[$c], "user");
436  }
437  else
438  {
439  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
440  }
441  $worksheet->write($a_row, $cnt, $val);
442  $cnt++;
443  }
444  }
445 
446  protected function fillHeaderCSV($a_csv)
447  {
448  $a_csv->addColumn($this->lng->txt("type"));
449  $a_csv->addColumn($this->lng->txt("title"));
450 
451  $labels = $this->getSelectableColumns();
452  foreach ($this->getSelectedColumns() as $c)
453  {
454  $a_csv->addColumn($labels[$c]["txt"]);
455  }
456 
457  $a_csv->addRow();
458  }
459 
460  protected function fillRowCSV($a_csv, $a_set)
461  {
462  $a_csv->addColumn($this->lng->txt($a_set["type"]));
463  $a_csv->addColumn($a_set["title"]);
464 
465  foreach ($this->getSelectedColumns() as $c)
466  {
467  if($c != 'status')
468  {
469  $val = $this->parseValue($c, $a_set[$c], "user");
470  }
471  else
472  {
473  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
474  }
475  $a_csv->addColumn($val);
476  }
477 
478  $a_csv->addRow();
479  }
480 }
481 ?>