ILIAS  Release_4_2_x_branch Revision 61807
 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  $cols['status_changed'] = array(
177  'txt' => $lng->txt('trac_status_changed'),
178  'default' => false);
179  }
180 
181  if($this->type != "lm")
182  {
183  $cols["mark"] = array(
184  "txt" => $lng->txt("trac_mark"),
185  "default" => true);
186  }
187 
188  $cols["u_comment"] = array(
189  "txt" => $lng->txt("trac_comment"),
190  "default" => false);
191 
192  $cols["create_date"] = array(
193  "txt" => $lng->txt("create_date"),
194  "default" => false);
195  $cols["language"] = array(
196  "txt" => $lng->txt("language"),
197  "default" => false);
198 
199  // add user data only if object is [part of] course
200  if($this->in_course && !$anonymized_object)
201  {
202  $this->user_fields = array();
203 
204  // other user profile fields
205  foreach ($ufs as $f => $fd)
206  {
207  if (!isset($cols[$f]) && $f != "username" && !$fd["lists_hide"] && ($fd["course_export_fix_value"] || $ilSetting->get("usr_settings_course_export_".$f)))
208  {
209  $cols[$f] = array(
210  "txt" => $lng->txt($f),
211  "default" => false);
212 
213  $this->user_fields[] = $f;
214  }
215  }
216 
217  // additional defined user data fields
218  include_once './Services/User/classes/class.ilUserDefinedFields.php';
219  $user_defined_fields = ilUserDefinedFields::_getInstance();
220  foreach($user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
221  {
222  if($definition["field_type"] != UDF_TYPE_WYSIWYG && $definition["course_export"])
223  {
224  $f = "udf_".$definition["field_id"];
225  $cols[$f] = array(
226  "txt" => $definition["field_name"],
227  "default" => false);
228 
229  $this->user_fields[] = $f;
230  }
231  }
232  }
233 
234  $this->selectable_columns = $cols;
235 
236  return $cols;
237  }
238 
242  function getItems()
243  {
244  global $lng, $tree;
245 
246  $this->determineOffsetAndOrder();
247 
248  include_once("./Services/Tracking/classes/class.ilTrQuery.php");
249 
250  $additional_fields = $this->getSelectedColumns();
251 
252  // only if object is [part of] course
253  $check_agreement = false;
254  if($this->in_course)
255  {
256  // privacy (if course agreement is activated)
257  include_once "Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
258  $privacy = ilPrivacySettings::_getInstance();
259  if($privacy->courseConfirmationRequired())
260  {
261  $check_agreement = $this->in_course;
262  }
263  }
264 
266  $this->ref_id,
270  ilUtil::stripSlashes($this->getLimit()),
271  $this->getCurrentFilter(),
272  $additional_fields,
273  $check_agreement,
274  $this->user_fields
275  );
276 
277  if (count($tr_data["set"]) == 0 && $this->getOffset() > 0)
278  {
279  $this->resetOffset();
281  $this->ref_id,
285  ilUtil::stripSlashes($this->getLimit()),
286  $this->getCurrentFilter(),
287  $additional_fields,
288  $check_agreement,
289  $this->user_fields
290  );
291  }
292 
293  $this->setMaxCount($tr_data["cnt"]);
294  $this->setData($tr_data["set"]);
295  }
296 
297 
301  function initFilter()
302  {
303  global $lng;
304 
305  foreach($this->getSelectableColumns() as $column => $meta)
306  {
307  // no udf!
308  switch($column)
309  {
310  case "firstname":
311  case "lastname":
312  case "mark":
313  case "u_comment":
314  case "institution":
315  case "department":
316  case "title":
317  case "street":
318  case "zipcode":
319  case "city":
320  case "country":
321  case "email":
322  case "matriculation":
323  case "login":
324  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_TEXT, true, $meta["txt"]);
325  $this->filter[$column] = $item->getValue();
326  break;
327 
328  case "first_access":
329  case "last_access":
330  case "create_date":
331  case "birthday":
332  case 'status_changed':
333  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_DATE_RANGE, true, $meta["txt"]);
334  $this->filter[$column] = $item->getDate();
335  break;
336 
337  case "read_count":
338  case "percentage":
339  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_NUMBER_RANGE, true, $meta["txt"]);
340  $this->filter[$column] = $item->getValue();
341  break;
342 
343  case "gender":
344  $item = $this->addFilterItemByMetaType("gender", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
345  $item->setOptions(array("" => $lng->txt("trac_all"), "m" => $lng->txt("gender_m"), "f" => $lng->txt("gender_f")));
346  $this->filter["gender"] = $item->getValue();
347  break;
348 
349  case "sel_country":
350  $item = $this->addFilterItemByMetaType("sel_country", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
351 
352  $options = array();
353  include_once("./Services/Utilities/classes/class.ilCountry.php");
354  foreach (ilCountry::getCountryCodes() as $c)
355  {
356  $options[$c] = $lng->txt("meta_c_".$c);
357  }
358  asort($options);
359  $item->setOptions(array("" => $lng->txt("trac_all"))+$options);
360 
361  $this->filter["sel_country"] = $item->getValue();
362  break;
363 
364  case "status":
365  include_once "Services/Tracking/classes/class.ilLPStatus.php";
366  $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
367  $item->setOptions(array("" => $lng->txt("trac_all"),
371  LP_STATUS_FAILED_NUM+1 => $lng->txt(LP_STATUS_FAILED)));
372  $this->filter["status"] = $item->getValue();
373  if($this->filter["status"])
374  {
375  $this->filter["status"]--;
376  }
377  break;
378 
379  case "language":
380  $item = $this->addFilterItemByMetaType("language", ilTable2GUI::FILTER_LANGUAGE, true);
381  $this->filter["language"] = $item->getValue();
382  break;
383 
384  case "spent_seconds":
385  $item = $this->addFilterItemByMetaType("spent_seconds", ilTable2GUI::FILTER_DURATION_RANGE, true, $meta["txt"]);
386  $this->filter["spent_seconds"]["from"] = $item->getCombinationItem("from")->getValueInSeconds();
387  $this->filter["spent_seconds"]["to"] = $item->getCombinationItem("to")->getValueInSeconds();
388  break;
389  }
390  }
391  }
392 
396  protected function fillRow($data)
397  {
398  global $ilCtrl, $lng;
399 
400  foreach ($this->getSelectedColumns() as $c)
401  {
402  if($c == 'status' && $data[$c] != LP_STATUS_COMPLETED_NUM)
403  {
404  $timing = $this->showTimingsWarning($this->ref_id, $data["usr_id"]);
405  if($timing)
406  {
407  if($timing !== true)
408  {
409  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
410  }
411  else
412  {
413  $timing = "";
414  }
415  $this->tpl->setCurrentBlock('warning_img');
416  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.gif'));
417  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
418  $this->tpl->parseCurrentBlock();
419  }
420  }
421 
422  // #7694
423  if($c == 'login' && !$data["active"])
424  {
425  $this->tpl->setCurrentBlock('inactive_bl');
426  $this->tpl->setVariable('TXT_INACTIVE', $lng->txt("inactive"));
427  $this->tpl->parseCurrentBlock();
428  }
429 
430  $this->tpl->setCurrentBlock("user_field");
431  $val = $this->parseValue($c, $data[$c], "user");
432  $this->tpl->setVariable("VAL_UF", $val);
433  $this->tpl->parseCurrentBlock();
434  }
435 
436  $ilCtrl->setParameterByClass("illplistofobjectsgui", "user_id", $data["usr_id"]);
437 
438  if(!$this->getPrintMode())
439  {
440  if(in_array($this->type, array("crs", "grp", "cat", "fold")))
441  {
442  $this->tpl->setCurrentBlock("item_command");
443  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", "userdetails"));
444  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('details'));
445  $this->tpl->parseCurrentBlock();
446  }
447 
448  $this->tpl->setCurrentBlock("item_command");
449  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", "edituser"));
450  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('edit'));
451  $this->tpl->parseCurrentBlock();
452  }
453 
454  $ilCtrl->setParameterByClass("illplistofobjectsgui", 'user_id', '');
455  }
456 
457  protected function fillHeaderExcel($worksheet, &$a_row)
458  {
459  $labels = $this->getSelectableColumns();
460  $cnt = 0;
461  foreach ($this->getSelectedColumns() as $c)
462  {
463  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
464  $cnt++;
465  }
466  }
467 
468  protected function fillRowExcel($worksheet, &$a_row, $a_set)
469  {
470  $cnt = 0;
471  foreach ($this->getSelectedColumns() as $c)
472  {
473  if($c != 'status')
474  {
475  $val = $this->parseValue($c, $a_set[$c], "user");
476  }
477  else
478  {
479  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
480  }
481  $worksheet->write($a_row, $cnt, $val);
482  $cnt++;
483  }
484  }
485 
486  protected function fillHeaderCSV($a_csv)
487  {
488  $labels = $this->getSelectableColumns();
489  foreach ($this->getSelectedColumns() as $c)
490  {
491  $a_csv->addColumn($labels[$c]["txt"]);
492  }
493 
494  $a_csv->addRow();
495  }
496 
497  protected function fillRowCSV($a_csv, $a_set)
498  {
499  foreach ($this->getSelectedColumns() as $c)
500  {
501  if($c != 'status')
502  {
503  $val = $this->parseValue($c, $a_set[$c], "user");
504  }
505  else
506  {
507  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
508  }
509  $a_csv->addColumn($val);
510  }
511 
512  $a_csv->addRow();
513  }
514 }
515 ?>