ILIAS  release_4-3 Revision
 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 
23  function __construct($a_parent_obj, $a_parent_cmd, $ref_id)
24  {
25  global $ilCtrl, $lng, $ilAccess, $lng, $ilObjDataCache;
26 
27  $this->setId("trsmtx_".$ref_id);
28  $this->ref_id = $ref_id;
29  $this->obj_id = ilObject::_lookupObjId($ref_id);
30 
31  $this->initFilter();
32 
33  parent::__construct($a_parent_obj, $a_parent_cmd);
34  $this->setLimit(9999);
35  $this->parseTitle($this->obj_id, "trac_matrix");
36 
37  $this->setEnableHeader(true);
38  $this->setFormAction($ilCtrl->getFormActionByClass(get_class($this)));
39  $this->setRowTemplate("tpl.user_object_matrix_row.html", "Services/Tracking");
40  $this->setDefaultOrderField("login");
41  $this->setDefaultOrderDirection("asc");
42  $this->setShowTemplates(true);
43 
44  $this->addColumn($this->lng->txt("login"), "login");
45 
46  $labels = $this->getSelectableColumns();
47  $selected = $this->getSelectedColumns();
48  foreach ($selected as $c)
49  {
50  $title = $labels[$c]["txt"];
51  $tooltip = "";
52  if(isset($labels[$c]["icon"]))
53  {
54  $alt = $lng->txt($labels[$c]["type"]);
55  $icon = '<img src="'.$labels[$c]["icon"].'" alt="'.$alt.'" />';
56  if(sizeof($selected) > 5)
57  {
58  $tooltip = $title;
59  $title = $icon;
60  }
61  else
62  {
63  $title = $icon.' '.$title;
64  }
65  }
66  $this->addColumn($title, $labels[$c]["id"], "", false, "", $tooltip);
67  }
68 
69  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
70  }
71 
72  function initFilter()
73  {
74  global $lng;
75 
76  $item = $this->addFilterItemByMetaType("name", ilTable2GUI::FILTER_TEXT);
77  $this->filter["name"] = $item->getValue();
78  }
79 
81  {
82  global $ilObjDataCache;
83 
84  $columns = array();
85 
86  if($this->obj_ids === NULL)
87  {
88  $this->obj_ids = $this->getItems();
89  }
90  if($this->obj_ids)
91  {
92  $tmp_cols = array();
93  foreach($this->obj_ids as $obj_id)
94  {
95  if($obj_id == $this->obj_id)
96  {
97  $parent = array("txt" => $this->lng->txt("status"),
98  "default" => true);
99  }
100  else
101  {
102  $title = $ilObjDataCache->lookupTitle($obj_id);
103  $type = $ilObjDataCache->lookupType($obj_id);
104  $icon = ilObject::_getIcon("", "tiny", $type);
105  if($type == "sess")
106  {
107  include_once "Modules/Session/classes/class.ilObjSession.php";
108  $sess = new ilObjSession($obj_id, false);
109  $title = $sess->getPresentationTitle();
110  }
111  $tmp_cols[strtolower($title)."#~#obj_".$obj_id] = array("txt" => $title, "icon" => $icon, "type" => $type, "default" => true);
112  }
113  }
114  if(sizeof($this->objective_ids))
115  {
116  foreach($this->objective_ids as $obj_id => $title)
117  {
118  $tmp_cols[strtolower($title)."#~#objtv_".$obj_id] = array("txt" => $title, "default" => true);
119  }
120  }
121  if(sizeof($this->sco_ids))
122  {
123  foreach($this->sco_ids as $obj_id => $title)
124  {
125  $icon = ilUtil::getTypeIconPath("sco", $obj_id, "tiny");
126  $tmp_cols[strtolower($title)."#~#objsco_".$obj_id] = array("txt" => $title, "icon"=>$icon, "default" => true);
127  }
128  }
129 
130  // alex, 5 Nov 2011: Do not sort SCORM items
131  if(!sizeof($this->sco_ids))
132  {
133  ksort($tmp_cols);
134  }
135  foreach($tmp_cols as $id => $def)
136  {
137  $id = explode('#~#', $id);
138  $columns[$id[1]] = $def;
139  }
140  unset($tmp_cols);
141 
142  if($parent)
143  {
144  $columns["obj_".$this->obj_id] = $parent;
145  }
146  }
147 
148  $columns["status_changed"] = array("txt" => $this->lng->txt("trac_status_changed"),
149  "id" => "status_changed",
150  "default" => false);
151 
152  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
153  $tracking = new ilObjUserTracking();
154 
155  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
156  {
157  $columns["last_access"] = array("txt" => $this->lng->txt("last_access"),
158  "id" => "last_access",
159  "default" => false);
160  }
161 
162  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS))
163  {
164  $columns["spent_seconds"] = array("txt" => $this->lng->txt("trac_spent_seconds"),
165  "id" => "spent_seconds",
166  "default" => false);
167  }
168 
169  return $columns;
170  }
171 
172  function getItems()
173  {
174  global $lng, $tree;
175 
176  // $this->determineOffsetAndOrder();
177 
178  include_once("./Services/Tracking/classes/class.ilTrQuery.php");
179  $collection = ilTrQuery::getObjectIds($this->obj_id, $this->ref_id, true);
180  if($collection["object_ids"])
181  {
182  // we need these for the timing warnings
183  $this->ref_ids = $collection["ref_ids"];
184 
185  $data = ilTrQuery::getUserObjectMatrix($this->ref_id, $collection["object_ids"], $this->filter["name"]);
186  if($collection["objectives_parent_id"] && $data["users"])
187  {
188  $objectives = ilTrQuery::getUserObjectiveMatrix($collection["objectives_parent_id"], $data["users"]);
189  if($objectives["cnt"])
190  {
191  $this->objective_ids = array();
192  $objective_columns = array();
193  foreach($objectives["set"] as $row)
194  {
195  if(isset($data["set"][$row["usr_id"]]))
196  {
197  $obj_id = "objtv_".$row["obj_id"];
198  $data["set"][$row["usr_id"]]["objects"][$obj_id] = array("status"=>$row["status"]);
199 
200  if(!in_array($obj_id, $this->objective_ids))
201  {
202  $this->objective_ids[$obj_id] = $row["title"];
203  }
204  }
205  }
206  }
207  }
208 
209  if($collection["scorm"] && $data["set"])
210  {
211  $this->sco_ids = array();
212  foreach(array_keys($data["set"]) as $user_id)
213  {
214  foreach($collection["scorm"]["scos"] as $sco)
215  {
216  if(!in_array($sco, $this->sco_ids))
217  {
218  $this->sco_ids[$sco] = $collection["scorm"]["scos_title"][$sco];
219  }
220 
221  // alex, 5 Nov 2011: we got users being in failed and in
222  // completed status, I changed the setting in: first check failed
223  // then check completed since failed should superseed completed
224  // (before completed has been checked before failed)
225  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
226  if(in_array($user_id, $collection["scorm"]["failed"][$sco]))
227  {
228  $status = LP_STATUS_FAILED_NUM;
229  }
230  else if(in_array($user_id, $collection["scorm"]["completed"][$sco]))
231  {
232  $status = LP_STATUS_COMPLETED_NUM;
233  }
234  else if(in_array($user_id, $collection["scorm"]["in_progress"][$sco]))
235  {
236  $status = LP_STATUS_IN_PROGRESS_NUM;
237  }
238 
239  $obj_id = "objsco_".$sco;
240  $data["set"][$user_id]["objects"][$obj_id] = array("status"=>$status);
241  }
242  }
243  }
244 
245  // percentage export
246  if($data["set"])
247  {
248  $this->perc_map = array();
249  foreach($data["set"] as $item)
250  {
251  if(is_array($item["objects"]))
252  {
253  foreach($item["objects"] as $obj_id => $obj_data)
254  {
255  if((int)$obj_data["percentage"] > 0)
256  {
257  $this->perc_map[$obj_id] = true;
258  }
259  }
260  }
261  }
262  }
263 
264  $this->setMaxCount($data["cnt"]);
265  $this->setData($data["set"]);
266 
267  return $collection["object_ids"];
268  }
269  return false;
270  }
271 
272  function fillRow(array $a_set)
273  {
274  global $lng;
275 
276  // #7694
277  if(!$a_set["active"])
278  {
279  $this->tpl->setCurrentBlock('inactive_bl');
280  $this->tpl->setVariable('TXT_INACTIVE', $lng->txt("inactive"));
281  $this->tpl->parseCurrentBlock();
282  }
283 
284  $this->tpl->setVariable("VAL_LOGIN", $a_set["login"]);
285 
286  foreach ($this->getSelectedColumns() as $c)
287  {
288  switch($c)
289  {
290  case "last_access":
291  case "spent_seconds":
292  case 'status_changed':
293  $this->tpl->setCurrentBlock($c);
294  $this->tpl->setVariable("VAL_".strtoupper($c), $this->parseValue($c, $a_set[$c], ""));
295  $this->tpl->parseCurrentBlock();
296  break;
297 
298  case (substr($c, 0, 4) == "obj_"):
299  $obj_id = substr($c, 4);
300  if(!isset($a_set["objects"][$obj_id]))
301  {
302  $data = array("status"=>0);
303  }
304  else
305  {
306  $data = $a_set["objects"][$obj_id];
307  if($data["percentage"] == "0")
308  {
309  $data["percentage"] = NULL;
310  }
311  }
312 
313  if($data['status'] != LP_STATUS_COMPLETED_NUM)
314  {
315  $timing = $this->showTimingsWarning($this->ref_ids[$obj_id], $a_set["usr_id"]);
316  if($timing)
317  {
318  if($timing !== true)
319  {
320  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
321  }
322  else
323  {
324  $timing = "";
325  }
326  $this->tpl->setCurrentBlock('warning_img');
327  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.png'));
328  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
329  $this->tpl->parseCurrentBlock();
330  }
331  }
332 
333  $this->tpl->setCurrentBlock("objects");
334  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
335  $this->tpl->setVariable("VAL_PERCENTAGE", $this->parseValue("percentage", $data["percentage"], ""));
336  $this->tpl->parseCurrentBlock();
337  break;
338 
339 
340  case (substr($c, 0, 6) == "objtv_"):
341  case (substr($c, 0, 7) == "objsco_"):
342  $obj_id = $c;
343  if(!isset($a_set["objects"][$obj_id]))
344  {
345  $data = array("status"=>0);
346  }
347  else
348  {
349  $data = $a_set["objects"][$obj_id];
350  }
351  $this->tpl->setCurrentBlock("objects");
352  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
353  $this->tpl->parseCurrentBlock();
354  break;
355  }
356  }
357  }
358 
359  protected function fillHeaderExcel($worksheet, &$a_row)
360  {
361  global $ilObjDataCache;
362 
363  $worksheet->write($a_row, 0, $this->lng->txt("login"));
364 
365  $labels = $this->getSelectableColumns();
366  $cnt = 1;
367  foreach ($this->getSelectedColumns() as $c)
368  {
369  if(substr($c, 0, 4) == "obj_")
370  {
371  $obj_id = substr($c, 4);
372  $type = $ilObjDataCache->lookupType($obj_id);
373  $worksheet->write($a_row, $cnt, "(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
374 
375  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
376  {
377  $cnt++;
378  $worksheet->write($a_row, $cnt, $this->lng->txt("trac_percentage")." (%)");
379  }
380  }
381  else
382  {
383  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
384  }
385  $cnt++;
386  }
387  }
388 
389  protected function fillRowExcel($worksheet, &$a_row, $a_set)
390  {
391  $worksheet->write($a_row, 0, $a_set["login"]);
392 
393  $cnt = 1;
394  foreach ($this->getSelectedColumns() as $c)
395  {
396  switch($c)
397  {
398  case "last_access":
399  case "spent_seconds":
400  case "status_changed":
401  $val = $this->parseValue($c, $a_set[$c], "user");
402  $worksheet->write($a_row, $cnt, $val);
403  break;
404 
405  case (substr($c, 0, 4) == "obj_"):
406  $obj_id = substr($c, 4);
407  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
408  $worksheet->write($a_row, $cnt, $val);
409 
410  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
411  {
412  $cnt++;
413  $perc = (int)$a_set["objects"][$obj_id]["percentage"];
414  if(!$perc)
415  {
416  $perc = null;
417  }
418  $worksheet->write($a_row, $cnt, $perc);
419  }
420  break;
421 
422  case (substr($c, 0, 6) == "objtv_"):
423  case (substr($c, 0, 7) == "objsco_"):
424  $obj_id = $c;
425  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
426  $worksheet->write($a_row, $cnt, $val);
427  break;
428  }
429  $cnt++;
430  }
431  }
432 
433  protected function fillHeaderCSV($a_csv)
434  {
435  global $ilObjDataCache;
436 
437  $a_csv->addColumn($this->lng->txt("login"));
438 
439  $labels = $this->getSelectableColumns();
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  $a_csv->addColumn("(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
447 
448  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
449  {
450  $a_csv->addColumn($this->lng->txt("trac_percentage")." (%)");
451  }
452  }
453  else
454  {
455  $a_csv->addColumn($labels[$c]["txt"]);
456  }
457  }
458 
459  $a_csv->addRow();
460  }
461 
462  protected function fillRowCSV($a_csv, $a_set)
463  {
464  $a_csv->addColumn($a_set["login"]);
465 
466  foreach ($this->getSelectedColumns() as $c)
467  {
468  switch($c)
469  {
470  case "last_access":
471  case "spent_seconds":
472  case "status_changed":
473  $val = $this->parseValue($c, $a_set[$c], "user");
474  $a_csv->addColumn($val);
475  break;
476 
477  case (substr($c, 0, 4) == "obj_"):
478  $obj_id = substr($c, 4);
479  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
480  $a_csv->addColumn($val);
481 
482  if(is_array($this->perc_map) && $this->perc_map[$obj_id])
483  {
484  $perc = (int)$a_set["objects"][$obj_id]["percentage"];
485  if(!$perc)
486  {
487  $perc = null;
488  }
489  $a_csv->addColumn($perc);
490  }
491  break;
492 
493  case (substr($c, 0, 6) == "objtv_"):
494  case (substr($c, 0, 7) == "objsco_"):
495  $obj_id = $c;
496  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
497  $a_csv->addColumn($val);
498  break;
499  }
500  }
501 
502  $a_csv->addRow();
503  }
504 }
505 
506 ?>