ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
34 require_once("./Services/UIComponent/Explorer/classes/class.ilExplorer.php");
35 require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
36 
38 {
39 
45  var $slm_obj;
46 
53  function __construct($a_target, &$a_slm_obj)
54  {
55  parent::__construct($a_target);
56  $this->slm_obj = $a_slm_obj;
57  $this->tree = new ilSCORMTree($a_slm_obj->getId());
58  $this->root_id = $this->tree->readRootId();
59  $this->checkPermissions(false);
60  $this->outputIcons(true);
61  $this->setOrderColumn("");
62  }
63 
64  function getItem($a_node_id) {
65  return new ilSCORMItem($a_node_id);
66  }
67 
69  return "scorm/";
70  }
71 
72  function getNodesToSkip() {
73  return 2;
74  }
75 
76 
83  function formatHeader($tpl,$a_obj_id,$a_option)
84  {
85  global $lng, $ilias;
86 
87  $tpl = new ilTemplate("tpl.tree.html", true, true, "Services/UIComponent/Explorer");
88 
89  $tpl->setCurrentBlock("row");
90  $tpl->setVariable("TITLE", $lng->txt("cont_manifest"));
91  $tpl->setVariable("LINK_TARGET", $this->target."&".$this->target_get."=".$a_obj_id);
92  $tpl->setVariable("TARGET", " target=\"".$this->frame_target."\"");
93  $tpl->parseCurrentBlock();
94 
95  $this->output[] = $tpl->get();
96  }
97 
105  function createTarget($a_type,$a_child, $a_highlighted_subtree = false, $a_append_anch = true)
106  {
107  // SET expand parameter:
108  // positive if object is expanded
109  // negative if object is compressed
110  $a_child = ($a_type == '+')
111  ? $a_child
112  : -(int) $a_child;
113 
114  return $_SERVER["PATH_INFO"]."?cmd=explorer&ref_id=".$this->slm_obj->getRefId()."&scexpand=".$a_child;
115  }
116 
121  public function setOutput ($parent_id, $a_depth = 1, $a_obj_id = 0, $a_highlighted_subtree = false) {
122  $this->format_options = $this->createOutputArray($parent_id);
123  }
124 
132  protected function createOutputArray($a_parent_id, $options = array()) {
133  $types_do_not_display = array("sos", "sma");
134  $types_do_not_load = array("srs");
135 
136  if (!isset($a_parent_id))
137  {
138  $this->ilias->raiseError(get_class($this)."::setOutput(): No node_id given!",$this->ilias->error_obj->WARNING);
139  }
140 
141  if (!$this->showChilds($a_parent_id))
142  {
143  return array();
144  }
145 
146  foreach ($this->tree->getChilds($a_parent_id, $this->order_column) as $key => $child) {
147  if(in_array($child["c_type"], $types_do_not_load)) {
148  continue;
149  }
150 
151  $option = array();
152  $option["parent"] = $child["parent"];
153  $option["id"] = $child["child"];
154  $option["title"] = $child["title"];
155  $option["c_type"] = $child["c_type"];
156  $option["obj_id"] = $child["obj_id"];
157  $option["desc"] = "obj_".$child["c_type"];
158  $option["container"] = false;
159  $option["visible"] = !in_array($child["c_type"], $types_do_not_display);
160 
161  if($this->showChilds($option["id"])) {
162  $option = $this->createOutputArray($option["id"], $option, ++$depth);
163  }
164 
165  $options["childs"][] = $option;
166  }
167 
168  return $options;
169  }
170 
174  function isVisible($a_id, $a_type)
175  {
176  if ($a_type == "sre")
177  {
178  return false;
179  }
180  else
181  {
182  return true;
183  }
184  }
185 
193  function getOutput($jsApi = false)
194  {
195  $output = $this->createOutput($this->format_options, $jsApi);
196 
197  return $output->get();
198  }
199 
208  function createOutput($option, $jsApi) {
209  global $ilBench;
210 
211  if ($option["visible"]) {
212  $tpl = new ilTemplate("tpl.sahs_tree_ul.html", true, true, "Modules/ScormAicc");
213  $tpl = $this->insertObject($option, $tpl, $jsApi);
214  } else {
215  $tpl = new ilTemplate("tpl.sahs_tree_free.html", true, true, "Modules/ScormAicc");
216  }
217 
218  if (count($option["childs"])) {
219  foreach ($option["childs"] as $key => $ch_option) {
220  $tpl->setCurrentBlock("childs");
221  $tpl->setVariable("CHILDS", $this->createOutput($ch_option, $jsApi)->get());
222  $tpl->parseCurrentBlock();
223  }
224  }
225 
226  return $tpl;
227  }
228 
237  function isClickable($a_type, $a_id = 0, $a_obj = 0)
238  {
239  if ($a_type != "sit")
240  {
241  return false;
242  }
243  else
244  {
245  if (is_object($a_obj))
246  {
247  $sc_object = $a_obj;
248  }
249  else
250  {
251  $sc_object = new ilSCORMItem($a_id);
252  }
253  if ($sc_object->getIdentifierRef() != "")
254  {
255  return true;
256  }
257  }
258  return false;
259  }
260 
270  protected function insertObject($option, ilTemplate $tpl, $jsApi) {
271  if (!is_array($option) || !isset($option["id"])) {
272  $this->ilias->raiseError(get_class($this)."::insertObject(): Missing parameter or wrong datatype! ".
273  "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
274  }
275 
276  //get scorm item
277  $sc_object = new ilSCORMItem($option["id"]);
278  $id_ref = $sc_object->getIdentifierRef();
279 
280  //get scorm resource ref id
281  $sc_res_id = ilSCORMResource::_lookupIdByIdRef($id_ref, $sc_object->getSLMId());
282 
283  //get scorm type
284  $scormtype = strtolower(ilSCORMResource::_lookupScormType($sc_res_id));
285 
286  //is scorm clickabke
287  $clickable = $this->isClickable($option["c_type"], $option["id"], $sc_object);
288 
289  if ($this->output_icons && $clickable) {
290  $this->getOutputIcons($tpl, $option, $option["id"], $scormtype);
291  }
292 
293  if ($clickable) // output link
294  {
295  $tpl->setCurrentBlock("link");
296  $frame_target = $this->buildFrameTarget($option["c_type"], $option["id"], $option["obj_id"]);
297  if ($frame_target != "")
298  {
299  $tpl->setVariable("TITLE", ilUtil::shortenText($option["title"], $this->textwidth, true));
300  $tpl->setVariable("LINK_TARGET", "javascript:void(0);");
301  if ($jsApi == true) {
302  $tpl->setVariable("ONCLICK", " onclick=\"parent.API.IliasLaunch('".$option["id"]."');return false;\"");
303  } else {
304  $tpl->setVariable("ONCLICK", " onclick=\"parent.APIFRAME.setupApi();parent.APIFRAME.API."
305  .($scormtype == 'asset' ? 'IliasLaunchAsset' : 'IliasLaunchSahs')
306  ."('".$option["id"]."');return false;\"");
307  }
308  }
309  $tpl->parseCurrentBlock();
310  }
311  else // output text only
312  {
313  $tpl->setCurrentBlock("text");
314  $tpl->setVariable("OBJ_TITLE", ilUtil::shortenText($option["title"], $this->textwidth, true));
315  $tpl->parseCurrentBlock();
316  }
317 
318  $tpl->setCurrentBlock("li");
319  $tpl->parseCurrentBlock();
320 
321  return $tpl;
322  }
323 
332  function getOutputIcons(&$tpl, $a_option, $a_node_id, $scormtype="sco")
333  {
334  global $lng;
335 
336  $tpl->setCurrentBlock("icon");
337 
338  if ($scormtype == 'asset')
339  {
340  $tpl->setVariable('ICON_IMAGE', ilUtil::getImagePath($this->getIconImagePathPrefix()."asset.svg"));
341  $tpl->setVariable('TXT_ALT_IMG', '');
342  $tpl->parseCurrentBlock();
343  return;
344  }
345 
346  $trdata = ilSCORMItem::_lookupTrackingDataOfUser($a_node_id, 0,
347  $this->slm_obj->getId());
348 
349  // status
350  $status = ($trdata["cmi.core.lesson_status"] == "")
351  ? "not attempted"
352  : $trdata["cmi.core.lesson_status"];
353 
354  $statusChar=strtolower(substr($status,0,1));
355  if ($statusChar=="f")
356  $status="failed";
357  else if ($statusChar=="b")
358  $status="browsed";
359  else if ($statusChar=="c")
360  $status="completed";
361  else if ($statusChar=="n")
362  $status="not_attempted";
363  else if ($statusChar=="p")
364  $status="passed";
365  else if ($statusChar=="r")
366  $status="running";
367 
368  $alt = $lng->txt("cont_status").": ".
369  $lng->txt("cont_sc_stat_".str_replace(" ", "_", $status));
370 
371  // score
372  if ($trdata["cmi.core.score.raw"] != "")
373  {
374  $alt.= ", ".$lng->txt("cont_credits").
375  ": ".$trdata["cmi.core.score.raw"];
376  }
377 
378  // total time
379  if ($trdata["cmi.core.total_time"] != "" &&
380  $trdata["cmi.core.total_time"] != "0000:00:00.00")
381  {
382  $alt.= ", ".$lng->txt("cont_total_time").
383  ": ".$trdata["cmi.core.total_time"];
384  }
385 
386  $tpl->setVariable("ICON_NAME", 'scoIcon'.$a_node_id);
387  $tpl->setVariable("ICON_IMAGE", ilUtil::getImagePath($this->getIconImagePathPrefix().str_replace(" ", "_", $status).".svg"));
388  $tpl->setVariable("TXT_ALT_IMG", $alt);
389  $tpl->parseCurrentBlock();
390 
391  }
392 }
393 ?>
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
buildFrameTarget($a_type, $a_child=0, $a_obj_id=0)
get frame target (may be overwritten by derived classes)
createTarget($a_type, $a_child, $a_highlighted_subtree=false, $a_append_anch=true)
Creates Get Parameter private.
insertObject($option, ilTemplate $tpl, $jsApi)
insert the option data in $tpl
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
getOutput($jsApi=false)
Creates output template.
checkPermissions($a_check)
check permissions via rbac
getOutputIcons(&$tpl, $a_option, $a_node_id, $scormtype="sco")
tpl is filled with option state
setOrderColumn($a_column)
set the order column public
static _lookupIdByIdRef($a_id_ref, $a_slm_id)
global $tpl
Definition: ilias.php:8
static _lookupScormType($a_obj_id)
createOutputArray($a_parent_id, $options=array())
recursivi creating of outputs
$a_type
Definition: workflow.php:93
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
setOutput($parent_id, $a_depth=1, $a_obj_id=0, $a_highlighted_subtree=false)
possible output array is set
if(!is_array($argv)) $options
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
SCORM Item.
showChilds($a_parent_id)
determines wether the childs of an object should be shown or not note: this standard implementation a...
redirection script todo: (a better solution should control the processing via a xml file) ...
Explorer View for SCORM Learning Modules.
isClickable($a_type, $a_id=0, $a_obj=0)
can i click on the module name
SCORM Object Tree.
isVisible($a_id, $a_type)
Create styles array
The data for the language used.
Class ilExplorer class for explorer view in admin frame.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
createOutput($option, $jsApi)
recursive creation of output templates
global $lng
Definition: privfeed.php:17
global $ilBench
Definition: ilias.php:18
__construct($a_target, &$a_slm_obj)
Constructor public.
static _lookupTrackingDataOfUser($a_item_id, $a_user_id=0, $a_obj_id=0)
outputIcons($a_icons)
output icons
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...
formatHeader($tpl, $a_obj_id, $a_option)
overwritten method from base class public
readRootId()
read root id from database