ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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;
37  protected ilLMTracker $tracker;
38  protected ilLMTree $lm_tree;
40  protected ilSetting $lm_set;
42  protected string $lang;
44 
45  public function __construct(
47  ilLMPresentationGUI $parent_gui,
48  ilLanguage $lng,
49  ilObjUser $user,
50  ilGlobalTemplateInterface $main_tpl,
51  int $requested_obj_id,
52  string $requested_back_pg,
53  string $requested_frame,
54  ilToolbarGUI $toolbar,
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  $page_id = $this->current_page;
93 
94  $tpl = new ilTemplate("tpl.lm_navigation.html", true, true, "Modules/LearningModule/Presentation");
95 
96  if (empty($page_id)) {
97  return "";
98  }
99 
100  // process navigation for free page
101  $back_pg = $this->navigation_status->getBackPageId();
102  if ($back_pg > 0) {
103  $back_href =
104  $this->linker->getLink(
105  "layout",
106  $back_pg,
107  "",
108  "",
109  "reduce"
110  );
111  $back_img =
112  ilUtil::getImagePath("nav/nav_arr2_L.png", false, "output", $this->offline);
113  $tpl->setCurrentBlock("ilLMNavigation_Prev");
114  $tpl->setVariable("IMG_PREV", $back_img);
115  $tpl->setVariable("HREF_PREV", $back_href);
116  $tpl->setVariable("TXT_PREV", $this->lng->txt("back"));
117  $tpl->setVariable("ALT_PREV", $this->lng->txt("back"));
118  $tpl->setVariable("SPACER_PREV", $this->offline
119  ? "images/media/spacer.png"
120  : ilUtil::getImagePath("media/spacer.png"));
121  $tpl->parseCurrentBlock();
122  if ($top) {
123  $b = $this->ui->factory()->button()->standard(
124  "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
125  $back_href
126  );
127  $this->toolbar->addStickyItem($b);
128  }
129  } else {
130  $pre_id = $this->navigation_status->getPredecessorPageId();
131  if ($pre_id > 0) {
132  // get presentation title
134  $pre_id,
135  $this->lm->getPageHeader(),
136  $this->lm->isActiveNumbering(),
137  (bool) $this->lm_set->get("time_scheduled_page_activation"),
138  false,
139  0,
140  $this->lang,
141  true
142  );
143  $prev_title = ilStr::shortenTextExtended($prev_title, 50, true);
144  $prev_img =
145  ilUtil::getImagePath("nav/nav_arr_L.png", false, "output", $this->offline);
146 
147  if (!$this->lm->cleanFrames()) {
148  $prev_href =
149  $this->linker->getLink(
150  "layout",
151  $pre_id,
152  $this->requested_frame
153  );
154  $prev_target = "";
155  } else {
156  if (!$this->offline) {
157  $prev_href =
158  $this->linker->getLink("layout", $pre_id);
159  $prev_target = 'target="' . ilFrameTargetInfo::_getFrame("MainContent") . '" ';
160  } else {
161  $prev_href =
162  $this->linker->getLink("layout", $pre_id);
163  $prev_target = 'target="_top" ';
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("FRAME_PREV", $prev_target);
171  $tpl->setVariable("TXT_PREV", $prev_title);
172  $tpl->setVariable("ALT_PREV", $this->lng->txt("previous"));
173  $tpl->setVariable("SPACER_PREV", $this->offline
174  ? "images/media/spacer.png"
175  : ilUtil::getImagePath("media/spacer.png"));
176 
177  if ($top) {
178  $b = $this->ui->factory()->button()->standard(
179  "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
180  $prev_href
181  );
182  $this->toolbar->addStickyItem($b);
183  }
184  } else {
185  if ($top) {
186  $b = $this->ui->factory()->button()->standard(
187  "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
188  "#"
189  )->withUnavailableAction();
190  $this->toolbar->addStickyItem($b);
191  }
192  }
193 
194  $this->addDropdown();
195 
196  $succ_id = $this->navigation_status->getSuccessorPageId();
197  if ($succ_id > 0) {
198  // get presentation title
200  $succ_id,
201  $this->lm->getPageHeader(),
202  $this->lm->isActiveNumbering(),
203  (bool) $this->lm_set->get("time_scheduled_page_activation"),
204  false,
205  0,
206  $this->lang,
207  true
208  );
209  $succ_title = ilStr::shortenTextExtended($succ_title, 50, true);
210  $succ_img =
211  ilUtil::getImagePath("nav/nav_arr_R.png", false, "output", $this->offline);
212  if (!$this->lm->cleanFrames()) {
213  $succ_href =
214  $this->linker->getLink(
215  "layout",
216  $succ_id,
217  $this->requested_frame
218  );
219  $succ_target = "";
220  } else {
221  if (!$this->offline) {
222  $succ_href =
223  $this->linker->getLink("layout", $succ_id);
224  $succ_target = ' target="' . ilFrameTargetInfo::_getFrame("MainContent") . '" ';
225  } else {
226  $succ_href =
227  $this->linker->getLink("layout", $succ_id);
228  $succ_target = ' target="_top" ';
229  }
230  }
231 
232  $tpl->setCurrentBlock("ilLMNavigation_Next");
233  $tpl->setVariable("IMG_SUCC", $succ_img);
234  $tpl->setVariable("HREF_SUCC", $succ_href);
235  $tpl->setVariable("FRAME_SUCC", $succ_target);
236  $tpl->setVariable("TXT_SUCC", $succ_title);
237  $tpl->setVariable("ALT_SUCC", $this->lng->txt("next"));
238  $tpl->setVariable("SPACER_SUCC", $this->offline
239  ? "images/media/spacer.png"
240  : ilUtil::getImagePath("media/spacer.png"));
241  $tpl->parseCurrentBlock();
242 
243  // check if successor page is not restricted
244  if (!$this->offline) {
245  if ($this->lm->getRestrictForwardNavigation()) {
246  if ($this->tracker->hasPredIncorrectAnswers($succ_id)) {
247  $this->main_tpl->addOnLoadCode("il.LearningModule.hideNextNavigation();");
248  }
249  }
250  }
251  if ($top) {
252  $b = $this->ui->factory()->button()->standard(
253  "<span class=\"glyphicon glyphicon-chevron-right \" aria-hidden=\"true\"></span>",
254  $succ_href
255  );
256  $this->toolbar->addStickyItem($b);
257  }
258  } else {
259  if ($top) {
260  $b = $this->ui->factory()->button()->standard(
261  "<span class=\"glyphicon glyphicon-chevron-right \" aria-hidden=\"true\"></span>",
262  "#"
263  )->withUnavailableAction();
264  $this->toolbar->addStickyItem($b);
265  }
266  }
267  }
268  $tpl->setVariable("CLASS", ($top) ? "tnav_Top" : "bnav_Bottom");
269 
270  return $tpl->get();
271  }
272 
273  protected function addDropdown()
274  {
275  $nodes = $this->lm_tree->getSubTree($this->lm_tree->getNodeData($this->lm_tree->getRootId()));
276  //$nodes = $this->filterNonAccessibleNode($nodes);
277 
278  foreach ($nodes as $node) {
279  $disabled = false;
280 
281  // check page activation
282  $active = ilLMPage::_lookupActive(
283  $node["obj_id"],
284  $this->lm->getType(),
285  (bool) $this->lm_set->get("time_scheduled_page_activation")
286  );
287 
288  if ($node["type"] === "pg" &&
289  !$active) {
290  continue;
291  }
292 
293  $text = "";
294  $checked = false;
295 
296  switch ($node["type"]) {
297  // page
298  case "pg":
299  if ($this->lm->getTOCMode() !== "pages") {
300  continue 2;
301  }
302  $text =
304  $node["obj_id"],
305  $this->lm->getPageHeader(),
306  $this->lm->isActiveNumbering(),
307  (bool) $this->lm_set->get("time_scheduled_page_activation"),
308  false,
309  $this->lm->getId(),
310  $this->lang,
311  true
312  );
313 
314  if ($this->user->getId() === ANONYMOUS_USER_ID &&
315  $this->lm->getPublicAccessMode() === "selected") {
316  if (!ilLMObject::_isPagePublic($node["obj_id"])) {
317  $disabled = true;
318  $text .= " (" . $this->lng->txt("cont_no_access") . ")";
319  }
320  }
321  break;
322 
323  // learning module
324  case "du":
325  $text = "";
326  break;
327 
328  // chapter
329  case "st":
330  $text =
332  $node["obj_id"],
334  $this->lm->isActiveNumbering(),
335  (bool) $this->lm_set->get("time_scheduled_page_activation"),
336  false,
337  $this->lm->getId(),
338  $this->lang,
339  true
340  );
341  if ($this->user->getId() === ANONYMOUS_USER_ID &&
342  $this->lm->getPublicAccessMode() === "selected") {
343  if (!ilLMObject::_isPagePublic($node["obj_id"])) {
344  $disabled = true;
345  $text .= " (" . $this->lng->txt("cont_no_access") . ")";
346  }
347  }
348  break;
349  }
350 
352  $this->lm->getRefId(),
353  $this->lm->getId(),
354  $node["obj_id"]
355  )) {
356  $disabled = true;
357  $text .= " (" . $this->lng->txt("cont_no_access") . ")";
358  }
359 
360  $href = $this->linker->getLink("layout", $node["obj_id"]);
361 
362  if ($text !== "") {
363  if ($this->lm->getTOCMode() === "pages" && $this->current_page == $node["obj_id"]) {
364  $text = "» " . $text;
365  }
366  if ($this->lm->getTOCMode() !== "pages") {
367  if ($this->lm_tree->getParentId($this->current_page) == $node["obj_id"]) {
368  $text = "» " . $text;
369  }
370  }
371  $text = str_pad("", ($node["depth"] - 1) * 12, "&nbsp;") . $text;
372  $actions[] = $this->ui->factory()->button()->shy(
373  $text,
374  $href
375  );
376  }
377  }
378 
379  if ($this->lm->getTOCMode() === "pages") {
381  $this->current_page,
382  $this->lm->getPageHeader(),
383  $this->lm->isActiveNumbering(),
384  (bool) $this->lm_set->get("time_scheduled_page_activation"),
385  false,
386  $this->lm->getId(),
387  $this->lang,
388  true
389  );
390  } else {
391  $st_id = $this->lm_tree->getParentId($this->current_page);
392  if ($st_id > 0) {
394  $st_id,
396  $this->lm->isActiveNumbering(),
397  (bool) $this->lm_set->get("time_scheduled_page_activation"),
398  false,
399  $this->lm->getId(),
400  $this->lang,
401  true
402  );
403  }
404  }
405 
406  $title = "<span style='vertical-align: bottom; max-width:60px; display: inline-block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>" . $title . "</span>";
407 
408 
409  $this->toolbar->addStickyItem(
410  $this->ui->factory()->dropdown()->standard($actions)->withLabel($title)
411  );
412  }
413 }
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
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)
static _isPagePublic(int $a_node_id, bool $a_check_public_mode=false)
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...
const ANONYMOUS_USER_ID
Definition: constants.php:27
Class ChatMainBarProvider .
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
__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 _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...
Class HTTPServicesTest.
getSettings()
Get learning module settings.
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&#39;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...
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getFrame(string $a_class)
$service
Definition: ltiservices.php:43
Main service init and factory.