ILIAS  release_8 Revision v8.24
class.ilSCORMExplorer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
21{
26
27 public function __construct(string $a_target, ilObjSCORMLearningModule &$a_slm_obj)
28 {
29 parent::__construct($a_target);
30 $this->slm_obj = $a_slm_obj;
31 $this->tree = new ilSCORMTree($a_slm_obj->getId());
32 $this->root_id = $this->tree->readRootId();
33 $this->checkPermissions(false);
34 $this->outputIcons(true);
35 $this->setOrderColumn("");
36 }
37
38 public function getItem(int $a_node_id): \ilSCORMItem
39 {
40 return new ilSCORMItem($a_node_id);
41 }
42
43 public function getIconImagePathPrefix(): string
44 {
45 return "scorm/";
46 }
47
48 public function getNodesToSkip(): int
49 {
50 return 2;
51 }
52
57 public function formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option): void //Missing typehint because ilExplorer
58 {
59 global $DIC;
60 $lng = $DIC->language();
61
62 $tpl = new ilTemplate("tpl.tree.html", true, true, "Services/UIComponent/Explorer");
63
64 $tpl->setCurrentBlock("row");
65 $tpl->setVariable("TITLE", $lng->txt("cont_manifest"));
66 $tpl->setVariable("LINK_TARGET", $this->target . "&" . $this->target_get . "=" . $a_obj_id);
67 $tpl->setVariable("TARGET", " target=\"" . $this->frame_target . "\"");
69
70 $this->output .= $tpl->get();
71 }
72
76 public function createTarget(string $a_type, $a_node_id, bool $a_highlighted_subtree = false, bool $a_append_anch = true): string //Missing typehint because ilExplorer
77 {
78 // SET expand parameter:
79 // positive if object is expanded
80 // negative if object is compressed
81 $a_node_id = ($a_type == '+')
82 ? $a_node_id
83 : -(int) $a_node_id;
84
85 return $_SERVER["PATH_INFO"] . "?cmd=explorer&ref_id=" . $this->slm_obj->getRefId() . "&scexpand=" . $a_node_id; //ToDo $_SERVER?
86 }
87
88 public function setOutput($a_parent_id, int $a_depth = 1, int $a_obj_id = 0, $a_highlighted_subtree = false): void
89 // public function setOutput(int $a_parent_id, int $a_depth = 1, int $a_obj_id = 0, bool $a_highlighted_subtree = false) : void
90 {
91 $this->format_options = $this->createOutputArray($a_parent_id);
92 }
93
98 protected function createOutputArray(int $a_parent_id, array $options = array()): array
99 {
100 global $ilErr;
101 $types_do_not_display = array("sos", "sma");
102 $types_do_not_load = array("srs");
103
104 if (!isset($a_parent_id)) {
105 $ilErr->raiseError(get_class($this) . "::setOutput(): No node_id given!", $ilErr->error_obj->WARNING);
106 }
107
108 if (!$this->showChilds($a_parent_id)) {
109 return array();
110 }
111
112 foreach ($this->tree->getChilds($a_parent_id, $this->order_column) as $key => $child) {
113 if (in_array($child["c_type"], $types_do_not_load)) {
114 continue;
115 }
116
117 $option = array();
118 $option["parent"] = $child["parent"];
119 $option["id"] = $child["child"];
120 $option["title"] = $child["title"];
121 $option["c_type"] = $child["c_type"];
122 $option["obj_id"] = $child["obj_id"];
123 $option["desc"] = "obj_" . $child["c_type"];
124 $option["container"] = false;
125 $option["visible"] = !in_array($child["c_type"], $types_do_not_display);
126
127 if ($this->showChilds($option["id"])) {
128 $option = $this->createOutputArray((int) $option["id"], $option);
129 }
130
131 $options["childs"][] = $option;
132 }
133
134 return $options;
135 }
136
137 public function isVisible($a_ref_id, string $a_type): bool //Typehint not possible now - see ilExplorer
138 {
139 return $a_type !== "sre";
140 }
141
146 public function getOutput(bool $jsApi = false): string
147 {
148 return $this->createOutput($this->format_options, $jsApi)->get();
149 }
150
155 public function createOutput(array $option, bool $jsApi): \ilTemplate
156 {
157 global $DIC;
158 $ilBench = $DIC['ilBench'];
159
160 if (isset($option["visible"]) && $option["visible"] == true) {
161 $tpl = new ilTemplate("tpl.sahs_tree_ul.html", true, true, "Modules/ScormAicc");
162 $tpl = $this->insertObject($option, $tpl, $jsApi);
163 } else {
164 $tpl = new ilTemplate("tpl.sahs_tree_free.html", true, true, "Modules/ScormAicc");
165 }
166
167 if (isset($option["childs"]) && is_array($option["childs"]) && count($option["childs"]) > 0) {
168 foreach ($option["childs"] as $key => $ch_option) {
169 $tpl->setCurrentBlock("childs");
170 $tpl->setVariable("CHILDS", $this->createOutput($ch_option, $jsApi)->get());
172 }
173 }
174
175 return $tpl;
176 }
177
181 public function isClickable(string $type, int $ref_id = 0): bool
182 {
183 if ($type !== "sit") {
184 return false;
185 }
186
187 $sc_object = new ilSCORMItem($ref_id);
188 return $sc_object->getIdentifierRef() != "";
189 }
190
195 protected function insertObject(array $option, ilTemplate $tpl, bool $jsApi): \ilTemplate
196 {
197 global $ilErr;
198 if (!is_array($option) || !isset($option["id"])) {
199 $ilErr->raiseError(get_class($this) . "::insertObject(): Missing parameter or wrong datatype! " .
200 "options:" . var_dump($option), $ilErr->error_obj->WARNING);
201 }
202 $clickable = false;
203 if ($option["c_type"] == "sit") {
204 //get scorm item
205 $sc_object = new ilSCORMItem((int) $option["id"]);
206 $id_ref = $sc_object->getIdentifierRef();
207
208 //get scorm resource ref id
209 $sc_res_id = ilSCORMResource::_lookupIdByIdRef($id_ref, $sc_object->getSLMId());
210
211 //get scorm type
212 $scormtype = strtolower(ilSCORMResource::_lookupScormType($sc_res_id));
213
214 //is scorm clickabke
215 $clickable = $this->isClickable($option["c_type"], (int) $option["id"]);
216
217 if ($this->output_icons && $clickable) {
218 $this->getOutputIcons($tpl, $option, (int) $option["id"], $scormtype);
219 }
220 }
221 if ($clickable) { // output link
222 $tpl->setCurrentBlock("link");
223 $frame_target = $this->buildFrameTarget($option["c_type"], $option["id"], $option["obj_id"]);
224 if ($frame_target != "") {
225 $tpl->setVariable("TITLE", ilStr::shortenTextExtended($option["title"], $this->textwidth, true));
226 $tpl->setVariable("LINK_TARGET", "javascript:void(0);");
227 if ($jsApi == true) {
228 $tpl->setVariable("ONCLICK", " onclick=\"parent.API.IliasLaunch('" . $option["id"] . "');return false;\"");
229 } else {
230 $tpl->setVariable("ONCLICK", " onclick=\"parent.APIFRAME.setupApi();parent.APIFRAME.API."
231 . ($scormtype === 'asset' ? 'IliasLaunchAsset' : 'IliasLaunchSahs')
232 . "('" . $option["id"] . "');return false;\"");
233 }
234 }
236 } else { // output text only
237 $tpl->setCurrentBlock("text");
238 $tpl->setVariable("OBJ_TITLE", ilStr::shortenTextExtended($option["title"], $this->textwidth, true));
240 }
241
242 $tpl->setCurrentBlock("li");
244
245 return $tpl;
246 }
247
252 public function getOutputIcons(\ilTemplate $tpl, array $a_option, int $a_node_id, string $scormtype = "sco"): void
253 {
254 global $DIC;
255 $lng = $DIC->language();
256
257 $tpl->setCurrentBlock("icon");
258
259 if ($scormtype === 'asset') {
260 $tpl->setVariable('ICON_IMAGE', ilUtil::getImagePath($this->getIconImagePathPrefix() . "asset.svg"));
261 $tpl->setVariable('TXT_ALT_IMG', '');
263 return;
264 }
265
267 $a_node_id,
268 0,
269 $this->slm_obj->getId()
270 );
271
272 // status
273 $status = !isset($trdata["cmi.core.lesson_status"])
274 ? "not attempted"
275 : $trdata["cmi.core.lesson_status"];
276
277 $statusChar = strtolower($status[0]);
278 if ($statusChar === "f") {
279 $status = "failed";
280 } elseif ($statusChar === "b") {
281 $status = "browsed";
282 } elseif ($statusChar === "c") {
283 $status = "completed";
284 } elseif ($statusChar === "n") {
285 $status = "not_attempted";
286 } elseif ($statusChar === "p") {
287 $status = "passed";
288 } elseif ($statusChar === "r") {
289 $status = "running";
290 }
291
292 $alt = $lng->txt("cont_status") . ": " .
293 $lng->txt("cont_sc_stat_" . str_replace(" ", "_", $status));
294
295 // score
296 if (isset($trdata["cmi.core.score.raw"])) {
297 $alt .= ", " . $lng->txt("cont_credits") .
298 ": " . $trdata["cmi.core.score.raw"];
299 }
300
301 // total time
302 if (isset($trdata["cmi.core.total_time"]) &&
303 $trdata["cmi.core.total_time"] !== "0000:00:00.00") {
304 $alt .= ", " . $lng->txt("cont_total_time") .
305 ": " . $trdata["cmi.core.total_time"];
306 }
307
308 $tpl->setVariable("ICON_NAME", 'scoIcon' . $a_node_id);
309 $tpl->setVariable("ICON_IMAGE", ilUtil::getImagePath($this->getIconImagePathPrefix() . str_replace(" ", "_", $status) . ".svg"));
310 $tpl->setVariable("TXT_ALT_IMG", $alt);
312 }
313}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
class for explorer view in admin frame
setOrderColumn(string $a_column)
showChilds($a_parent_id)
determines wether the childs of an object should be shown or not note: this standard implementation a...
checkPermissions(bool $a_check)
buildFrameTarget(string $a_type, $a_child=0, $a_obj_id=0)
outputIcons(bool $a_icons)
string $frame_target
ilLanguage $lng
ilGlobalTemplateInterface $tpl
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getOutputIcons(\ilTemplate $tpl, array $a_option, int $a_node_id, string $scormtype="sco")
tpl is filled with option state
createTarget(string $a_type, $a_node_id, bool $a_highlighted_subtree=false, bool $a_append_anch=true)
Creates Get Parameter.
formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option)
overwritten method from base class
createOutput(array $option, bool $jsApi)
recursive creation of output templates
isVisible($a_ref_id, string $a_type)
ilObjSCORMLearningModule $slm_obj
id of root folder
createOutputArray(int $a_parent_id, array $options=array())
recursive creating of outputs
getItem(int $a_node_id)
isClickable(string $type, int $ref_id=0)
can i click on the module name
setOutput($a_parent_id, int $a_depth=1, int $a_obj_id=0, $a_highlighted_subtree=false)
getOutput(bool $jsApi=false)
Creates output template.
__construct(string $a_target, ilObjSCORMLearningModule &$a_slm_obj)
insertObject(array $option, ilTemplate $tpl, bool $jsApi)
insert the option data in $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTrackingDataOfUser(int $a_item_id, int $a_user_id=0, int $a_obj_id=0)
static _lookupIdByIdRef(string $a_id_ref, int $a_slm_id)
static _lookupScormType(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
special template class to simplify handling of ITX/PEAR
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$ref_id
Definition: ltiauth.php:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$type
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$ilErr
Definition: raiseError.php:17