ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORMExplorer.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 /*
25 * Explorer View for SCORM Learning Modules
26 *
27 * @author Alex Killing <alex.killing@gmx.de>
28 * @version $Id: class.ilSCORMExplorer.php 31725 2011-11-17 09:40:21Z hschottm $
29 *
30 * @ingroup ModulesScormAicc
31 */
32 
33 require_once("classes/class.ilExplorer.php");
34 require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
35 
37 {
38 
44  var $slm_obj;
45 
52  function ilSCORMExplorer($a_target, &$a_slm_obj)
53  {
54  parent::ilExplorer($a_target);
55  $this->slm_obj =& $a_slm_obj;
56  $this->tree = new ilSCORMTree($a_slm_obj->getId());
57  $this->root_id = $this->tree->readRootId();
58  $this->checkPermissions(false);
59  $this->outputIcons(true);
60  $this->setOrderColumn("");
61  }
62 
63  function getItem($a_node_id) {
64  return new ilSCORMItem($a_node_id);
65  }
66 
68  return "scorm/";
69  }
70 
71  function getNodesToSkip() {
72  return 2;
73  }
74 
75 
82  function formatHeader($a_obj_id,$a_option)
83  {
84  global $lng, $ilias;
85 
86  $tpl = new ilTemplate("tpl.tree.html", true, true);
87 
88  $tpl->setCurrentBlock("row");
89  //$tpl->setVariable("TYPE", $a_option["c_type"]);
90  //$tpl->setVariable("ICON_IMAGE" ,ilUtil::getImagePath("icon_".$a_option["c_type"].".gif"));
91  $tpl->setVariable("TITLE", $lng->txt("cont_manifest"));
92  $tpl->setVariable("LINK_TARGET", $this->target."&".$this->target_get."=".$a_obj_id);
93  $tpl->setVariable("TARGET", " target=\"".$this->frame_target."\"");
94  $tpl->parseCurrentBlock();
95 
96  $this->output[] = $tpl->get();
97  }
98 
99 
107  function createTarget($a_type,$a_child)
108  {
109  // SET expand parameter:
110  // positive if object is expanded
111  // negative if object is compressed
112  $a_child = ($a_type == '+')
113  ? $a_child
114  : -(int) $a_child;
115 
116  return $_SERVER["PATH_INFO"]."?cmd=explorer&ref_id=".$this->slm_obj->getRefId()."&scexpand=".$a_child;
117  }
118 
119  function setOutput($a_parent_id, $a_depth = 0)
120  {
121 
122  global $rbacadmin, $rbacsystem;
123  static $counter = 0;
124 
125  //echo "setOutput <br>";
126 
127  if (!isset($a_parent_id))
128  {
129  $this->ilias->raiseError(get_class($this)."::setOutput(): No node_id given!",$this->ilias->error_obj->WARNING);
130  }
131 
132  if ($this->showChilds($a_parent_id))
133  {
134  $objects = $this->tree->getChilds($a_parent_id, $this->order_column);
135  }
136  else
137  {
138  $objects = array();
139  }
140 
141  if (count($objects) > 0)
142  {
143 
144  //moved the scorm-only constant parameter to a function
145  //to be able to reuse the code
146  //$tab = ++$a_depth - 2;
147  $tab = ++$a_depth - $this->getNodesToSkip();
148 
149 
150  // Maybe call a lexical sort function for the child objects
151 
152  //666if ($this->post_sort)
153  //{
154  //$objects = $this->sortNodes($objects);
155  //}
156 
157  foreach ($objects as $key => $object)
158  {
159  //ask for FILTER
160  if ($this->filtered == false or $this->checkFilter($object["c_type"]) == false)
161  {
162  if ($this->isVisible($object["obj_id"], $object["c_type"]))
163  {
164  if ($object["child"] != $this->tree->getRootId())
165  {
166  $parent_index = $this->getIndex($object);
167  }
168  $this->format_options["$counter"]["parent"] = $object["parent"];
169  $this->format_options["$counter"]["child"] = $object["child"];
170  $this->format_options["$counter"]["title"] = $object["title"];
171  $this->format_options["$counter"]["c_type"] = $object["c_type"];
172  $this->format_options["$counter"]["obj_id"] = $object["obj_id"];
173  $this->format_options["$counter"]["desc"] = "obj_".$object["c_type"];
174  $this->format_options["$counter"]["depth"] = $tab;
175  $this->format_options["$counter"]["container"] = false;
176  $this->format_options["$counter"]["visible"] = true;
177 
178  // Create prefix array
179  for ($i = 0; $i < $tab; ++$i)
180  {
181  $this->format_options["$counter"]["tab"][] = 'blank';
182  }
183 
184  if ($object["c_type"]=="sos")
185  $this->setExpand($object["obj_id"]);
186 
187  // fix explorer (sometimes explorer disappears)
188  if ($parent_index == 0)
189  {
190  if (!$this->expand_all and !in_array($object["parent"],$this->expanded))
191  {
192  $this->expanded[] = $object["parent"];
193  }
194  //$this->format_options["$parent_index"]["visible"] = true;
195  }
196 
197  if ($object["child"] != $this->tree->getRootId() and (!$this->expand_all and !in_array($object["parent"],$this->expanded)
198  or !$this->format_options["$parent_index"]["visible"]))
199  {
200  $this->format_options["$counter"]["visible"] = false;
201  }
202 
203  // if object exists parent is container
204  if ($object["child"] != $this->tree->getRootId())
205  {
206  $this->format_options["$parent_index"]["container"] = true;
207 
208  if ($this->expand_all or in_array($object["parent"],$this->expanded))
209  {
210  $this->format_options["$parent_index"]["tab"][($tab-2)] = 'minus';
211  }
212  else
213  {
214  $this->format_options["$parent_index"]["tab"][($tab-2)] = 'plus';
215  }
216  }
217 
218  ++$counter;
219 
220  // stop recursion if 2. level beyond expanded nodes is reached
221  if ($this->expand_all or in_array($object["parent"],$this->expanded) or ($object["parent"] == 0))
222  {
223  // recursive
224  $this->setOutput($object["child"],$a_depth);
225  }
226  } //if
227  } //if FILTER
228  } //foreach
229  } //if
230  } //function
231 
232  function isVisible($a_id, $a_type)
233  {
234  if ($a_type == "sre")
235  {
236  return false;
237  }
238  else
239  {
240  return true;
241  }
242  }
243 
250  function getOutput($jsApi = false)
251  {
252  global $ilBench;
253 
254  //echo "getOutput <br>";
255  $this->format_options[0]["tab"] = array();
256 
257  $depth = $this->tree->getMaximumDepth();
258 
259  for ($i=0;$i<$depth;++$i)
260  {
261  $this->createLines($i);
262  }
263 
264  foreach ($this->format_options as $key => $options)
265  {
266  if ($options["visible"] and $key != 0)
267  {
268  $ilBench->start("SCORMExplorer", "formatObject");
269  $this->formatObject($options["child"],$options,$jsApi);
270  $ilBench->stop("SCORMExplorer", "formatObject");
271  }
272  }
273 
274  return implode('',$this->output);
275  }
276 
277  function isClickable($a_type, $a_id = 0, $a_obj = 0)
278  {
279  if ($a_type != "sit")
280  {
281  return false;
282  }
283  else
284  {
285  if (is_object($a_obj))
286  {
287  $sc_object =& $a_obj;
288  }
289  else
290  {
291  $sc_object =& new ilSCORMItem($a_id);
292  }
293  if ($sc_object->getIdentifierRef() != "")
294  {
295  return true;
296  }
297  }
298  return false;
299  }
300 
301  function formatItemTable(&$tpl, $a_id, $a_type)
302  {
303  global $lng;
304 
305  }
306 
315  function formatObject($a_node_id,$a_option,$jsApi)
316  {
317  global $lng, $ilBench;
318 
319  //echo "scorm: ".$a_option["title"]." >> ".implode(", ",$a_option["tab"])."<br>";
320 
321  if (!isset($a_node_id) or !is_array($a_option))
322  {
323  $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
324  "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
325  }
326 
327  $tpl = new ilTemplate("tpl.sahs_tree.html", true, true, "Modules/ScormAicc");
328 
329  if ($a_option["c_type"]=="sos")
330  return;
331 
332  if ($a_option["c_type"]=="srs")
333  return;
334 
335  $ilBench->start("SCORMExplorer", "renderIcons");
336  if (is_array($a_option["tab"])) { //test if there are any tabs
337  foreach ($a_option["tab"] as $picture)
338  {
339  if ($picture == 'plus')
340  {
341  $target = $this->createTarget('+',$a_node_id);
342  $tpl->setCurrentBlock("expander");
343  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
344  $tpl->setVariable("IMGPATH", ilUtil::getImagePath("browser/plus.gif"));
345  $tpl->parseCurrentBlock();
346  }
347 
348  if ($picture == 'minus' && $this->show_minus)
349  {
350  $target = $this->createTarget('-',$a_node_id);
351  $tpl->setCurrentBlock("expander");
352  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
353  $tpl->setVariable("IMGPATH", ilUtil::getImagePath("browser/minus.gif"));
354  $tpl->parseCurrentBlock();
355  }
356 
357  if ($picture == 'blank' or $picture == 'winkel'
358  or $picture == 'hoch' or $picture == 'quer' or $picture == 'ecke')
359  {
360  $picture = 'blank';
361  $tpl->setCurrentBlock("lines");
362  $tpl->setVariable("IMGPATH_LINES", ilUtil::getImagePath("browser/".$picture.".gif"));
363  $tpl->parseCurrentBlock();
364  }
365  }
366  }
367  $ilBench->stop("SCORMExplorer", "renderIcons");
368 
369  $ilBench->start("SCORMExplorer", "initSCORMItem");
370  $sc_object =& new ilSCORMItem($a_node_id);
371  $id_ref = $sc_object->getIdentifierRef();
372  $ilBench->stop("SCORMExplorer", "initSCORMItem");
373 
374  $ilBench->start("SCORMExplorer", "initResource");
375  //$sc_res =& new ilSCORMResource();
376  $sc_res_id = ilSCORMResource::_lookupIdByIdRef($id_ref, $sc_object->getSLMId());
377  $ilBench->stop("SCORMExplorer", "initResource");
378 
379  $scormtype = strtolower(ilSCORMResource::_lookupScormType($sc_res_id));
380 
381  $ilBench->start("SCORMExplorer", "renderLink");
382  $ilBench->start("SCORMExplorer", "renderLink_OutputIcons");
383  if ($this->output_icons)
384  {
385  if ($this->isClickable($a_option["c_type"], $a_node_id, $sc_object))
386  {
387  $this->getOutputIcons($tpl, $a_option, $a_node_id, $scormtype);
388  }
389  }
390  $ilBench->stop("SCORMExplorer", "renderLink_OutputIcons");
391 
392  if ($this->isClickable($a_option["c_type"], $a_node_id, $sc_object)) // output link
393  {
394  $ilBench->start("SCORMExplorer", "renderLink_parseLinkBlock");
395  $tpl->setCurrentBlock("link");
396  $frame_target = $this->buildFrameTarget($a_option["c_type"], $a_node_id, $a_option["obj_id"]);
397  if ($frame_target != "")
398  {
399  $tpl->setVariable("TITLE", ilUtil::shortenText($a_option["title"], $this->textwidth, true));
400  $tpl->setVariable("LINK_TARGET", "javascript:void(0);");
401  if ($jsApi == true) {
402  $tpl->setVariable("ONCLICK", " onclick=\"parent.API.IliasLaunch('".$a_node_id."');return false;\"");
403  } else {
404  $tpl->setVariable("ONCLICK", " onclick=\"parent.APIFRAME.setupApi();parent.APIFRAME.API."
405  .($scormtype == 'asset' ? 'IliasLaunchAsset' : 'IliasLaunchSahs')
406  ."('".$a_node_id."');return false;\"");
407  }
408  }
409  $tpl->parseCurrentBlock();
410  $ilBench->stop("SCORMExplorer", "renderLink_parseLinkBlock");
411  }
412  else // output text only
413  {
414  $tpl->setCurrentBlock("text");
415  $tpl->setVariable("OBJ_TITLE", ilUtil::shortenText($a_option["title"], $this->textwidth, true));
416  $tpl->parseCurrentBlock();
417  }
418  $ilBench->stop("SCORMExplorer", "renderLink");
419 
420  $ilBench->start("SCORMExplorer", "formatItemTable");
421  $this->formatItemTable($tpl, $a_node_id, $a_option["c_type"]);
422  $ilBench->stop("SCORMExplorer", "formatItemTable");
423 
424  $tpl->setCurrentBlock("row");
425  $tpl->parseCurrentBlock();
426 
427  $this->output[] = $tpl->get();
428  }
429 
430  function getOutputIcons(&$tpl, $a_option, $a_node_id, $scormtype="sco")
431  {
432  global $lng;
433 
434  $tpl->setCurrentBlock("icon");
435 
436  if ($scormtype == 'asset')
437  {
438  $tpl->setVariable('ICON_IMAGE', ilUtil::getImagePath($this->getIconImagePathPrefix()."asset.gif"));
439  $tpl->setVariable('TXT_ALT_IMG', '');
440  $tpl->parseCurrentBlock();
441  return;
442  }
443 
444  $trdata = ilSCORMItem::_lookupTrackingDataOfUser($a_node_id, 0,
445  $this->slm_obj->getId());
446 
447  // status
448  $status = ($trdata["cmi.core.lesson_status"] == "")
449  ? "not attempted"
450  : $trdata["cmi.core.lesson_status"];
451 
452  $statusChar=strtolower(substr($status,0,1));
453  if ($statusChar=="f")
454  $status="failed";
455  else if ($statusChar=="b")
456  $status="browsed";
457  else if ($statusChar=="c")
458  $status="completed";
459  else if ($statusChar=="n")
460  $status="not_attempted";
461  else if ($statusChar=="p")
462  $status="passed";
463  else if ($statusChar=="r")
464  $status="running";
465 
466  $alt = $lng->txt("cont_status").": ".
467  $lng->txt("cont_sc_stat_".str_replace(" ", "_", $status));
468 
469  // score
470  if ($trdata["cmi.core.score.raw"] != "")
471  {
472  $alt.= ", ".$lng->txt("cont_credits").
473  ": ".$trdata["cmi.core.score.raw"];
474  }
475 
476  // total time
477  if ($trdata["cmi.core.total_time"] != "" &&
478  $trdata["cmi.core.total_time"] != "0000:00:00.00")
479  {
480  $alt.= ", ".$lng->txt("cont_total_time").
481  ": ".$trdata["cmi.core.total_time"];
482  }
483 
484  $tpl->setVariable("ICON_NAME", 'scoIcon'.$a_node_id);
485  $tpl->setVariable("ICON_IMAGE", ilUtil::getImagePath($this->getIconImagePathPrefix().str_replace(" ", "_", $status).".gif"));
486  $tpl->setVariable("TXT_ALT_IMG", $alt);
487  $tpl->parseCurrentBlock();
488 
489  }
490 }
491 ?>