ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
class.ilLMNavigationRendererGUI.php
Go to the documentation of this file.
1<?php
2
23{
25 protected \ILIAS\DI\UIServices $ui;
26 protected string $requested_frame;
27 protected int $requested_back_pg;
28 protected int $requested_obj_id;
30 protected bool $deactivated_page;
32 protected ilObjUser $user;
33 protected ?int $current_page;
35 protected ilLanguage $lng;
36 protected bool $offline;
38 protected ilLMTree $lm_tree;
40 protected ilSetting $lm_set;
42 protected string $lang;
44
45 public function __construct(
52 string $requested_back_pg,
53 string $requested_frame,
55 \ILIAS\DI\UIServices $ui
56 ) {
57 $this->user = $user;
58 $this->toolbar = $toolbar;
59 $this->ui = $ui;
60 $this->lm_tree = $service->getLMTree();
61 $this->current_page = $service->getNavigationStatus()->getCurrentPage();
62 $this->lm = $service->getLearningModule();
63 $this->lm_set = $service->getSettings();
64 $this->lng = $lng;
65 $this->offline = $service->getPresentationStatus()->offline();
66 $this->tracker = $service->getTracker();
67 $this->parent_gui = $parent_gui;
68 $this->chapter_has_no_active_page = $service->getNavigationStatus()->isChapterWithoutActivePage();
69 $this->deactivated_page = $service->getNavigationStatus()->isDeactivatedPage();
70 $this->linker = $service->getLinker();
71 $this->navigation_status = $service->getNavigationStatus();
72 $this->requested_obj_id = $requested_obj_id;
73 $back_pg = explode(":", $requested_back_pg);
74 $this->requested_back_pg = (int) $back_pg[0];
75 $this->requested_frame = $requested_frame;
76 $this->main_tpl = $main_tpl;
77 $this->lang = $service->getPresentationStatus()->getLang();
78 }
79
80 public function renderTop(): string
81 {
82 return $this->render();
83 }
84
85 public function renderBottom(): string
86 {
87 return $this->render(false);
88 }
89
90 protected function render(bool $top = true): string
91 {
92 $this->toolbar->setStickyItems([]);
93
94 $page_id = $this->current_page;
95
96 $tpl = new ilTemplate("tpl.lm_navigation.html", true, true, "components/ILIAS/LearningModule/Presentation");
97
98 if (empty($page_id)) {
99 return "";
100 }
101
102 // process navigation for free page
103 $back_pg = $this->navigation_status->getBackPageId();
104 if ($back_pg > 0) {
105 $back_href =
106 $this->linker->getLink(
107 "layout",
108 $back_pg,
109 "",
110 "",
111 "reduce"
112 );
113 $back_img =
114 ilUtil::getImagePath("nav/nav_arr2_L.png", false, "output", $this->offline);
115 $tpl->setCurrentBlock("ilLMNavigation_Prev");
116 $tpl->setVariable("IMG_PREV", $back_img);
117 $tpl->setVariable("HREF_PREV", $back_href);
118 $tpl->setVariable("TXT_PREV", $this->lng->txt("back"));
119 $tpl->setVariable("ALT_PREV", $this->lng->txt("back"));
120 $tpl->setVariable("SPACER_PREV", $this->offline
121 ? "images/media/spacer.png"
122 : ilUtil::getImagePath("media/spacer.png"));
123 $tpl->parseCurrentBlock();
124 if ($top) {
125 $b = $this->ui->factory()->button()->standard(
126 "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
127 $back_href
128 );
129 $this->toolbar->addStickyItem($b);
130 }
131 } else {
132 $pre_id = $this->navigation_status->getPredecessorPageId();
133 if ($pre_id > 0) {
134 // get presentation title
136 $pre_id,
137 $this->lm->getPageHeader(),
138 $this->lm->isActiveNumbering(),
139 (bool) $this->lm_set->get("time_scheduled_page_activation"),
140 false,
141 0,
142 $this->lang,
143 true
144 );
145 $prev_title = ilStr::shortenTextExtended($prev_title, 50, true);
146 $prev_img =
147 ilUtil::getImagePath("nav/nav_arr_L.png", false, "output", $this->offline);
148
149 if (!$this->lm->cleanFrames()) {
150 $prev_href =
151 $this->linker->getLink(
152 "layout",
153 $pre_id,
154 $this->requested_frame
155 );
156 $prev_target = "";
157 } else {
158 if (!$this->offline) {
159 $prev_href =
160 $this->linker->getLink("layout", $pre_id);
161 } else {
162 $prev_href =
163 $this->linker->getLink("layout", $pre_id);
164 }
165 }
166
167 $tpl->setCurrentBlock("ilLMNavigation_Prev");
168 $tpl->setVariable("IMG_PREV", $prev_img);
169 $tpl->setVariable("HREF_PREV", $prev_href);
170 $tpl->setVariable("TXT_PREV", $prev_title);
171 $tpl->setVariable("ALT_PREV", $this->lng->txt("previous"));
172 $tpl->setVariable("SPACER_PREV", $this->offline
173 ? "images/media/spacer.png"
174 : ilUtil::getImagePath("media/spacer.png"));
175
176 if ($top) {
177 $b = $this->ui->factory()->button()->standard(
178 "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
179 $prev_href
180 );
181 $this->toolbar->addStickyItem($b);
182 }
183 } else {
184 if ($top) {
185 $b = $this->ui->factory()->button()->standard(
186 "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
187 "#"
188 )->withUnavailableAction();
189 $this->toolbar->addStickyItem($b);
190 }
191 }
192
193 $this->addDropdown();
194
195 $succ_id = $this->navigation_status->getSuccessorPageId();
196 if ($succ_id > 0) {
197 // get presentation title
199 $succ_id,
200 $this->lm->getPageHeader(),
201 $this->lm->isActiveNumbering(),
202 (bool) $this->lm_set->get("time_scheduled_page_activation"),
203 false,
204 0,
205 $this->lang,
206 true
207 );
208 $succ_title = ilStr::shortenTextExtended($succ_title, 50, true);
209 $succ_img =
210 ilUtil::getImagePath("nav/nav_arr_R.png", false, "output", $this->offline);
211 if (!$this->lm->cleanFrames()) {
212 $succ_href =
213 $this->linker->getLink(
214 "layout",
215 $succ_id,
216 $this->requested_frame
217 );
218 $succ_target = "";
219 } else {
220 if (!$this->offline) {
221 $succ_href =
222 $this->linker->getLink("layout", $succ_id);
223 } else {
224 $succ_href =
225 $this->linker->getLink("layout", $succ_id);
226 }
227 }
228
229 $tpl->setCurrentBlock("ilLMNavigation_Next");
230 $tpl->setVariable("IMG_SUCC", $succ_img);
231 $tpl->setVariable("HREF_SUCC", $succ_href);
232 $tpl->setVariable("TXT_SUCC", $succ_title);
233 $tpl->setVariable("ALT_SUCC", $this->lng->txt("next"));
234 $tpl->setVariable("SPACER_SUCC", $this->offline
235 ? "images/media/spacer.png"
236 : ilUtil::getImagePath("media/spacer.png"));
237 $tpl->parseCurrentBlock();
238
239 // check if successor page is not restricted
240 if (!$this->offline) {
241 if ($this->lm->getRestrictForwardNavigation()) {
242 if ($this->tracker->hasPredIncorrectAnswers($succ_id)) {
243 $this->main_tpl->addOnLoadCode("il.LearningModule.hideNextNavigation();");
244 }
245 }
246 }
247 if ($top) {
248 $b = $this->ui->factory()->button()->standard(
249 "<span class=\"glyphicon glyphicon-chevron-right \" aria-hidden=\"true\"></span>",
250 $succ_href
251 );
252 $this->toolbar->addStickyItem($b);
253 }
254 } else {
255 if ($top) {
256 $b = $this->ui->factory()->button()->standard(
257 "<span class=\"glyphicon glyphicon-chevron-right \" aria-hidden=\"true\"></span>",
258 "#"
259 )->withUnavailableAction();
260 $this->toolbar->addStickyItem($b);
261 }
262 }
263 }
264 $tpl->setVariable("CLASS", ($top) ? "tnav_Top" : "bnav_Bottom");
265
266 return $tpl->get();
267 }
268
269 protected function addDropdown(): void
270 {
271 $nodes = $this->lm_tree->getSubTree($this->lm_tree->getNodeData($this->lm_tree->getRootId()));
272 //$nodes = $this->filterNonAccessibleNode($nodes);
273
274 $actions = [];
275
276 foreach ($nodes as $node) {
277 $disabled = false;
278
279 // check page activation
280 $active = ilLMPage::_lookupActive(
281 $node["obj_id"],
282 $this->lm->getType(),
283 (bool) $this->lm_set->get("time_scheduled_page_activation")
284 );
285
286 if ($node["type"] === "pg" &&
287 !$active) {
288 continue;
289 }
290
291 $text = "";
292 $checked = false;
293
294 switch ($node["type"]) {
295 // page
296 case "pg":
297 if ($this->lm->getTOCMode() !== "pages") {
298 continue 2;
299 }
300 $text =
302 $node["obj_id"],
303 $this->lm->getPageHeader(),
304 $this->lm->isActiveNumbering(),
305 (bool) $this->lm_set->get("time_scheduled_page_activation"),
306 false,
307 $this->lm->getId(),
308 $this->lang,
309 true
310 );
311
312 break;
313
314 // learning module
315 case "du":
316 $text = "";
317 break;
318
319 // chapter
320 case "st":
321 $text =
323 $node["obj_id"],
325 $this->lm->isActiveNumbering(),
326 (bool) $this->lm_set->get("time_scheduled_page_activation"),
327 false,
328 $this->lm->getId(),
329 $this->lang,
330 true
331 );
332 break;
333 }
334
336 $this->lm->getRefId(),
337 $this->lm->getId(),
338 $node["obj_id"]
339 )) {
340 $disabled = true;
341 $text .= " (" . $this->lng->txt("cont_no_access") . ")";
342 }
343
344 $href = $this->linker->getLink("layout", $node["obj_id"]);
345
346 if ($text !== "") {
347 if ($this->lm->getTOCMode() === "pages" && $this->current_page == $node["obj_id"]) {
348 $text = "» " . $text;
349 }
350 if ($this->lm->getTOCMode() !== "pages") {
351 if ($this->lm_tree->getParentId($this->current_page) == $node["obj_id"]) {
352 $text = "» " . $text;
353 }
354 }
355 $text = str_pad("", ($node["depth"] - 1) * 12, "&nbsp;") . $text;
356 $button = $this->ui->factory()->button()->shy(
357 $text,
358 $href
359 );
360 if ($disabled) {
361 $button = $button->withUnavailableAction();
362 }
363 $actions[] = $button;
364 }
365 }
366
367 $title = "";
368 if ($this->lm->getTOCMode() === "pages") {
370 $this->current_page,
371 $this->lm->getPageHeader(),
372 $this->lm->isActiveNumbering(),
373 (bool) $this->lm_set->get("time_scheduled_page_activation"),
374 false,
375 $this->lm->getId(),
376 $this->lang,
377 true
378 );
379 } else {
380 $st_id = $this->lm_tree->getParentId($this->current_page);
381 if ($st_id > 0) {
383 $st_id,
385 $this->lm->isActiveNumbering(),
386 (bool) $this->lm_set->get("time_scheduled_page_activation"),
387 false,
388 $this->lm->getId(),
389 $this->lang,
390 true
391 );
392 }
393 }
394
395 $title = "<span style='vertical-align: bottom; max-width:60px; display: inline-block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>" . $title . "</span>";
396
397 $this->toolbar->addStickyItem(
398 $this->ui->factory()->dropdown()->standard($actions)->withLabel($title)
399 );
400 }
401}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilLMPresentationService $service, ilLMPresentationGUI $parent_gui, ilLanguage $lng, ilObjUser $user, ilGlobalTemplateInterface $main_tpl, int $requested_obj_id, string $requested_back_pg, string $requested_frame, ilToolbarGUI $toolbar, \ILIAS\DI\UIServices $ui)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
Class ilLMPresentationGUI GUI class for learning module presentation.
Learning module presentation linker.
Main service init and factory.
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...
language handling
static _checkPreconditionsOfPage(int $cont_ref_id, int $cont_obj_id, int $page_id)
checks whether the preconditions of a page are fulfilled or not
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
ILIAS Setting Class.
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
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)
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$service
Definition: ltiresult.php:36
Class HTTPServicesTest.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$text
Definition: xapiexit.php:21