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