ILIAS  release_8 Revision v8.24
class.ilLMTOCExplorerGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected string $lang;
27 protected int $highlight_node = 0;
28 protected bool $export_all_languages;
30 protected array $complete_tree = [];
31 protected array $activation_data = [];
32 protected ilSetting $lm_set;
34 protected int $focus_id = 0;
37
42 public function __construct(
43 $a_parent_obj,
44 string $a_parent_cmd,
46 string $a_lang = "-",
47 int $a_focus_id = 0,
48 bool $export_all_languages = false
49 ) {
50 global $DIC;
51
52 $this->service = $service;
53 $this->user = $DIC->user();
54 $this->lm = $service->getLearningModule();
55 $this->linker = $service->getLinker();
56 $this->tracker = $service->getTracker();
57
58 $exp_id = (!$this->getOfflineMode() && $this->lm->getProgressIcons())
59 ? "ilLMProgressTree"
60 : "";
61 parent::__construct($a_parent_obj, $a_parent_cmd, $this->lm, $exp_id);
62 $this->lm_set = new ilSetting("lm");
63 $this->lang = $a_lang;
64 if ($a_focus_id > 0) {
65 $this->setSecondaryHighlightedNodes(array($a_focus_id));
66 }
67 if ($this->lm->getTOCMode() != "pages") {
68 $this->setTypeWhiteList(array("st", "du"));
69 }
70 $this->focus_id = $a_focus_id;
71 $this->export_all_languages = $export_all_languages;
72
73 $this->activation_repo = new ilPageActivationDBRepository();
74
75 $this->initTreeData();
76 }
77
78 protected function initTreeData(): void
79 {
80 $nodes = $this->tree->getCompleteTree();
81 foreach ($nodes as $node) {
82 $this->complete_tree["childs"][$node["parent"]][] = $node;
83 $this->complete_tree["parent"][$node["child"]] = $node["parent"];
84 $this->complete_tree["nodes"][$node["child"]] = $node;
85 }
86
87 $page_ids = array_column($this->complete_tree["nodes"], "child");
88 $this->activation_data = $this->activation_repo->get(
89 "lm",
90 $page_ids,
91 (bool) $this->lm_set->get("time_scheduled_page_activation"),
92 $this->lang
93 );
94 $this->initVisibilityData($this->tree->readRootId());
95 }
96
97 protected function initVisibilityData(
98 int $node_id
99 ): void {
100 $current_node = $this->complete_tree["nodes"][$node_id];
101
102 if (isset($this->complete_tree["childs"][$node_id])) {
103 foreach ($this->complete_tree["childs"][$node_id] as $node) {
104 $this->initVisibilityData($node["child"]);
105 }
106 }
107
108 // pages are visible if they are active or activation info should be shown
109 if ($current_node["type"] == "pg") {
110 $this->complete_tree["visibility"][$node_id] = ($this->activation_data[$node_id]["active"] ||
111 $this->activation_data[$node_id]["show_info"]);
112 } elseif ($current_node["type"] == "st") {
113
114 // make chapters visible as soon as there is one visible child
115 $this->complete_tree["visibility"][$node_id] = false;
116 if (isset($this->complete_tree["childs"][$node_id])) {
117 foreach ($this->complete_tree["childs"][$node_id] as $node) {
118 if (isset($this->complete_tree["visibility"][$node["child"]]) &&
119 $this->complete_tree["visibility"][$node["child"]]) {
120 $this->complete_tree["visibility"][$node_id] = true;
121 }
122 }
123 }
124 } else {
125 $this->complete_tree["visibility"][$node_id] = true;
126 }
127 }
128
129 public function getRootNode(): array
130 {
131 $root_id = $this->getTree()->readRootId();
132 if ($this->focus_id > 0 && $this->getTree()->isInTree($this->focus_id) &&
133 ilLMObject::_lookupType($this->focus_id) == "st") {
134 // $root_id = $this->focus_id;
135 }
136 return $this->getTree()->getNodeData($root_id);
137 }
138
139 public function setTracker(ilLMTracker $a_val): void
140 {
141 $this->tracker = $a_val;
142 }
143
144 public function getTracker(): ilLMTracker
145 {
146 return $this->tracker;
147 }
148
149 public function setHighlightNode(int $a_val): void
150 {
151 $this->highlight_node = $a_val;
152 }
153
154 public function getHighlightNode(): int
155 {
156 return $this->highlight_node;
157 }
158
162 public function isNodeHighlighted($a_node): bool
163 {
164 if ($a_node["child"] == $this->getHighlightNode()) {
165 return true;
166 }
167 return false;
168 }
169
173 public function getNodeContent($a_node): string
174 {
175 if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
176 return $this->service->getPresentationStatus()->getLMPresentationTitle();
177 }
178
179 if ($a_node["type"] == "st") {
181 $a_node["child"],
183 $this->lm->isActiveNumbering(),
184 false,
185 false,
186 $this->lm->getId(),
187 $this->lang,
188 true
189 );
190 } elseif ($a_node["type"] == "pg") {
192 $a_node["child"],
193 $this->lm->getPageHeader(),
194 $this->lm->isActiveNumbering(),
195 (bool) $this->lm_set->get("time_scheduled_page_activation"),
196 true,
197 $this->lm->getId(),
198 $this->lang,
199 true
200 );
201 } elseif ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
202 return $this->lm->getTitle();
203 }
204
205 return $a_node["title"];
206 }
207
208
212 public function getNodeIcon($a_node): string
213 {
214 // overwrite chapter icons with lp info?
215 if (!$this->getOfflineMode() && $a_node["type"] == "st") {
216 $icon = $this->checkLPIcon($a_node["child"]);
217 if ($icon != "") {
218 return $icon;
219 }
220 }
221
222 // use progress icons (does not depend on lp mode)
223 if (!$this->getOfflineMode() && $this->lm->getProgressIcons()) {
224 return $this->tracker->getIconForLMObject($a_node, $this->highlight_node);
225 }
226
227 if ($a_node["type"] == "du") {
228 $a_node["type"] = "lm";
229 }
230 $a_name = "icon_" . $a_node["type"] . ".svg";
231 if ($a_node["type"] == "pg") {
232 $lm_set = new ilSetting("lm");
233 $active = ilLMPage::_lookupActive(
234 $a_node["child"],
235 $this->lm->getType(),
236 (bool) $lm_set->get("time_scheduled_page_activation")
237 );
238
239 // is page scheduled?
240 $img_sc = ($lm_set->get("time_scheduled_page_activation") &&
241 ilLMPage::_isScheduledActivation($a_node["child"], $this->lm->getType()) && !$active
242 && !$this->getOfflineMode())
243 ? "_sc"
244 : "";
245
246 $a_name = "icon_pg" . $img_sc . ".svg";
247
248 if (!$active && !$this->getOfflineMode()) {
249 $a_name = "icon_pg_d" . $img_sc . ".svg";
250 }
251 }
252
253 return ilUtil::getImagePath($a_name, false, "output", $this->getOfflineMode());
254 }
255
259 public function isNodeClickable($a_node): bool
260 {
261 $ilUser = $this->user;
262
263 $orig_node_id = $a_node["child"];
264
265 // if navigation is restricted based on correct answered questions
266 // check if we have preceeding pages including unsanswered/incorrect answered questions
267 if (!$this->getOfflineMode()) {
268 if ($this->lm->getRestrictForwardNavigation()) {
269 if ($this->getTracker()->hasPredIncorrectAnswers($orig_node_id)) {
270 return false;
271 }
272 }
273 }
274
275 if ($a_node["type"] == "st") {
276 if (!$this->getOfflineMode()) {
277 if ($this->lm->getTOCMode() != "pages") {
278 $a_node = $this->getTree()->fetchSuccessorNode($a_node["child"], "pg");
279 } else {
280 // faster, but needs pages to be in explorer
281 $a_node = $this->getSuccessorNode($a_node["child"], "pg");
282 }
283 if ($a_node["child"] == 0) {
284 return false;
285 }
286 } else {
287 // get next activated page
288 $found = false;
289 while (!$found) {
290 if ($this->lm->getTOCMode() != "pages") {
291 $a_node = $this->getTree()->fetchSuccessorNode($a_node["child"], "pg");
292 } else {
293 $a_node = $this->getSuccessorNode($a_node["child"], "pg");
294 }
295 $active = ilLMPage::_lookupActive(
296 $a_node["child"],
297 $this->lm->getType(),
298 (bool) $this->lm_set->get("time_scheduled_page_activation")
299 );
300
301 if ($a_node["child"] > 0 && !$active) {
302 $found = false;
303 } else {
304 $found = true;
305 }
306 }
307 if ($a_node["child"] <= 0) {
308 return false;
309 } else {
310 $path = $this->getTree()->getPathId($a_node["child"]);
311 if (!in_array($orig_node_id, $path)) {
312 return false;
313 }
314 }
315 }
316 }
317
318 if ($a_node["type"] == "pg") {
319 // check public area mode
320 if ($ilUser->getId() == ANONYMOUS_USER_ID && !ilLMObject::_isPagePublic($a_node["child"], true)) {
321 return false;
322 }
323 }
324
325 return true;
326 }
327
328
332 public function getNodeIconAlt($a_node): string
333 {
334 return "";
335 }
336
340 public function getNodeHref($a_node): string
341 {
342 if (!$this->getOfflineMode()) {
343 return $this->linker->getLink("", $a_node["child"]);
344 //return parent::buildLinkTarget($a_node_id, $a_type);
345 } else {
346 if ($a_node["type"] != "pg") {
347 // get next activated page
348 $found = false;
349 while (!$found) {
350 $a_node = $this->getTree()->fetchSuccessorNode($a_node["child"], "pg");
351 $active = ilLMPage::_lookupActive(
352 $a_node["child"],
353 $this->lm->getType(),
354 (bool) $this->lm_set->get("time_scheduled_page_activation")
355 );
356
357 if ($a_node["child"] > 0 && !$active) {
358 $found = false;
359 } else {
360 $found = true;
361 }
362 }
363 }
364
365 $lang_suffix = "";
366 if ($this->export_all_languages) {
367 if ($this->lang != "" && $this->lang != "-") {
368 $lang_suffix = "_" . $this->lang;
369 }
370 }
371
372 if ($nid = ilLMPageObject::getExportId($this->lm->getId(), $a_node["child"])) {
373 return "lm_pg_" . $nid . $lang_suffix . ".html";
374 }
375 return "lm_pg_" . $a_node["child"] . $lang_suffix . ".html";
376 }
377 }
378
382 public function isNodeVisible($a_node): bool
383 {
384 return (bool) $this->complete_tree["visibility"][$a_node["child"]];
385 }
386
387 //
388 // Learning Sequence TOC
389 //
390
391 public function renderLSToc(\LSTOCBuilder $toc): void
392 {
393 $this->renderLSTocNode($toc, null);
394 }
395
396 protected function renderLSTocNode(\LSTOCBuilder $toc, ?array $current_node = null): void
397 {
398 $root = false;
399 if ($current_node == 0) {
400 $root = true;
401 $current_node = $this->tree->getNodeData($this->tree->readRootId());
402 }
403
404 $children = $this->getChildren($current_node);
405 if (count($children) > 0) {
406 if ($root) {
407 $node_toc = $toc;
408 } else {
409 // current workaround
411 $node_icon = $this->getNodeIcon($current_node);
412 if (strpos($node_icon, "complete")) {
414 }
415
416 $node_toc = $toc->node($current_node["title"], $current_node["child"], $lp);
417 }
418 foreach ($this->getChildren($current_node) as $child) {
419 $this->renderLSTocNode($node_toc, $child);
420 }
421 $node_toc->end();
422 } else {
423 $highlight = $this->isNodeHighlighted($current_node);
424 $toc->item($current_node["title"], $current_node["child"], null, $highlight);
425 }
426 }
427}
Class LSTOCBuilder.
node(string $label, int $parameter=null, int $lp=null)
Build a sub tree in the TOC.If a parameter is provided, the node in the TOC can be accessed itself....
item(string $label, int $parameter, $state=null, bool $current=false)
Build an entry in the TOC.The parameter will be appended to the command when updating the state....
setSecondaryHighlightedNodes(array $a_val)
Set secondary (background) highlighted nodes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isPagePublic(int $a_node_id, bool $a_check_public_mode=false)
static getExportId(int $a_lm_id, int $a_lmobj_id, string $a_type="pg")
static _lookupType(int $a_obj_id, int $a_lm_id=0)
static _getPresentationTitle(int $a_pg_id, string $a_mode=self::CHAPTER_TITLE, bool $a_include_numbers=false, bool $a_time_scheduled_activation=false, bool $a_force_content=false, int $a_lm_id=0, string $a_lang="-", bool $a_include_short=false)
presentation title doesn't have to be page title, it may be chapter title + page title or chapter tit...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Main service init and factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTracker(ilLMTracker $a_val)
ilLMPresentationLinker $linker
renderLSToc(\LSTOCBuilder $toc)
ilLMPresentationService $service
__construct( $a_parent_obj, string $a_parent_cmd, ilLMPresentationService $service, string $a_lang="-", int $a_focus_id=0, bool $export_all_languages=false)
Constructor.
ilPageActivationDBRepository $activation_repo
renderLSTocNode(\LSTOCBuilder $toc, ?array $current_node=null)
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...
static _isScheduledActivation(int $a_id, string $a_parent_type, string $a_lang="-")
Check whether page is activated by time schedule.
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getPresentationTitle(int $a_st_id, string $a_mode=self::CHAPTER_TITLE, bool $a_include_numbers=false, bool $a_time_scheduled_activation=false, bool $a_force_content=false, int $a_lm_id=0, string $a_lang="-", bool $a_include_short=false)
setTypeWhiteList(array $a_val)
Set type white list.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$lm_set
$lang
Definition: xapiexit.php:26