ILIAS  Release_4_4_x_branch Revision 61816
 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, $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_group = $tree->checkForParentType($this->ref_id, "grp");
43  if($this->in_group)
44  {
45  $this->in_group = ilObject::_lookupObjId($this->in_group);
46  }
47  else
48  {
49  $this->in_course = $tree->checkForParentType($this->ref_id, "crs");
50  if($this->in_course)
51  {
52  $this->in_course = ilObject::_lookupObjId($this->in_course);
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  if($this->selectable_columns)
111  {
113  }
114 
115  $cols = $this->getSelectableUserColumns($this->in_course, $this->in_group);
116  $this->user_fields = $cols[1];
117  $this->selectable_columns = $cols[0];
118 
120  }
121 
125  function getItems()
126  {
127  global $lng;
128 
129  $this->determineOffsetAndOrder();
130 
131  include_once("./Services/Tracking/classes/class.ilTrQuery.php");
132 
133  $additional_fields = $this->getSelectedColumns();
134 
135  // only if object is [part of] course/group
136  $check_agreement = false;
137  if($this->in_course)
138  {
139  // privacy (if course agreement is activated)
140  include_once "Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
141  $privacy = ilPrivacySettings::_getInstance();
142  if($privacy->courseConfirmationRequired())
143  {
144  $check_agreement = $this->in_course;
145  }
146  }
147  else if($this->in_group)
148  {
149  // privacy (if group agreement is activated)
150  include_once "Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
151  $privacy = ilPrivacySettings::_getInstance();
152  if($privacy->groupConfirmationRequired())
153  {
154  $check_agreement = $this->in_group;
155  }
156  }
157 
159  $this->ref_id,
163  ilUtil::stripSlashes($this->getLimit()),
164  $this->getCurrentFilter(),
165  $additional_fields,
166  $check_agreement,
167  $this->user_fields
168  );
169 
170  if (count($tr_data["set"]) == 0 && $this->getOffset() > 0)
171  {
172  $this->resetOffset();
174  $this->ref_id,
178  ilUtil::stripSlashes($this->getLimit()),
179  $this->getCurrentFilter(),
180  $additional_fields,
181  $check_agreement,
182  $this->user_fields
183  );
184  }
185 
186  $this->setMaxCount($tr_data["cnt"]);
187  $this->setData($tr_data["set"]);
188  }
189 
190 
194  function initFilter()
195  {
196  global $lng;
197 
198  foreach($this->getSelectableColumns() as $column => $meta)
199  {
200  // no udf!
201  switch($column)
202  {
203  case "firstname":
204  case "lastname":
205  case "mark":
206  case "u_comment":
207  case "institution":
208  case "department":
209  case "title":
210  case "street":
211  case "zipcode":
212  case "city":
213  case "country":
214  case "email":
215  case "matriculation":
216  case "login":
217  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_TEXT, true, $meta["txt"]);
218  $this->filter[$column] = $item->getValue();
219  break;
220 
221  case "first_access":
222  case "last_access":
223  case "create_date":
224  case 'status_changed':
225  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_DATETIME_RANGE, true, $meta["txt"]);
226  $this->filter[$column] = $item->getDate();
227  break;
228 
229  case "birthday":
230  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_DATE_RANGE, true, $meta["txt"]);
231  $this->filter[$column] = $item->getDate();
232  break;
233 
234  case "read_count":
235  case "percentage":
236  $item = $this->addFilterItemByMetaType($column, ilTable2GUI::FILTER_NUMBER_RANGE, true, $meta["txt"]);
237  $this->filter[$column] = $item->getValue();
238  break;
239 
240  case "gender":
241  $item = $this->addFilterItemByMetaType("gender", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
242  $item->setOptions(array("" => $lng->txt("trac_all"), "m" => $lng->txt("gender_m"), "f" => $lng->txt("gender_f")));
243  $this->filter["gender"] = $item->getValue();
244  break;
245 
246  case "sel_country":
247  $item = $this->addFilterItemByMetaType("sel_country", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
248 
249  $options = array();
250  include_once("./Services/Utilities/classes/class.ilCountry.php");
251  foreach (ilCountry::getCountryCodes() as $c)
252  {
253  $options[$c] = $lng->txt("meta_c_".$c);
254  }
255  asort($options);
256  $item->setOptions(array("" => $lng->txt("trac_all"))+$options);
257 
258  $this->filter["sel_country"] = $item->getValue();
259  break;
260 
261  case "status":
262  include_once "Services/Tracking/classes/class.ilLPStatus.php";
263  $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT, true, $meta["txt"]);
264  $item->setOptions(array("" => $lng->txt("trac_all"),
269  $this->filter["status"] = $item->getValue();
270  if($this->filter["status"])
271  {
272  $this->filter["status"]--;
273  }
274  break;
275 
276  case "language":
277  $item = $this->addFilterItemByMetaType("language", ilTable2GUI::FILTER_LANGUAGE, true);
278  $this->filter["language"] = $item->getValue();
279  break;
280 
281  case "spent_seconds":
282  $item = $this->addFilterItemByMetaType("spent_seconds", ilTable2GUI::FILTER_DURATION_RANGE, true, $meta["txt"]);
283  $this->filter["spent_seconds"]["from"] = $item->getCombinationItem("from")->getValueInSeconds();
284  $this->filter["spent_seconds"]["to"] = $item->getCombinationItem("to")->getValueInSeconds();
285  break;
286  }
287  }
288  }
289 
293  protected function fillRow($data)
294  {
295  global $ilCtrl, $lng;
296 
297  foreach ($this->getSelectedColumns() as $c)
298  {
299  if(!(bool)$data["privacy_conflict"])
300  {
301  if($c == 'status' && $data[$c] != ilLPStatus::LP_STATUS_COMPLETED_NUM)
302  {
303  $timing = $this->showTimingsWarning($this->ref_id, $data["usr_id"]);
304  if($timing)
305  {
306  if($timing !== true)
307  {
308  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
309  }
310  else
311  {
312  $timing = "";
313  }
314  $this->tpl->setCurrentBlock('warning_img');
315  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.png'));
316  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
317  $this->tpl->parseCurrentBlock();
318  }
319  }
320 
321  // #7694
322  if($c == 'login' && !$data["active"])
323  {
324  $this->tpl->setCurrentBlock('inactive_bl');
325  $this->tpl->setVariable('TXT_INACTIVE', $lng->txt("inactive"));
326  $this->tpl->parseCurrentBlock();
327  }
328 
329  $val = $this->parseValue($c, $data[$c], "user");
330  }
331  else
332  {
333  $val = "-";
334  }
335 
336  $this->tpl->setCurrentBlock("user_field");
337  $this->tpl->setVariable("VAL_UF", $val);
338  $this->tpl->parseCurrentBlock();
339  }
340 
341  $ilCtrl->setParameterByClass("illplistofobjectsgui", "user_id", $data["usr_id"]);
342 
343  if(!$this->getPrintMode() && !(bool)$data["privacy_conflict"])
344  {
345  if(in_array($this->type, array("crs", "grp", "cat", "fold")))
346  {
347  $this->tpl->setCurrentBlock("item_command");
348  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", "userdetails"));
349  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('details'));
350  $this->tpl->parseCurrentBlock();
351  }
352 
353  $this->tpl->setCurrentBlock("item_command");
354  $this->tpl->setVariable("HREF_COMMAND", $ilCtrl->getLinkTargetByClass("illplistofobjectsgui", "edituser"));
355  $this->tpl->setVariable("TXT_COMMAND", $lng->txt('edit'));
356  $this->tpl->parseCurrentBlock();
357  }
358 
359  $ilCtrl->setParameterByClass("illplistofobjectsgui", 'user_id', '');
360  }
361 
362  protected function fillHeaderExcel($worksheet, &$a_row)
363  {
364  $labels = $this->getSelectableColumns();
365  $cnt = 0;
366  foreach ($this->getSelectedColumns() as $c)
367  {
368  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
369  $cnt++;
370  }
371  }
372 
373  protected function fillRowExcel($worksheet, &$a_row, $a_set)
374  {
375  $cnt = 0;
376  foreach ($this->getSelectedColumns() as $c)
377  {
378  if($c != 'status')
379  {
380  $val = $this->parseValue($c, $a_set[$c], "user");
381  }
382  else
383  {
384  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
385  }
386  $worksheet->write($a_row, $cnt, $val);
387  $cnt++;
388  }
389  }
390 
391  protected function fillHeaderCSV($a_csv)
392  {
393  $labels = $this->getSelectableColumns();
394  foreach ($this->getSelectedColumns() as $c)
395  {
396  $a_csv->addColumn($labels[$c]["txt"]);
397  }
398 
399  $a_csv->addRow();
400  }
401 
402  protected function fillRowCSV($a_csv, $a_set)
403  {
404  foreach ($this->getSelectedColumns() as $c)
405  {
406  if($c != 'status')
407  {
408  $val = $this->parseValue($c, $a_set[$c], "user");
409  }
410  else
411  {
412  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set[$c]);
413  }
414  $a_csv->addColumn($val);
415  }
416 
417  $a_csv->addRow();
418  }
419 }
420 ?>