ILIAS  Release_4_1_x_branch Revision 61804
 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  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
149  $tracking = new ilObjUserTracking();
150 
151  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
152  {
153  $columns["last_access"] = array("txt" => $this->lng->txt("last_access"),
154  "id" => "last_access",
155  "default" => false);
156  }
157 
158  if($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS))
159  {
160  $columns["spent_seconds"] = array("txt" => $this->lng->txt("trac_spent_seconds"),
161  "id" => "spent_seconds",
162  "default" => false);
163  }
164 
165  return $columns;
166  }
167 
168  function getItems()
169  {
170  global $lng, $tree;
171 
172  // $this->determineOffsetAndOrder();
173 
174  include_once("./Services/Tracking/classes/class.ilTrQuery.php");
175  $collection = ilTrQuery::getObjectIds($this->obj_id, $this->ref_id, true);
176  if($collection["object_ids"])
177  {
178  // we need these for the timing warnings
179  $this->ref_ids = $collection["ref_ids"];
180 
181  $data = ilTrQuery::getUserObjectMatrix($this->ref_id, $collection["object_ids"], $this->filter["name"]);
182 
183  if($collection["objectives_parent_id"] && $data["users"])
184  {
185  $objectives = ilTrQuery::getUserObjectiveMatrix($collection["objectives_parent_id"], $data["users"]);
186  if($objectives["cnt"])
187  {
188  $this->objective_ids = array();
189  $objective_columns = array();
190  foreach($objectives["set"] as $row)
191  {
192  if(isset($data["set"][$row["usr_id"]]))
193  {
194  $obj_id = "objtv_".$row["obj_id"];
195  $data["set"][$row["usr_id"]]["objects"][$obj_id] = array("status"=>$row["status"]);
196 
197  if(!in_array($obj_id, $this->objective_ids))
198  {
199  $this->objective_ids[$obj_id] = $row["title"];
200  }
201  }
202  }
203  }
204  }
205 
206  if($collection["scorm"])
207  {
208  $this->sco_ids = array();
209  foreach(array_keys($data["set"]) as $user_id)
210  {
211  foreach($collection["scorm"]["scos"] as $sco)
212  {
213  if(!in_array($sco, $this->sco_ids))
214  {
215  $this->sco_ids[$sco] = $collection["scorm"]["scos_title"][$sco];
216  }
217 
218  // alex, 5 Nov 2011: we got users being in failed and in
219  // completed status, I changed the setting in: first check failed
220  // then check completed since failed should superseed completed
221  // (before completed has been checked before failed)
222  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
223  if(in_array($user_id, $collection["scorm"]["failed"][$sco]))
224  {
225  $status = LP_STATUS_FAILED_NUM;
226  }
227  else if(in_array($user_id, $collection["scorm"]["completed"][$sco]))
228  {
229  $status = LP_STATUS_COMPLETED_NUM;
230  }
231  else if(in_array($user_id, $collection["scorm"]["in_progress"][$sco]))
232  {
233  $status = LP_STATUS_IN_PROGRESS_NUM;
234  }
235 
236  $obj_id = "objsco_".$sco;
237  $data["set"][$user_id]["objects"][$obj_id] = array("status"=>$status);
238  }
239  }
240  }
241 
242  $this->setMaxCount($data["cnt"]);
243  $this->setData($data["set"]);
244 
245  return $collection["object_ids"];
246  }
247  return false;
248  }
249 
250  function fillRow(array $a_set)
251  {
252  $this->tpl->setVariable("VAL_LOGIN", $a_set["login"]);
253 
254  foreach ($this->getSelectedColumns() as $c)
255  {
256  switch($c)
257  {
258  case "last_access":
259  case "spent_seconds":
260  $this->tpl->setCurrentBlock($c);
261  $this->tpl->setVariable("VAL_".strtoupper($c), $this->parseValue($c, $a_set[$c], ""));
262  $this->tpl->parseCurrentBlock();
263  break;
264 
265  case (substr($c, 0, 4) == "obj_"):
266  $obj_id = substr($c, 4);
267  if(!isset($a_set["objects"][$obj_id]))
268  {
269  $data = array("status"=>0);
270  }
271  else
272  {
273  $data = $a_set["objects"][$obj_id];
274  if($data["percentage"] == "0")
275  {
276  $data["percentage"] = NULL;
277  }
278  }
279 
280  if($data['status'] != LP_STATUS_COMPLETED_NUM)
281  {
282  $timing = $this->showTimingsWarning($this->ref_ids[$obj_id], $a_set["usr_id"]);
283  if($timing)
284  {
285  if($timing !== true)
286  {
287  $timing = ": ".ilDatePresentation::formatDate(new ilDate($timing, IL_CAL_UNIX));
288  }
289  else
290  {
291  $timing = "";
292  }
293  $this->tpl->setCurrentBlock('warning_img');
294  $this->tpl->setVariable('WARNING_IMG', ilUtil::getImagePath('time_warn.gif'));
295  $this->tpl->setVariable('WARNING_ALT', $this->lng->txt('trac_time_passed').$timing);
296  $this->tpl->parseCurrentBlock();
297  }
298  }
299 
300  $this->tpl->setCurrentBlock("objects");
301  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
302  $this->tpl->setVariable("VAL_PERCENTAGE", $this->parseValue("percentage", $data["percentage"], ""));
303  $this->tpl->parseCurrentBlock();
304  break;
305 
306 
307  case (substr($c, 0, 6) == "objtv_"):
308  $obj_id = $c;
309  if(!isset($a_set["objects"][$obj_id]))
310  {
311  $data = array("status"=>0);
312  }
313  else
314  {
315  $data = $a_set["objects"][$obj_id];
316  }
317  $this->tpl->setCurrentBlock("objects");
318  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
319  $this->tpl->parseCurrentBlock();
320  break;
321 
322  case (substr($c, 0, 7) == "objsco_"):
323  $obj_id = $c;
324  if(!isset($a_set["objects"][$obj_id]))
325  {
326  $data = array("status"=>0);
327  }
328  else
329  {
330  $data = $a_set["objects"][$obj_id];
331  }
332  $this->tpl->setCurrentBlock("objects");
333  $this->tpl->setVariable("VAL_STATUS", $this->parseValue("status", $data["status"], ""));
334  $this->tpl->parseCurrentBlock();
335  break;
336  }
337  }
338  }
339 
340  protected function fillHeaderExcel($worksheet, &$a_row)
341  {
342  global $ilObjDataCache;
343 
344  $worksheet->write($a_row, 0, $this->lng->txt("login"));
345 
346  $labels = $this->getSelectableColumns();
347  $cnt = 1;
348  foreach ($this->getSelectedColumns() as $c)
349  {
350  if(substr($c, 0, 4) == "obj_")
351  {
352  $obj_id = substr($c, 4);
353  $type = $ilObjDataCache->lookupType($obj_id);
354  $worksheet->write($a_row, $cnt, "(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
355  }
356  else
357  {
358  $worksheet->write($a_row, $cnt, $labels[$c]["txt"]);
359  }
360  $cnt++;
361  }
362  }
363 
364  protected function fillRowExcel($worksheet, &$a_row, $a_set)
365  {
366  $worksheet->write($a_row, 0, $a_set["login"]);
367 
368  $cnt = 1;
369  foreach ($this->getSelectedColumns() as $c)
370  {
371  if(in_array($c, array('last_access', 'spent_seconds')))
372  {
373  $val = $this->parseValue($c, $a_set[$c], "user");
374  }
375  else if(substr($c, 0, 4) == "obj_")
376  {
377  $obj_id = substr($c, 4);
378  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
379  }
380  else
381  {
382  $obj_id = substr($c, 6);
383  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
384  }
385  $worksheet->write($a_row, $cnt, $val);
386  $cnt++;
387  }
388  }
389 
390  protected function fillHeaderCSV($a_csv)
391  {
392  global $ilObjDataCache;
393 
394  $a_csv->addColumn($this->lng->txt("login"));
395 
396  $labels = $this->getSelectableColumns();
397  foreach ($this->getSelectedColumns() as $c)
398  {
399  if(substr($c, 0, 4) == "obj_")
400  {
401  $obj_id = substr($c, 4);
402  $type = $ilObjDataCache->lookupType($obj_id);
403  $a_csv->addColumn("(".$this->lng->txt($type).") ".$labels[$c]["txt"]);
404  }
405  else
406  {
407  $a_csv->addColumn($labels[$c]["txt"]);
408  }
409  }
410 
411  $a_csv->addRow();
412  }
413 
414  protected function fillRowCSV($a_csv, $a_set)
415  {
416  $a_csv->addColumn($a_set["login"]);
417 
418  foreach ($this->getSelectedColumns() as $c)
419  {
420  if(in_array($c, array('last_access', 'spent_seconds')))
421  {
422  $val = $this->parseValue($c, $a_set[$c], "user");
423  }
424  else if(substr($c, 0, 4) == "obj_")
425  {
426  $obj_id = substr($c, 4);
427  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
428  }
429  else
430  {
431  $obj_id = substr($c, 6);
432  $val = ilLearningProgressBaseGUI::_getStatusText((int)$a_set["objects"][$obj_id]["status"]);
433  }
434  $a_csv->addColumn($val);
435  }
436 
437  $a_csv->addRow();
438  }
439 }
440 
441 ?>