ILIAS  Release_4_2_x_branch Revision 61807
 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 = ilUtil::getTypeIconPath($type, $obj_id, "tiny");
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  $this->setMaxCount($data["cnt"]);
246  $this->setData($data["set"]);
247 //var_dump($this->sco_ids);
248  return $collection["object_ids"];
249  }
250  return false;
251  }
252 
253  function fillRow(array $a_set)
254  {
255  global $lng;
256 
257  // #7694
258  if(!$a_set["active"])
259  {
260  $this->tpl->setCurrentBlock('inactive_bl');
261  $this->tpl->setVariable('TXT_INACTIVE', $lng->txt("inactive"));
262  $this->tpl->parseCurrentBlock();
263  }
264 
265  $this->tpl->setVariable("VAL_LOGIN", $a_set["login"]);
266 
267  foreach ($this->getSelectedColumns() as $c)
268  {
269  switch($c)
270  {
271  case "last_access":
272  case "spent_seconds":
273  case 'status_changed':
274  $this->tpl->setCurrentBlock($c);
275  $this->tpl->setVariable("VAL_".strtoupper($c), $this->parseValue($c, $a_set[$c], ""));
276  $this->tpl->parseCurrentBlock();
277  break;
278 
279  case (substr($c, 0, 4) == "obj_"):
280  $obj_id = substr($c, 4);
281  if(!isset($a_set["objects"][$obj_id]))
282  {
283  $data = array("status"=>0);
284  }
285  else
286  {
287  $data = $a_set["objects"][$obj_id];
288  if($data["percentage"] == "0")
289  {
290  $data["percentage"] = NULL;
291  }
292  }
293 
294  if($data['status'] != LP_STATUS_COMPLETED_NUM)
295  {
296  $timing = $this->showTimingsWarning($this->ref_ids[$obj_id], $a_set["usr_id"]);
297  if($timing)
298  {
299  if($timing !== true)
300  {
301  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
302  }
303  else
304  {
305  $timing = "";
306  }
307  $this->tpl->setCurrentBlock('warning_img');
308  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.gif'));
309  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
310  $this->tpl->parseCurrentBlock();
311  }
312  }
313 
314  $this->tpl->setCurrentBlock("objects");
315  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
316  $this->tpl->setVariable("VAL_PERCENTAGE", $this->parseValue("percentage", $data["percentage"], ""));
317  $this->tpl->parseCurrentBlock();
318  break;
319 
320 
321  case (substr($c, 0, 6) == "objtv_"):
322  $obj_id = $c;
323  if(!isset($a_set["objects"][$obj_id]))
324  {
325  $data = array("status"=>0);
326  }
327  else
328  {
329  $data = $a_set["objects"][$obj_id];
330  }
331  $this->tpl->setCurrentBlock("objects");
332  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
333  $this->tpl->parseCurrentBlock();
334  break;
335 
336  case (substr($c, 0, 7) == "objsco_"):
337  $obj_id = $c;
338  if(!isset($a_set["objects"][$obj_id]))
339  {
340  $data = array("status"=>0);
341  }
342  else
343  {
344  $data = $a_set["objects"][$obj_id];
345  }
346  $this->tpl->setCurrentBlock("objects");
347  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
348  $this->tpl->parseCurrentBlock();
349  break;
350  }
351  }
352  }
353 
354  protected function fillHeaderExcel($worksheet, &$a_row)
355  {
356  global $ilObjDataCache;
357 
358  $worksheet->write($a_row, 0, $this->lng->txt("login"));
359 
360  $labels = $this->getSelectableColumns();
361  $cnt = 1;
362  foreach ($this->getSelectedColumns() as $c)
363  {
364  if(substr($c, 0, 4) == "obj_")
365  {
366  $obj_id = substr($c, 4);
367  $type = $ilObjDataCache->lookupType($obj_id);
368  $worksheet->write($a_row, $cnt, "(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
369  }
370  else
371  {
372  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
373  }
374  $cnt++;
375  }
376  }
377 
378  protected function fillRowExcel($worksheet, &$a_row, $a_set)
379  {
380  $worksheet->write($a_row, 0, $a_set["login"]);
381 
382  $cnt = 1;
383  foreach ($this->getSelectedColumns() as $c)
384  {
385  switch($c)
386  {
387  case "last_access":
388  case "spent_seconds":
389  case "status_changed":
390  $val = $this->parseValue($c, $a_set[$c], "user");
391  break;
392 
393  case (substr($c, 0, 4) == "obj_"):
394  $obj_id = substr($c, 4);
395  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
396  break;
397 
398  case (substr($c, 0, 6) == "objtv_"):
399  $obj_id = $c;
400  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
401  break;
402 
403  case (substr($c, 0, 7) == "objsco_"):
404  $obj_id = $c;
405  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
406  break;
407  }
408  $worksheet->write($a_row, $cnt, $val);
409  $cnt++;
410  }
411  }
412 
413  protected function fillHeaderCSV($a_csv)
414  {
415  global $ilObjDataCache;
416 
417  $a_csv->addColumn($this->lng->txt("login"));
418 
419  $labels = $this->getSelectableColumns();
420  foreach ($this->getSelectedColumns() as $c)
421  {
422  if(substr($c, 0, 4) == "obj_")
423  {
424  $obj_id = substr($c, 4);
425  $type = $ilObjDataCache->lookupType($obj_id);
426  $a_csv->addColumn("(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
427  }
428  else
429  {
430  $a_csv->addColumn($labels[$c]["txt"]);
431  }
432  }
433 
434  $a_csv->addRow();
435  }
436 
437  protected function fillRowCSV($a_csv, $a_set)
438  {
439  $a_csv->addColumn($a_set["login"]);
440 
441  foreach ($this->getSelectedColumns() as $c)
442  {
443  switch($c)
444  {
445  case "last_access":
446  case "spent_seconds":
447  case "status_changed":
448  $val = $this->parseValue($c, $a_set[$c], "user");
449  break;
450 
451  case (substr($c, 0, 4) == "obj_"):
452  $obj_id = substr($c, 4);
453  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
454  break;
455 
456  case (substr($c, 0, 6) == "objtv_"):
457  $obj_id = $c;
458  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
459  break;
460 
461  case (substr($c, 0, 7) == "objsco_"):
462  $obj_id = $c;
463  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
464  break;
465  }
466  $a_csv->addColumn($val);
467  }
468 
469  $a_csv->addRow();
470  }
471 }
472 
473 ?>