ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSCORMExplorer.php
Go to the documentation of this file.
1<?php
2
19declare(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, "components/ILIAS/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
97 protected function createOutputArray(int $a_parent_id, array $options = array()): array
98 {
99 global $ilErr;
100 $types_do_not_display = array("sos", "sma");
101 $types_do_not_load = array("srs");
102
103 if (!isset($a_parent_id)) {
104 $ilErr->raiseError(get_class($this) . "::setOutput(): No node_id given!", $ilErr->error_obj->WARNING);
105 }
106
107 if (!$this->showChilds($a_parent_id)) {
108 return array();
109 }
110
111 foreach ($this->tree->getChilds($a_parent_id, $this->order_column) as $key => $child) {
112 if (in_array($child["c_type"], $types_do_not_load)) {
113 continue;
114 }
115
116 $option = array();
117 $option["parent"] = $child["parent"];
118 $option["id"] = $child["child"];
119 $option["title"] = $child["title"];
120 $option["c_type"] = $child["c_type"];
121 $option["obj_id"] = $child["obj_id"];
122 $option["desc"] = "obj_" . $child["c_type"];
123 $option["container"] = false;
124 $option["visible"] = !in_array($child["c_type"], $types_do_not_display);
125
126 if ($this->showChilds($option["id"])) {
127 $option = $this->createOutputArray((int) $option["id"], $option);
128 }
129
130 $options["childs"][] = $option;
131 }
132
133 return $options;
134 }
135
136 public function isVisible($a_ref_id, string $a_type): bool //Typehint not possible now - see ilExplorer
137 {
138 return $a_type !== "sre";
139 }
140
145 public function getOutput(bool $jsApi = false): string
146 {
147 return $this->createOutput($this->format_options, $jsApi)->get();
148 }
149
154 public function createOutput(array $option, bool $jsApi): \ilTemplate
155 {
156 global $DIC;
157 $ilBench = $DIC['ilBench'];
158
159 if (isset($option["visible"]) && $option["visible"] == true) {
160 $tpl = new ilTemplate("tpl.sahs_tree_ul.html", true, true, "components/ILIAS/ScormAicc");
161 $tpl = $this->insertObject($option, $tpl, $jsApi);
162 } else {
163 $tpl = new ilTemplate("tpl.sahs_tree_free.html", true, true, "components/ILIAS/ScormAicc");
164 }
165
166 if (isset($option["childs"]) && is_array($option["childs"]) && count($option["childs"]) > 0) {
167 foreach ($option["childs"] as $key => $ch_option) {
168 $tpl->setCurrentBlock("childs");
169 $tpl->setVariable("CHILDS", $this->createOutput($ch_option, $jsApi)->get());
171 }
172 }
173
174 return $tpl;
175 }
176
180 public function isClickable(string $type, int $ref_id = 0): bool
181 {
182 if ($type !== "sit") {
183 return false;
184 }
185
186 $sc_object = new ilSCORMItem($ref_id);
187 return $sc_object->getIdentifierRef() != "";
188 }
189
194 protected function insertObject(array $option, ilTemplate $tpl, bool $jsApi): \ilTemplate
195 {
196 global $ilErr;
197 if (!is_array($option) || !isset($option["id"])) {
198 $ilErr->raiseError(get_class($this) . "::insertObject(): Missing parameter or wrong datatype! " .
199 "options:" . var_dump($option), $ilErr->error_obj->WARNING);
200 }
201 $clickable = false;
202 if ($option["c_type"] == "sit") {
203 //get scorm item
204 $sc_object = new ilSCORMItem((int) $option["id"]);
205 $id_ref = $sc_object->getIdentifierRef();
206
207 //get scorm resource ref id
208 $sc_res_id = ilSCORMResource::_lookupIdByIdRef($id_ref, $sc_object->getSLMId());
209
210 //get scorm type
211 $scormtype = strtolower(ilSCORMResource::_lookupScormType($sc_res_id));
212
213 //is scorm clickabke
214 $clickable = $this->isClickable($option["c_type"], (int) $option["id"]);
215
216 if ($this->output_icons && $clickable) {
217 $this->getOutputIcons($tpl, $option, (int) $option["id"], $scormtype);
218 }
219 }
220 if ($clickable) { // output link
221 $tpl->setCurrentBlock("link");
222 $frame_target = $this->buildFrameTarget($option["c_type"], $option["id"], $option["obj_id"]);
223 if ($frame_target != "") {
224 $tpl->setVariable("TITLE", ilStr::shortenTextExtended($option["title"], $this->textwidth, true));
225 $tpl->setVariable("LINK_TARGET", "javascript:void(0);");
226 if ($jsApi == true) {
227 $tpl->setVariable("ONCLICK", " onclick=\"parent.API.IliasLaunch('" . $option["id"] . "');return false;\"");
228 } else {
229 $tpl->setVariable("ONCLICK", " onclick=\"parent.APIFRAME.setupApi();parent.APIFRAME.API."
230 . ($scormtype === 'asset' ? 'IliasLaunchAsset' : 'IliasLaunchSahs')
231 . "('" . $option["id"] . "');return false;\"");
232 }
233 }
235 } else { // output text only
236 $tpl->setCurrentBlock("text");
237 $tpl->setVariable("OBJ_TITLE", ilStr::shortenTextExtended($option["title"], $this->textwidth, true));
239 }
240
241 $tpl->setCurrentBlock("li");
243
244 return $tpl;
245 }
246
251 public function getOutputIcons(\ilTemplate $tpl, array $a_option, int $a_node_id, string $scormtype = "sco"): void
252 {
253 global $DIC;
254 $lng = $DIC->language();
255
256 $tpl->setCurrentBlock("icon");
257
258 if ($scormtype === 'asset') {
259 $tpl->setVariable('ICON_IMAGE', ilUtil::getImagePath($this->getIconImagePathPrefix() . "asset.svg"));
260 $tpl->setVariable('TXT_ALT_IMG', '');
262 return;
263 }
264
266 $a_node_id,
267 0,
268 $this->slm_obj->getId()
269 );
270
271 // status
272 $status = !isset($trdata["cmi.core.lesson_status"])
273 ? "not attempted"
274 : $trdata["cmi.core.lesson_status"];
275
276 $statusChar = strtolower($status[0]);
277 if ($statusChar === "f") {
278 $status = "failed";
279 } elseif ($statusChar === "b") {
280 $status = "browsed";
281 } elseif ($statusChar === "c") {
282 $status = "completed";
283 } elseif ($statusChar === "n") {
284 $status = "not_attempted";
285 } elseif ($statusChar === "p") {
286 $status = "passed";
287 } elseif ($statusChar === "r") {
288 $status = "running";
289 }
290
291 $alt = $lng->txt("cont_status") . ": " .
292 $lng->txt("cont_sc_stat_" . str_replace(" ", "_", $status));
293
294 // score
295 if (isset($trdata["cmi.core.score.raw"])) {
296 $alt .= ", " . $lng->txt("cont_credits") .
297 ": " . $trdata["cmi.core.score.raw"];
298 }
299
300 // total time
301 if (isset($trdata["cmi.core.total_time"]) &&
302 $trdata["cmi.core.total_time"] !== "0000:00:00.00") {
303 $alt .= ", " . $lng->txt("cont_total_time") .
304 ": " . $trdata["cmi.core.total_time"];
305 }
306
307 $tpl->setVariable("ICON_NAME", 'scoIcon' . $a_node_id);
308 $tpl->setVariable("ICON_IMAGE", ilUtil::getImagePath($this->getIconImagePathPrefix() . str_replace(" ", "_", $status) . ".svg"));
309 $tpl->setVariable("TXT_ALT_IMG", $alt);
311 }
312}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
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...
Class ilObjSCORMLearningModule.
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
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)
SCORM Object Tree.
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 $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$ilErr
Definition: raiseError.php:33
global $DIC
Definition: shib_login.php:26