ILIAS  Release_4_4_x_branch Revision 61816
 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/Object/classes/class.ilObjectLP.php";
225  $olp = ilObjectLP::getInstance($a_parent_id);
226  $collection = $olp->getCollectionInstance();
227  if($collection)
228  {
229  foreach($collection->getItems() as $child_ref_id)
230  {
231  $child_id = ilObject::_lookupObjId($child_ref_id);
232  $result[] = $child_id;
233  $this->getObjectHierarchy($child_id, $result);
234  }
235  }
236  }
237 
238 
242  function initFilter()
243  {
244  global $lng;
245 
246  // for scorm and objectives this filter does not make sense / is not implemented
247  include_once './Services/Object/classes/class.ilObjectLP.php';
248  $olp = ilObjectLP::getInstance($this->obj_id);
249  $collection = $olp->getCollectionInstance();
250  if($collection instanceof ilLPCollectionOfRepositoryObjects)
251  {
252  include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
253  include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
254 
255  // show collection only/all
256  include_once("./Services/Form/classes/class.ilRadioGroupInputGUI.php");
257  include_once("./Services/Form/classes/class.ilRadioOption.php");
258  $ti = new ilRadioGroupInputGUI($lng->txt("trac_view_mode"), "view_mode");
259  $ti->addOption(new ilRadioOption($lng->txt("trac_view_mode_all"), ""));
260  $ti->addOption(new ilRadioOption($lng->txt("trac_view_mode_collection"), "coll"));
261  $this->addFilterItem($ti);
262  $ti->readFromSession();
263  $this->filter["view_mode"] = $ti->getValue();
264  }
265  }
266 
270  protected function fillRow($data)
271  {
272  global $ilCtrl, $lng;
273 
274  if(!$this->isPercentageAvailable($data["obj_id"]))
275  {
276  $data["percentage"] = NULL;
277  }
278 
279  foreach ($this->getSelectedColumns() as $c)
280  {
281  $val = (trim($data[$c]) == "")
282  ? " "
283  : $data[$c];
284 
285  if ($data[$c] != "" || $c == "status")
286  {
287  switch ($c)
288  {
289  case "first_access":
291  break;
292 
293  case "last_access":
295  break;
296 
297  case "status":
298  include_once("./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php");
301  $val = ilUtil::img($path, $text);
302 
303  if($data["type"] != "lobj" && $data["type"] != "sco")
304  {
305  $timing = $this->showTimingsWarning($data["ref_id"], $this->user_id);
306  if($timing)
307  {
308  if($timing !== true)
309  {
310  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
311  }
312  else
313  {
314  $timing = "";
315  }
316  $this->tpl->setCurrentBlock('warning_img');
317  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.png'));
318  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
319  $this->tpl->parseCurrentBlock();
320  }
321  }
322  break;
323 
324  case "spent_seconds":
325  include_once("./Services/Utilities/classes/class.ilFormat.php");
326  $val = ilFormat::_secondsToString($data[$c]);
327  break;
328 
329  case "percentage":
330  $val = $data[$c]."%";
331  break;
332 
333  }
334  }
335  if ($c == "mark" && in_array($this->type, array("lm", "dbk")))
336  {
337  $val = "-";
338  }
339  if ($c == "spent_seconds" && in_array($this->type, array("exc")))
340  {
341  $val = "-";
342  }
343  if ($c == "percentage" &&
344  (in_array(strtolower($this->status_class),
345  array("illpstatusmanual", "illpstatusscormpackage", "illpstatustestfinished")) ||
346  $this->type == "exc"))
347  {
348  $val = "-";
349  }
350 
351  $this->tpl->setCurrentBlock("user_field");
352  $this->tpl->setVariable("VAL_UF", $val);
353  $this->tpl->parseCurrentBlock();
354  }
355 
356  if($data["title"] == "")
357  {
358  $data["title"] = "--".$lng->txt("none")."--";
359  }
360  $this->tpl->setVariable("ICON",ilObject::_getIcon("", "tiny", $data["type"]));
361  $this->tpl->setVariable("ICON_ALT", $lng->txt($data["type"]));
362 
363  if(in_array($data['type'], array('fold', 'grp')) && $data['obj_id'] != $this->obj_id)
364  {
365  if($data['type'] == 'fold')
366  {
367  $object_gui = 'ilobjfoldergui';
368  }
369  else
370  {
371  $object_gui = 'ilobjgroupgui';
372  }
373  $this->tpl->setCurrentBlock('title_linked');
374 
375  // link structure gets too complicated
376  if($_GET["baseClass"] != "ilPersonalDesktopGUI" && $_GET["baseClass"] != "ilAdministrationGUI")
377  {
378  $old = $ilCtrl->getParameterArrayByClass('illplistofobjectsgui');
379  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'ref_id', $data["ref_id"]);
380  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'details_id', $data["ref_id"]);
381  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'user_id', $this->user_id);
382  $url = $ilCtrl->getLinkTargetByClass(array('ilrepositorygui', $object_gui, 'illearningprogressgui', 'illplistofobjectsgui'), 'userdetails');
383  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'ref_id', $old["ref_id"]);
384  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'details_id', $old["details_id"]);
385  $ilCtrl->setParameterByClass('illplistofobjectsgui', 'user_id', $old["user_id"]);
386  }
387  else
388  {
389  $url = "#";
390  }
391 
392  $this->tpl->setVariable("URL_TITLE", $url);
393  $this->tpl->setVariable("VAL_TITLE", $data["title"]);
394  $this->tpl->parseCurrentBlock();
395  }
396  else
397  {
398  $this->tpl->setCurrentBlock('title_plain');
399  $this->tpl->setVariable("VAL_TITLE", $data["title"]);
400  $this->tpl->parseCurrentBlock();
401  }
402 
403  if(!in_array($data["type"], array("sco", "lobj")) && !$this->getPrintMode())
404  {
405  $this->tpl->setCurrentBlock("item_command");
406  $ilCtrl->setParameterByClass("illplistofobjectsgui", "userdetails_id", $data["ref_id"]);
407  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", 'edituser'));
408  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('edit'));
409  $ilCtrl->setParameterByClass("illplistofobjectsgui", "userdetails_id", "");
410  $this->tpl->parseCurrentBlock();
411  }
412  }
413 
414  protected function fillHeaderExcel($worksheet, &$a_row)
415  {
416  $worksheet->write($a_row, 0, $this->lng->txt("type"));
417  $worksheet->write($a_row, 1, $this->lng->txt("title"));
418 
419  $labels = $this->getSelectableColumns();
420  $cnt = 2;
421  foreach ($this->getSelectedColumns() as $c)
422  {
423  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
424  $cnt++;
425  }
426  }
427 
428  protected function fillRowExcel($worksheet, &$a_row, $a_set)
429  {
430  $worksheet->write($a_row, 0, $this->lng->txt($a_set["type"]));
431  $worksheet->write($a_row, 1, $a_set["title"]);
432 
433  $cnt = 2;
434  foreach ($this->getSelectedColumns() as $c)
435  {
436  if($c != 'status')
437  {
438  $val = $this->parseValue($c, $a_set[$c], "user");
439  }
440  else
441  {
442  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
443  }
444  $worksheet->write($a_row, $cnt, $val);
445  $cnt++;
446  }
447  }
448 
449  protected function fillHeaderCSV($a_csv)
450  {
451  $a_csv->addColumn($this->lng->txt("type"));
452  $a_csv->addColumn($this->lng->txt("title"));
453 
454  $labels = $this->getSelectableColumns();
455  foreach ($this->getSelectedColumns() as $c)
456  {
457  $a_csv->addColumn($labels[$c]["txt"]);
458  }
459 
460  $a_csv->addRow();
461  }
462 
463  protected function fillRowCSV($a_csv, $a_set)
464  {
465  $a_csv->addColumn($this->lng->txt($a_set["type"]));
466  $a_csv->addColumn($a_set["title"]);
467 
468  foreach ($this->getSelectedColumns() as $c)
469  {
470  if($c != 'status')
471  {
472  $val = $this->parseValue($c, $a_set[$c], "user");
473  }
474  else
475  {
476  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
477  }
478  $a_csv->addColumn($val);
479  }
480 
481  $a_csv->addRow();
482  }
483 }
484 ?>