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