ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTrObjectUsersPropsTableGUI.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 
24 {
25  protected $user_fields; // array
26  protected $filter; // array
27  protected $in_course; // array
28 
32  function __construct($a_parent_obj, $a_parent_cmd, $a_obj_id, $a_ref_id, $a_print_view = false)
33  {
34  global $ilCtrl, $lng, $ilAccess, $lng, $rbacsystem, $tree;
35 
36  $this->setId("troup");
37  $this->obj_id = $a_obj_id;
38  $this->ref_id = $a_ref_id;
39  $this->type = ilObject::_lookupType($a_obj_id);
40 
41  $this->in_course = (bool)$tree->checkForParentType($this->ref_id, "crs");
42 
43  parent::__construct($a_parent_obj, $a_parent_cmd);
44 
45  $this->parseTitle($a_obj_id, "trac_participants");
46 
47  if($a_print_view)
48  {
49  $this->setPrintMode(true);
50  }
51 
52  $labels = $this->getSelectableColumns();
53  foreach ($this->getSelectedColumns() as $c)
54  {
55  $first = $c;
56 
57  // list cannot be sorted by udf fields (separate query)
58  $sort_id = (substr($c, 0, 4) == "udf_") ? "" : $c;
59 
60  $this->addColumn($labels[$c]["txt"], $sort_id);
61  }
62 
63  if(!$this->getPrintMode())
64  {
65  $this->addColumn($this->lng->txt("actions"), "");
66  }
67 
68  $this->setExternalSorting(true);
69  $this->setExternalSegmentation(true);
70  $this->setEnableHeader(true);
71  $this->setFormAction($ilCtrl->getFormActionByClass(get_class($this)));
72  $this->setRowTemplate("tpl.object_users_props_row.html", "Services/Tracking");
73  $this->setEnableTitle(true);
74  $this->setShowTemplates(true);
75  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
76 
77  if($first)
78  {
79  $this->setDefaultOrderField($first);
80  $this->setDefaultOrderDirection("asc");
81  }
82 
83  $this->initFilter();
84 
85  $this->getItems();
86  }
87 
95  {
96  global $lng, $ilSetting;
97 
98  if($this->selectable_columns)
99  {
101  }
102 
103  $anonymized_object = false;
104  include_once './Modules/Test/classes/class.ilObjTest.php';
105  if(ilObjTest::_lookupAnonymity($this->obj_id))
106  {
107  $anonymized_object = true;
108  }
109 
110  include_once("./Services/User/classes/class.ilUserProfile.php");
111  $up = new ilUserProfile();
112  $up->skipGroup("preferences");
113  $up->skipGroup("settings");
114  $ufs = $up->getStandardFields();
115 
116  // default fields
117  $cols = array();
118  $cols["login"] = array(
119  "txt" => $lng->txt("login"),
120  "default" => true);
121 
122  if(!$anonymized_object)
123  {
124  $cols["firstname"] = array(
125  "txt" => $lng->txt("firstname"),
126  "default" => true);
127  $cols["lastname"] = array(
128  "txt" => $lng->txt("lastname"),
129  "default" => true);
130  }
131 
132  // show only if extended data was activated in lp settings
133  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
134  $tracking = new ilObjUserTracking();
135  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
136  {
137  $cols["first_access"] = array(
138  "txt" => $lng->txt("trac_first_access"),
139  "default" => true);
140  $cols["last_access"] = array(
141  "txt" => $lng->txt("trac_last_access"),
142  "default" => true);
143  }
144  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_READ_COUNT))
145  {
146  $cols["read_count"] = array(
147  "txt" => $lng->txt("trac_read_count"),
148  "default" => true);
149  }
150  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS))
151  {
152  $cols["spent_seconds"] = array(
153  "txt" => $lng->txt("trac_spent_seconds"),
154  "default" => true);
155  }
156 
157  if($this->isPercentageAvailable($this->obj_id))
158  {
159  $cols["percentage"] = array(
160  "txt" => $lng->txt("trac_percentage"),
161  "default" => true);
162  }
163 
164  // do not show status if learning progress is deactivated
165  $mode = ilLPObjSettings::_lookupMode($this->obj_id);
166  if($mode != LP_MODE_DEACTIVATED && $mode != LP_MODE_LP_MODE_UNDEFINED)
167  {
168  $cols["status"] = array(
169  "txt" => $lng->txt("trac_status"),
170  "default" => true);
171  }
172 
173  if($this->type != "lm")
174  {
175  $cols["mark"] = array(
176  "txt" => $lng->txt("trac_mark"),
177  "default" => true);
178  }
179 
180  $cols["u_comment"] = array(
181  "txt" => $lng->txt("trac_comment"),
182  "default" => false);
183 
184  $cols["create_date"] = array(
185  "txt" => $lng->txt("create_date"),
186  "default" => false);
187  $cols["language"] = array(
188  "txt" => $lng->txt("language"),
189  "default" => false);
190 
191  // add user data only if object is [part of] course
192  if($this->in_course && !$anonymized_object)
193  {
194  $this->user_fields = array();
195 
196  // other user profile fields
197  foreach ($ufs as $f => $fd)
198  {
199  if (!isset($cols[$f]) && $f != "username" && !$fd["lists_hide"] && ($fd["course_export_fix_value"] || $ilSetting->get("usr_settings_course_export_".$f)))
200  {
201  $cols[$f] = array(
202  "txt" => $lng->txt($f),
203  "default" => false);
204 
205  $this->user_fields[] = $f;
206  }
207  }
208 
209  // additional defined user data fields
210  include_once './Services/User/classes/class.ilUserDefinedFields.php';
211  $user_defined_fields = ilUserDefinedFields::_getInstance();
212  foreach($user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
213  {
214  if($definition["field_type"] != UDF_TYPE_WYSIWYG && $definition["course_export"])
215  {
216  $f = "udf_".$definition["field_id"];
217  $cols[$f] = array(
218  "txt" => $definition["field_name"],
219  "default" => false);
220 
221  $this->user_fields[] = $f;
222  }
223  }
224  }
225 
226  $this->selectable_columns = $cols;
227 
228  return $cols;
229  }
230 
234  function getItems()
235  {
236  global $lng, $tree;
237 
238  $this->determineOffsetAndOrder();
239 
240  include_once("./Services/Tracking/classes/class.ilTrQuery.php");
241 
242  $additional_fields = $this->getSelectedColumns();
243 
244  // only if object is [part of] course
245  $check_agreement = false;
246  if($this->in_course)
247  {
248  // privacy (if course agreement is activated)
249  include_once "Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
250  $privacy = ilPrivacySettings::_getInstance();
251  if($privacy->courseConfirmationRequired())
252  {
253  $check_agreement = true;
254  }
255  }
256 
258  $this->ref_id,
262  ilUtil::stripSlashes($this->getLimit()),
263  $this->getCurrentFilter(),
264  $additional_fields,
265  $check_agreement,
266  $this->user_fields
267  );
268 
269  if (count($tr_data["set"]) == 0 && $this->getOffset() > 0)
270  {
271  $this->resetOffset();
273  $this->ref_id,
277  ilUtil::stripSlashes($this->getLimit()),
278  $this->getCurrentFilter(),
279  $additional_fields,
280  $check_agreement,
281  $this->user_fields
282  );
283  }
284 
285  $this->setMaxCount($tr_data["cnt"]);
286  $this->setData($tr_data["set"]);
287  }
288 
289 
293  function initFilter()
294  {
295  global $lng;
296 
297  foreach($this->getSelectableColumns() as $column => $meta)
298  {
299  // no udf!
300  switch($column)
301  {
302  case "firstname":
303  case "lastname":
304  case "mark":
305  case "u_comment":
306  case "institution":
307  case "department":
308  case "title":
309  case "street":
310  case "zipcode":
311  case "city":
312  case "country":
313  case "email":
314  case "matriculation":
315  case "login":
316  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_TEXT, true, $meta["txt"]);
317  $this->filter[$column] = $item->getValue();
318  break;
319 
320  case "first_access":
321  case "last_access":
322  case "create_date":
323  case "birthday":
324  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_DATE_RANGE, true, $meta["txt"]);
325  $this->filter[$column] = $item->getDate();
326  break;
327 
328  case "read_count":
329  case "percentage":
330  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_NUMBER_RANGE, true, $meta["txt"]);
331  $this->filter[$column] = $item->getValue();
332  break;
333 
334  case "gender":
335  $item = $this->addFilterItemByMetaType("gender", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
336  $item->setOptions(array("" => $lng->txt("trac_all"), "m" => $lng->txt("gender_m"), "f" => $lng->txt("gender_f")));
337  $this->filter["gender"] = $item->getValue();
338  break;
339 
340  case "sel_country":
341  $item = $this->addFilterItemByMetaType("sel_country", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
342 
343  $options = array();
344  include_once("./Services/Utilities/classes/class.ilCountry.php");
345  foreach (ilCountry::getCountryCodes() as $c)
346  {
347  $options[$c] = $lng->txt("meta_c_".$c);
348  }
349  asort($options);
350  $item->setOptions(array("" => $lng->txt("trac_all"))+$options);
351 
352  $this->filter["sel_country"] = $item->getValue();
353  break;
354 
355  case "status":
356  include_once "Services/Tracking/classes/class.ilLPStatus.php";
357  $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
358  $item->setOptions(array("" => $lng->txt("trac_all"),
362  LP_STATUS_FAILED_NUM+1 => $lng->txt(LP_STATUS_FAILED)));
363  $this->filter["status"] = $item->getValue();
364  if($this->filter["status"])
365  {
366  $this->filter["status"]--;
367  }
368  break;
369 
370  case "language":
371  $item = $this->addFilterItemByMetaType("language", ilTable2GUI::FILTER_LANGUAGE, true);
372  $this->filter["language"] = $item->getValue();
373  break;
374 
375  case "spent_seconds":
376  $item = $this->addFilterItemByMetaType("spent_seconds", ilTable2GUI::FILTER_DURATION_RANGE, true, $meta["txt"]);
377  $this->filter["spent_seconds"]["from"] = $item->getCombinationItem("from")->getValueInSeconds();
378  $this->filter["spent_seconds"]["to"] = $item->getCombinationItem("to")->getValueInSeconds();
379  break;
380  }
381  }
382  }
383 
387  protected function fillRow($data)
388  {
389  global $ilCtrl, $lng;
390 
391  foreach ($this->getSelectedColumns() as $c)
392  {
393  if($c == 'status' && $data[$c] != LP_STATUS_COMPLETED_NUM)
394  {
395  $timing = $this->showTimingsWarning($this->ref_id, $data["usr_id"]);
396  if($timing)
397  {
398  if($timing !== true)
399  {
400  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
401  }
402  else
403  {
404  $timing = "";
405  }
406  $this->tpl->setCurrentBlock('warning_img');
407  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.gif'));
408  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
409  $this->tpl->parseCurrentBlock();
410  }
411  }
412 
413  $this->tpl->setCurrentBlock("user_field");
414  $val = $this->parseValue($c, $data[$c], "user");
415  $this->tpl->setVariable("VAL_UF", $val);
416  $this->tpl->parseCurrentBlock();
417  }
418 
419  $ilCtrl->setParameterByClass("illplistofobjectsgui", "user_id", $data["usr_id"]);
420 
421  if(!$this->getPrintMode())
422  {
423  if(in_array($this->type, array("crs", "grp", "cat", "fold")))
424  {
425  $this->tpl->setCurrentBlock("item_command");
426  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", "userdetails"));
427  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('details'));
428  $this->tpl->parseCurrentBlock();
429  }
430 
431  $this->tpl->setCurrentBlock("item_command");
432  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", "edituser"));
433  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('edit'));
434  $this->tpl->parseCurrentBlock();
435  }
436 
437  $ilCtrl->setParameterByClass("illplistofobjectsgui", 'user_id', '');
438  }
439 
440  protected function fillHeaderExcel($worksheet, &$a_row)
441  {
442  $labels = $this->getSelectableColumns();
443  $cnt = 0;
444  foreach ($this->getSelectedColumns() as $c)
445  {
446  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
447  $cnt++;
448  }
449  }
450 
451  protected function fillRowExcel($worksheet, &$a_row, $a_set)
452  {
453  $cnt = 0;
454  foreach ($this->getSelectedColumns() as $c)
455  {
456  if($c != 'status')
457  {
458  $val = $this->parseValue($c, $a_set[$c], "user");
459  }
460  else
461  {
462  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
463  }
464  $worksheet->write($a_row, $cnt, $val);
465  $cnt++;
466  }
467  }
468 
469  protected function fillHeaderCSV($a_csv)
470  {
471  $labels = $this->getSelectableColumns();
472  foreach ($this->getSelectedColumns() as $c)
473  {
474  $a_csv->addColumn($labels[$c]["txt"]);
475  }
476 
477  $a_csv->addRow();
478  }
479 
480  protected function fillRowCSV($a_csv, $a_set)
481  {
482  foreach ($this->getSelectedColumns() as $c)
483  {
484  if($c != 'status')
485  {
486  $val = $this->parseValue($c, $a_set[$c], "user");
487  }
488  else
489  {
490  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
491  }
492  $a_csv->addColumn($val);
493  }
494 
495  $a_csv->addRow();
496  }
497 }
498 ?>