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