ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTrMatrixTableGUI.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 
15 {
16  protected $obj_ids = NULL;
17  protected $objective_ids = NULL;
18  protected $sco_ids = NULL;
19  protected $subitem_ids = NULL;
20  protected $in_course; // int
21  protected $in_group; // int
22  protected $privacy_fields; // array
23 
27  function __construct($a_parent_obj, $a_parent_cmd, $ref_id)
28  {
29  global $ilCtrl, $lng, $tree;
30 
31  $this->setId("trsmtx_".$ref_id);
32  $this->ref_id = $ref_id;
33  $this->obj_id = ilObject::_lookupObjId($ref_id);
34 
35  $this->in_group = $tree->checkForParentType($this->ref_id, "grp");
36  if($this->in_group)
37  {
38  $this->in_group = ilObject::_lookupObjId($this->in_group);
39  }
40  else
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  }
48 
49  $this->initFilter();
50 
51  parent::__construct($a_parent_obj, $a_parent_cmd);
52  $this->setLimit(9999);
53  $this->parseTitle($this->obj_id, "trac_matrix");
54 
55  $this->setEnableHeader(true);
56  $this->setFormAction($ilCtrl->getFormActionByClass(get_class($this)));
57  $this->setRowTemplate("tpl.user_object_matrix_row.html", "Services/Tracking");
58  $this->setDefaultOrderField("login");
59  $this->setDefaultOrderDirection("asc");
60  $this->setShowTemplates(true);
61 
62  $this->addColumn($this->lng->txt("login"), "login");
63 
64  $labels = $this->getSelectableColumns();
65  $selected = $this->getSelectedColumns();
66  foreach ($selected as $c)
67  {
68  $title = $labels[$c]["txt"];
69  $tooltip = "";
70  if(isset($labels[$c]["icon"]))
71  {
72  $alt = $lng->txt($labels[$c]["type"]);
73  $icon = '<img src="'.$labels[$c]["icon"].'" alt="'.$alt.'" />';
74  if(sizeof($selected) > 5)
75  {
76  $tooltip = $title;
77  $title = $icon;
78  }
79  else
80  {
81  $title = $icon.' '.$title;
82  }
83  }
84 
85  if(isset($labels[$c]["id"]))
86  {
87  $sort_id = $labels[$c]["id"];
88  }
89  else
90  {
91  // list cannot be sorted by udf fields (separate query)
92  $sort_id = (substr($c, 0, 4) == "udf_") ? "" : $c;
93  }
94 
95  $this->addColumn($title, $sort_id, "", false, "", $tooltip);
96  }
97 
98  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
99  }
100 
101  function initFilter()
102  {
103  global $lng;
104 
105  $item = $this->addFilterItemByMetaType("name", ilTable2GUI::FILTER_TEXT);
106  $this->filter["name"] = $item->getValue();
107  }
108 
110  {
111  global $ilObjDataCache;
112 
113  $user_cols = $this->getSelectableUserColumns($this->in_course, $this->in_group);
114 
115  if($this->obj_ids === NULL)
116  {
117  // we cannot use the selected columns because they are not ready yet
118  // so we use all available columns, should be ok anyways
119  $this->obj_ids = $this->getItems(array_keys($user_cols[0]), $user_cols[1]);
120  }
121  if($this->obj_ids)
122  {
123  $tmp_cols = array();
124  foreach($this->obj_ids as $obj_id)
125  {
126  if($obj_id == $this->obj_id)
127  {
128  $parent = array("txt" => $this->lng->txt("status"),
129  "default" => true);
130  }
131  else
132  {
133  $title = $ilObjDataCache->lookupTitle($obj_id);
134  $type = $ilObjDataCache->lookupType($obj_id);
135  $icon = ilObject::_getIcon("", "tiny", $type);
136  if($type == "sess")
137  {
138  include_once "Modules/Session/classes/class.ilObjSession.php";
139  $sess = new ilObjSession($obj_id, false);
140  $title = $sess->getPresentationTitle();
141  }
142  $tmp_cols[strtolower($title)."#~#obj_".$obj_id] = array("txt" => $title, "icon" => $icon, "type" => $type, "default" => true);
143  }
144  }
145  if(sizeof($this->objective_ids))
146  {
147  foreach($this->objective_ids as $obj_id => $title)
148  {
149  $tmp_cols[strtolower($title)."#~#objtv_".$obj_id] = array("txt" => $title, "default" => true);
150  }
151  }
152  if(sizeof($this->sco_ids))
153  {
154  foreach($this->sco_ids as $obj_id => $title)
155  {
156  $icon = ilUtil::getTypeIconPath("sco", $obj_id, "tiny");
157  $tmp_cols[strtolower($title)."#~#objsco_".$obj_id] = array("txt" => $title, "icon"=>$icon, "default" => true);
158  }
159  }
160  if(sizeof($this->subitem_ids))
161  {
162  foreach($this->subitem_ids as $obj_id => $title)
163  {
164  $icon = ilUtil::getTypeIconPath("st", $obj_id, "tiny");
165  $tmp_cols[strtolower($title)."#~#objsub_".$obj_id] = array("txt" => $title, "icon"=>$icon, "default" => true);
166  }
167  }
168 
169  // alex, 5 Nov 2011: Do not sort SCORM items or "chapters"
170  if(!sizeof($this->sco_ids) && !sizeof($this->subitem_ids))
171  {
172  ksort($tmp_cols);
173  }
174  foreach($tmp_cols as $id => $def)
175  {
176  $id = explode('#~#', $id);
177  $columns[$id[1]] = $def;
178  }
179  unset($tmp_cols);
180 
181  if($parent)
182  {
183  $columns["obj_".$this->obj_id] = $parent;
184  }
185  }
186 
187  unset($user_cols[0]["status"]);
188  unset($user_cols[0]["login"]);
189  foreach($user_cols[0] as $col_id => $col_def)
190  {
191  if(!isset($columns[$col_id]))
192  {
193  // these are all additional fields, no default
194  $col_def["default"] = false;
195  $columns[$col_id] = $col_def;
196  }
197  }
198 
199  return $columns;
200  }
201 
202  function getItems(array $a_user_fields, array $a_privary_fields = null)
203  {
204  include_once("./Services/Tracking/classes/class.ilTrQuery.php");
205  $collection = ilTrQuery::getObjectIds($this->obj_id, $this->ref_id, true);
206  if($collection["object_ids"])
207  {
208  // we need these for the timing warnings
209  $this->ref_ids = $collection["ref_ids"];
210 
211  // only if object is [part of] course/group
212  $check_agreement = false;
213  if($this->in_course)
214  {
215  // privacy (if course agreement is activated)
216  include_once "Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
217  $privacy = ilPrivacySettings::_getInstance();
218  if($privacy->courseConfirmationRequired())
219  {
220  $check_agreement = $this->in_course;
221  }
222  }
223  else if($this->in_group)
224  {
225  // privacy (if group agreement is activated)
226  include_once "Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
227  $privacy = ilPrivacySettings::_getInstance();
228  if($privacy->groupConfirmationRequired())
229  {
230  $check_agreement = $this->in_group;
231  }
232  }
233 
234  $data = ilTrQuery::getUserObjectMatrix($this->ref_id, $collection["object_ids"], $this->filter["name"], $a_user_fields, $a_privary_fields, $check_agreement);
235  if($collection["objectives_parent_id"] && $data["users"])
236  {
237  $objectives = ilTrQuery::getUserObjectiveMatrix($collection["objectives_parent_id"], $data["users"]);
238  if($objectives["cnt"])
239  {
240  $this->objective_ids = array();
241  $objective_columns = array();
242  foreach($objectives["set"] as $row)
243  {
244  if(isset($data["set"][$row["usr_id"]]))
245  {
246  $obj_id = "objtv_".$row["obj_id"];
247  $data["set"][$row["usr_id"]]["objects"][$obj_id] = array("status"=>$row["status"]);
248 
249  if(!in_array($obj_id, $this->objective_ids))
250  {
251  $this->objective_ids[$obj_id] = $row["title"];
252  }
253  }
254  }
255  }
256  }
257 
258  if($collection["scorm"] && $data["set"])
259  {
260  $this->sco_ids = array();
261  foreach(array_keys($data["set"]) as $user_id)
262  {
263  foreach($collection["scorm"]["scos"] as $sco)
264  {
265  if(!in_array($sco, $this->sco_ids))
266  {
267  $this->sco_ids[$sco] = $collection["scorm"]["scos_title"][$sco];
268  }
269 
270  // alex, 5 Nov 2011: we got users being in failed and in
271  // completed status, I changed the setting in: first check failed
272  // then check completed since failed should superseed completed
273  // (before completed has been checked before failed)
275  if(in_array($user_id, $collection["scorm"]["failed"][$sco]))
276  {
278  }
279  else if(in_array($user_id, $collection["scorm"]["completed"][$sco]))
280  {
282  }
283  else if(in_array($user_id, $collection["scorm"]["in_progress"][$sco]))
284  {
286  }
287 
288  $obj_id = "objsco_".$sco;
289  $data["set"][$user_id]["objects"][$obj_id] = array("status"=>$status);
290  }
291  }
292  }
293 
294  if($collection["subitems"] && $data["set"])
295  {
296  foreach(array_keys($data["set"]) as $user_id)
297  {
298  foreach($collection["subitems"]["items"] as $item_id)
299  {
300  $this->subitem_ids[$item_id] = $collection["subitems"]["item_titles"][$item_id];
301 
303  if(in_array($user_id, $collection["subitems"]["completed"][$item_id]))
304  {
306  }
307  else if(is_array($collection["subitems"]["in_progress"]) &&
308  in_array($user_id, $collection["subitems"]["in_progress"][$item_id]))
309  {
311  }
312 
313  $obj_id = "objsub_".$item_id;
314  $data["set"][$user_id]["objects"][$obj_id] = array("status"=>$status);
315  }
316  }
317  }
318 
319  // percentage export
320  if($data["set"])
321  {
322  $this->perc_map = array();
323  foreach($data["set"] as $item)
324  {
325  if(is_array($item["objects"]))
326  {
327  foreach($item["objects"] as $obj_id => $obj_data)
328  {
329  if((int)$obj_data["percentage"] > 0)
330  {
331  $this->perc_map[$obj_id] = true;
332  }
333  }
334  }
335  }
336  }
337 
338  $this->setMaxCount($data["cnt"]);
339  $this->setData($data["set"]);
340 
341  return $collection["object_ids"];
342  }
343  return false;
344  }
345 
346  function fillRow(array $a_set)
347  {
348  global $lng;
349 
350  // #7694
351  if(!$a_set["active"])
352  {
353  $this->tpl->setCurrentBlock('inactive_bl');
354  $this->tpl->setVariable('TXT_INACTIVE', $lng->txt("inactive"));
355  $this->tpl->parseCurrentBlock();
356  }
357 
358  $this->tpl->setVariable("VAL_LOGIN", $a_set["login"]);
359 
360  foreach ($this->getSelectedColumns() as $c)
361  {
362  switch($c)
363  {
364  case (substr($c, 0, 4) == "obj_"):
365  $obj_id = substr($c, 4);
366  if(!isset($a_set["objects"][$obj_id]))
367  {
368  $data = array("status"=>0);
369  }
370  else
371  {
372  $data = $a_set["objects"][$obj_id];
373  if($data["percentage"] == "0")
374  {
375  $data["percentage"] = NULL;
376  }
377  }
378 
380  {
381  $timing = $this->showTimingsWarning($this->ref_ids[$obj_id], $a_set["usr_id"]);
382  if($timing)
383  {
384  if($timing !== true)
385  {
386  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
387  }
388  else
389  {
390  $timing = "";
391  }
392  $this->tpl->setCurrentBlock('warning_img');
393  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.png'));
394  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
395  $this->tpl->parseCurrentBlock();
396  }
397  }
398 
399  $this->tpl->setCurrentBlock("objects");
400  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
401  $this->tpl->setVariable("VAL_PERCENTAGE", $this->parseValue("percentage", $data["percentage"], ""));
402  $this->tpl->parseCurrentBlock();
403  break;
404 
405 
406  case (substr($c, 0, 6) == "objtv_"):
407  case (substr($c, 0, 7) == "objsco_"):
408  case (substr($c, 0, 7) == "objsub_"):
409  $obj_id = $c;
410  if(!isset($a_set["objects"][$obj_id]))
411  {
412  $data = array("status"=>0);
413  }
414  else
415  {
416  $data = $a_set["objects"][$obj_id];
417  }
418  $this->tpl->setCurrentBlock("objects");
419  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
420  $this->tpl->parseCurrentBlock();
421  break;
422 
423  default:
424  $this->tpl->setCurrentBlock("user_field");
425  $this->tpl->setVariable("VAL_UF", $this->parseValue($c, $a_set[$c], ""));
426  $this->tpl->parseCurrentBlock();
427  break;
428  }
429  }
430  }
431 
432  protected function fillHeaderExcel($worksheet, &$a_row)
433  {
434  global $ilObjDataCache;
435 
436  $worksheet->write($a_row, 0, $this->lng->txt("login"));
437 
438  $labels = $this->getSelectableColumns();
439  $cnt = 1;
440  foreach ($this->getSelectedColumns() as $c)
441  {
442  if(substr($c, 0, 4) == "obj_")
443  {
444  $obj_id = substr($c, 4);
445  $type = $ilObjDataCache->lookupType($obj_id);
446  $worksheet->write($a_row, $cnt, "(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
447 
448  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
449  {
450  $cnt++;
451  $worksheet->write($a_row, $cnt, $this->lng->txt("trac_percentage")." (%)");
452  }
453  }
454  else
455  {
456  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
457  }
458  $cnt++;
459  }
460  }
461 
462  protected function fillRowExcel($worksheet, &$a_row, $a_set)
463  {
464  $worksheet->write($a_row, 0, $a_set["login"]);
465 
466  $cnt = 1;
467  foreach ($this->getSelectedColumns() as $c)
468  {
469  switch($c)
470  {
471  case (substr($c, 0, 4) == "obj_"):
472  $obj_id = substr($c, 4);
473  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
474  $worksheet->write($a_row, $cnt, $val);
475 
476  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
477  {
478  $cnt++;
479  $perc = (int)$a_set["objects"][$obj_id]["percentage"];
480  if(!$perc)
481  {
482  $perc = null;
483  }
484  $worksheet->write($a_row, $cnt, $perc);
485  }
486  break;
487 
488  case (substr($c, 0, 6) == "objtv_"):
489  case (substr($c, 0, 7) == "objsco_"):
490  case (substr($c, 0, 7) == "objsub_"):
491  $obj_id = $c;
492  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
493  $worksheet->write($a_row, $cnt, $val);
494  break;
495 
496  /* #14142
497  case "last_access":
498  case "spent_seconds":
499  case "status_changed":
500  */
501  default:
502  $val = $this->parseValue($c, $a_set[$c], "user");
503  $worksheet->write($a_row, $cnt, $val);
504  break;
505 
506  }
507  $cnt++;
508  }
509  }
510 
511  protected function fillHeaderCSV($a_csv)
512  {
513  global $ilObjDataCache;
514 
515  $a_csv->addColumn($this->lng->txt("login"));
516 
517  $labels = $this->getSelectableColumns();
518  foreach ($this->getSelectedColumns() as $c)
519  {
520  if(substr($c, 0, 4) == "obj_")
521  {
522  $obj_id = substr($c, 4);
523  $type = $ilObjDataCache->lookupType($obj_id);
524  $a_csv->addColumn("(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
525 
526  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
527  {
528  $a_csv->addColumn($this->lng->txt("trac_percentage")." (%)");
529  }
530  }
531  else
532  {
533  $a_csv->addColumn($labels[$c]["txt"]);
534  }
535  }
536 
537  $a_csv->addRow();
538  }
539 
540  protected function fillRowCSV($a_csv, $a_set)
541  {
542  $a_csv->addColumn($a_set["login"]);
543 
544  foreach ($this->getSelectedColumns() as $c)
545  {
546  switch($c)
547  {
548  case (substr($c, 0, 4) == "obj_"):
549  $obj_id = substr($c, 4);
550  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
551  $a_csv->addColumn($val);
552 
553  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
554  {
555  $perc = (int)$a_set["objects"][$obj_id]["percentage"];
556  if(!$perc)
557  {
558  $perc = null;
559  }
560  $a_csv->addColumn($perc);
561  }
562  break;
563 
564  case (substr($c, 0, 6) == "objtv_"):
565  case (substr($c, 0, 7) == "objsco_"):
566  case (substr($c, 0, 7) == "objsub_"):
567  $obj_id = $c;
568  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
569  $a_csv->addColumn($val);
570  break;
571 
572  /* #14142
573  case "last_access":
574  case "spent_seconds":
575  case "status_changed":
576  */
577  default:
578  $val = $this->parseValue($c, $a_set[$c], "user");
579  $a_csv->addColumn($val);
580  break;
581 
582  }
583  }
584 
585  $a_csv->addRow();
586  }
587 }
588 
589 ?>