ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLMContentRendererGUI.php
Go to the documentation of this file.
1<?php
2
20
25{
26 public const STATUS_ACCESS = 0;
27 public const STATUS_NO_ACCESS = 1;
28 public const STATUS_NO_PUBLIC_ACCESS = 2;
31 public const STATUS_NO_PAGE_IN_CHAPTER = 5;
32 public const STATUS_DEACTIVATED_PAGE = 6;
33 public const STATUS_NO_PAGE_FOUND = 7;
35
37 protected int $requested_obj_id = 0;
38 protected ?string $search_string;
39 protected ?int $focus_id;
40 protected bool $deactivated_page;
43 protected ilObjUser $user;
44 protected ilHelpGUI $help;
45 protected ?int $current_page = null;
47 protected ilLanguage $lng;
48 protected bool $offline;
50 protected ilCtrl $ctrl;
51 protected ilLMTree $lm_tree;
53 protected ilSetting $lm_set;
54 protected string $lang;
56 protected string $requested_frame;
57 protected Translations $ot;
58 protected string $concrete_lang = "";
59
60 public function __construct(
64 Translations $translation,
70 ) {
71 $this->access = $access;
72 $this->user = $user;
73 $this->help = $help;
74 $this->ctrl = $ctrl;
75 $this->lm_tree = $service->getLMTree();
76 $this->lang = $service->getPresentationStatus()->getLang();
77 $this->ot = $translation;
78 $this->current_page = $service->getNavigationStatus()->getCurrentPage();
79 $this->lm = $service->getLearningModule();
80 $this->lm_set = $service->getSettings();
81 $this->lng = $lng;
82 $this->offline = $service->getPresentationStatus()->offline;
83 $this->tracker = $service->getTracker();
84 $this->linker = $service->getLinker();
85 $this->parent_gui = $parent_gui;
86 $this->chapter_has_no_active_page = $service->getNavigationStatus()->isChapterWithoutActivePage();
87 $this->deactivated_page = $service->getNavigationStatus()->isDeactivatedPage();
88 $this->focus_id = $service->getPresentationStatus()->getFocusId();
89 $this->concrete_lang = $service->getPresentationStatus()->getConcreteLang();
90 $this->search_string = $service->getPresentationStatus()->getSearchString();
91 $this->requested_obj_id = $requested_obj_id;
92 $this->requested_focus_return = $service->getPresentationStatus()->getFocusReturn();
93 $this->requested_frame = $service->getRequest()->getFrame();
94 $this->navigation_status = $service->getNavigationStatus();
95 }
96
97 protected function initHelp(): void
98 {
99 $ilHelp = $this->help;
100 $ilHelp->setScreenIdComponent("lm");
101 $ilHelp->setScreenId("content");
102 $ilHelp->setSubScreenId("content");
103 }
104
105 protected function determineStatus(): int
106 {
108
109 $status = self::STATUS_ACCESS;
110 // check page id
111 $requested_page_lm = ilLMPage::lookupParentId($this->current_page, "lm");
112 if ($requested_page_lm != $this->lm->getId()) {
113 $status = self::STATUS_NO_ACCESS;
114 }
115
116 // preconditions
117 if (!ilObjContentObject::_checkPreconditionsOfPage($this->lm->getRefId(), $this->lm->getId(), $this->current_page) && !
118 $this->access->checkAccess("write", "", $this->lm->getRefId())) {
120 }
121
122 // if navigation is restricted based on correct answered questions
123 // check if we have preceeding pages including unsanswered/incorrect answered questions
124 if (!$this->offline) {
125 if ($this->lm->getRestrictForwardNavigation()) {
126 if ($this->tracker->hasPredIncorrectAnswers($this->current_page)) {
128 }
129 }
130 }
131
132 // no active page found in chapter
133 if ($this->chapter_has_no_active_page &&
134 ilLMObject::_lookupType($this->requested_obj_id) == "st") {
136 }
137
138 if ($this->deactivated_page) {
140 }
141
142 if ($this->current_page == 0) {
144 }
145 return $status;
146 }
147
148 protected function initSearchHighlighting(): void
149 {
151
152 if ($this->search_string != "" && !$this->offline) {
154 $cache->switchSearchType(ilUserSearchCache::LAST_QUERY);
155 $search_string = $cache->getQuery();
156
157 // advanced search?
158 if (is_array($search_string)) {
159 $search_string = $search_string["lom_content"];
160 }
161
163 $p->parse();
164
165 $words = $p->getQuotedWords();
166 if (is_array($words)) {
167 foreach ($words as $w) {
168 ilTextHighlighterGUI::highlight("ilLMPageContent", $w);
169 }
170 }
171 }
172 }
173
174 public function render(
175 int $a_head_foot_page_id = 0
176 ): string {
177 $ilUser = $this->user;
178
179 $head = $foot = "";
180
181 $this->initHelp();
182
183 switch ($this->determineStatus()) {
185 return $this->renderNoPageAccess();
186
188 return $this->renderNoPublicAccess();
189
191 return $this->renderPreconditionsOfPage();
192
195
197 return $this->renderNoPageInChapterMessage();
198
200 return $this->renderDeactivatedPageMessage();
201
203 return $this->renderNoPageFoundMessage();
204 }
205
206 // page id is e.g. > 0 when footer or header page is processed
207 if ($a_head_foot_page_id == 0) {
208 $page_id = $this->current_page;
209 $this->initSearchHighlighting();
210 } else {
211 $page_id = $a_head_foot_page_id;
212 }
213
214 // check if page is out of focus
215 $focus_mess = $this->renderFocusMessage();
216 $page_object_gui = $this->getLMPageGUI($page_id);
217
218 // @todo 6.0 (factor this out (maybe to ilLMPageGUI)
219 $this->parent_gui->basicPageGuiInit($page_object_gui);
220
221 $page_object = $page_object_gui->getPageObject();
222 $page_object->buildDom();
223 $page_object->registerOfflineHandler($this);
224
225 $page_object_gui->setTemplateOutput(false);
226
227 // Update course items
228 ilCourseLMHistory::_updateLastAccess($ilUser->getId(), $this->lm->getRefId(), $page_id);
229
230 // read link targets
231 $page_object_gui->setPageLinker($this->linker);
232
233 // get lm page object
234 $lm_pg_obj = new ilLMPageObject($this->lm, $page_id);
235 $lm_pg_obj->setLMId($this->lm->getId());
236
237 // determine target frames for internal links
238 $page_object_gui->setLinkFrame($this->requested_frame);
239
240 // page title and tracking (not for header or footer page)
241 if ($page_id == 0 || ($page_id != $this->lm->getHeaderPage() &&
242 $page_id != $this->lm->getFooterPage())) {
243 $page_object_gui->setPresentationTitle(
245 $lm_pg_obj->getId(),
246 $this->lm->getPageHeader(),
247 $this->lm->isActiveNumbering(),
248 (bool) $this->lm_set->get("time_scheduled_page_activation"),
249 false,
250 0,
251 $this->lang
252 )
253 );
254
255 // track access
256 if ($page_id != 0 && !$this->offline) {
257 $this->tracker->trackAccess($page_id, $ilUser->getId());
258 }
259 } else {
260 $page_object_gui->setEnabledPageFocus(false);
261 $page_object_gui->getPageConfig()->setEnableSelfAssessment(false);
262 }
263
264 // ADDED FOR CITATION
265 $page_object_gui->setLinkParams("ref_id=" . $this->lm->getRefId());
266 $page_object_gui->setTemplateTargetVar("PAGE_CONTENT");
267 // @todo 6.0
268 // $page_object_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadLink());
269
270 $ret = $page_object_gui->presentation($page_object_gui->getOutputMode());
271
272 // process header
273 if ($this->lm->getHeaderPage() > 0 &&
274 $page_id != $this->lm->getHeaderPage() &&
275 ($page_id == 0 || $page_id != $this->lm->getFooterPage())) {
276 if (ilLMObject::_exists($this->lm->getHeaderPage())) {
277 $head = $this->render($this->lm->getHeaderPage());
278 }
279 }
280
281 // process footer
282 if ($this->lm->getFooterPage() > 0 &&
283 $page_id != $this->lm->getFooterPage() &&
284 ($page_id == 0 || $page_id != $this->lm->getHeaderPage())) {
285 if (ilLMObject::_exists($this->lm->getFooterPage())) {
286 $foot = $this->render($this->lm->getFooterPage());
287 }
288 }
289 return $head . $focus_mess . $ret . $foot;
290 }
291
292 public function getLMPageGUI(int $a_id): ilLMPageGUI
293 {
294 if ($this->lang != "-" && ilPageObject::_exists("lm", $a_id, $this->lang)) {
295 $page_gui = new ilLMPageGUI($a_id, 0, false, $this->lang, $this->concrete_lang);
296 } else {
297 if ($this->lang != "-" && ilPageObject::_exists("lm", $a_id, $this->ot->getDefaultLanguage())) {
298 $page_gui = new ilLMPageGUI($a_id, 0, false, $this->ot->getDefaultLanguage(), $this->concrete_lang);
299 } else {
300 $page_gui = new ilLMPageGUI($a_id, 0, false, "", $this->concrete_lang);
301 }
302 }
303 if ($this->offline) {
304 $page_gui->setOutputMode(ilPageObjectGUI::OFFLINE);
305 }
306 return $page_gui;
307 }
308
309 public function handleCodeParagraph(
310 int $page_id,
311 int $paragraph_id,
312 string $title,
313 string $text
314 ): void {
315 $directory = $this->parent_gui->getOfflineDirectory() . "/codefiles/" . $page_id . "/" . $paragraph_id;
316 ilFileUtils::makeDirParents($directory);
317 $file = $directory . "/" . $title;
318 if (!($fp = fopen($file, "w+"))) {
319 die("<strong>Error</strong>: Could not open \"" . $file . "\" for writing" .
320 " in <strong>" . __FILE__ . "</strong> on line <strong>" . __LINE__ . "</strong><br />");
321 }
322 chmod($file, 0770);
323 fwrite($fp, $text);
324 fclose($fp);
325 }
326
327 protected function renderFocusMessage(): string
328 {
329 $focus_mess = "";
330 if ($this->focus_id > 0) {
331 $path = $this->lm_tree->getPathId($this->current_page);
332
333 // out of focus
334 if (!in_array($this->focus_id, $path)) {
335 $mtpl = new ilTemplate(
336 "tpl.out_of_focus_message.html",
337 true,
338 true,
339 "components/ILIAS/LearningModule"
340 );
341 $mtpl->setVariable("MESSAGE", $this->lng->txt("cont_out_of_focus_message"));
342 $mtpl->setVariable("TXT_SHOW_CONTENT", $this->lng->txt("cont_show_content_after_focus"));
343
344 if ($this->requested_focus_return == 0 || ilObject::_lookupType((int) $this->requested_focus_return, true) != "crs") {
345 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_beginning"));
346 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->focus_id);
347 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
348 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->requested_obj_id);
349 } else {
350 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_return_crs"));
351 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", ilLink::_getLink($this->requested_focus_return));
352 }
353
354 $this->ctrl->setParameter($this->parent_gui, "focus_id", null);
355 $mtpl->setVariable("LINK_SHOW_CONTENT", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
356 $this->ctrl->setParameter($this->parent_gui, "focus_id", $this->requested_obj_id);
357
358 $focus_mess = $mtpl->get();
359 } else {
360 $succ_page_id = $this->navigation_status->getSuccessorPageId();
361 $path2 = array();
362 if ($succ_page_id > 0) {
363 $path2 = $this->lm_tree->getPathId($succ_page_id);
364 }
365 if ($succ_page_id == 0 || !in_array($this->focus_id, $path2)) {
366 $mtpl = new ilTemplate(
367 "tpl.out_of_focus_message.html",
368 true,
369 true,
370 "components/ILIAS/LearningModule"
371 );
372 $mtpl->setVariable("MESSAGE", $this->lng->txt("cont_out_of_focus_message_last_page"));
373 $mtpl->setVariable("TXT_SHOW_CONTENT", $this->lng->txt("cont_show_content_after_focus"));
374
375 if ($this->requested_focus_return == 0 || ilObject::_lookupType($this->requested_focus_return, true) != "crs") {
376 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_beginning"));
377 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->focus_id);
378 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
379 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->requested_obj_id);
380 } else {
381 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_return_crs"));
382 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", ilLink::_getLink($this->requested_focus_return));
383 }
384
385 $this->ctrl->setParameter($this->parent_gui, "focus_id", null);
386 $mtpl->setVariable("LINK_SHOW_CONTENT", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
387 $this->ctrl->setParameter($this->parent_gui, "focus_id", $this->requested_obj_id);
388
389 $focus_mess = $mtpl->get();
390 }
391 }
392 }
393 return $focus_mess;
394 }
395
396
400 protected function renderNoPageAccess(): string
401 {
402 return $this->renderMessageScreen($this->lng->txt("msg_no_page_access"));
403 }
404
408 protected function renderMessageScreen(string $a_content): string
409 {
410 // content style
411 $tpl = new ilTemplate("tpl.page_message_screen.html", true, true, "components/ILIAS/LearningModule");
412 $tpl->setVariable("TXT_PAGE_NO_PUBLIC_ACCESS", $a_content);
413
414 return $tpl->get();
415 }
416
420 protected function renderNoPublicAccess(): string
421 {
422 return $this->renderMessageScreen($this->lng->txt("msg_page_no_public_access"));
423 }
424
429 protected function renderNavRestrictionDueToQuestions(): string
430 {
431 return $this->renderMessageScreen($this->lng->txt("cont_no_page_access_unansw_q"));
432 }
433
437 protected function renderNoPageInChapterMessage(): string
438 {
439 $mtpl = new ilTemplate(
440 "tpl.no_content_message.html",
441 true,
442 true,
443 "components/ILIAS/LearningModule"
444 );
445 $mtpl->setVariable("MESSAGE", $this->lng->txt("cont_no_page_in_chapter"));
446 $mtpl->setVariable(
447 "ITEM_TITLE",
448 ilLMObject::_lookupTitle($this->requested_obj_id)
449 );
450 return $mtpl->get();
451 }
452
456 protected function renderNoPageFoundMessage(): string
457 {
458 return $this->renderMessageScreen($this->lng->txt("cont_no_page"));
459 }
460
461 protected function renderDeactivatedPageMessage(): string
462 {
463 $mtpl = new ilTemplate(
464 "tpl.no_content_message.html",
465 true,
466 true,
467 "components/ILIAS/LearningModule"
468 );
469 $m = $this->lng->txt("cont_page_currently_deactivated");
470 $act_data = ilLMPage::_lookupActivationData($this->current_page, $this->lm->getType());
471 if ($act_data["show_activation_info"] &&
472 (ilUtil::now() < $act_data["activation_start"])) {
473 $m .= "<p>" . sprintf(
474 $this->lng->txt("cont_page_activation_on"),
476 new ilDateTime($act_data["activation_start"], IL_CAL_DATETIME)
477 )
478 ) .
479 "</p>";
480 }
481 $mtpl->setVariable("MESSAGE", $m);
482 $mtpl->setVariable(
483 "ITEM_TITLE",
484 ilLMObject::_lookupTitle($this->current_page)
485 );
486 return $mtpl->get();
487 }
488
489
493 public function renderPreconditionsOfPage(): string
494 {
495 $succ_node = "";
496 $conds = ilObjContentObject::_getMissingPreconditionsOfPage($this->lm->getRefId(), $this->lm->getId(), $this->current_page);
497 $topchap = ilObjContentObject::_getMissingPreconditionsTopChapter($this->lm->getRefId(), $this->lm->getId(), $this->current_page);
498
499 $ptpl = new ilTemplate("tpl.page_preconditions.html", true, true, "components/ILIAS/LearningModule");
500
501 // list all missing preconditions
502 foreach ($conds as $cond) {
503 $obj_link = ilLink::_getLink($cond["trigger_ref_id"]);
504 $ptpl->setCurrentBlock("condition");
505 $ptpl->setVariable("VAL_ITEM", ilObject::_lookupTitle($cond["trigger_obj_id"]));
506 $ptpl->setVariable("LINK_ITEM", $obj_link);
507 if ($cond["operator"] == "passed") {
508 $cond_str = $this->lng->txt("passed");
509 } else {
510 $cond_str = $this->lng->txt("condition_" . $cond["operator"]);
511 }
512 $ptpl->setVariable("VAL_CONDITION", $cond_str . " " . $cond["value"]);
513 $ptpl->parseCurrentBlock();
514 }
515
516 $ptpl->setVariable(
517 "TXT_MISSING_PRECONDITIONS",
518 sprintf(
519 $this->lng->txt("cont_missing_preconditions"),
521 )
522 );
523 $ptpl->setVariable("TXT_ITEM", $this->lng->txt("object"));
524 $ptpl->setVariable("TXT_CONDITION", $this->lng->txt("condition"));
525
526 // output skip chapter link
527 $parent = $this->lm_tree->getParentId($topchap);
528 $childs = $this->lm_tree->getChildsByType($parent, "st");
529 $j = -2;
530 $i = 1;
531 foreach ($childs as $child) {
532 if ($child["child"] == $topchap) {
533 $j = $i;
534 }
535 if ($i++ == ($j + 1)) {
536 $succ_node = $this->lm_tree->fetchSuccessorNode($child["child"], "pg");
537 }
538 }
539 if ($succ_node != "") {
540 $link = "<br /><a href=\"" .
541 $this->linker->getLink("layout", $succ_node["obj_id"], $this->requested_frame) .
542 "\">" . $this->lng->txt("cont_skip_chapter") . "</a>";
543 $ptpl->setVariable("LINK_SKIP_CHAPTER", $link);
544 }
545
546 return $ptpl->get();
547 }
548}
Class handles translation mode for an object.
const IL_CAL_DATETIME
static _updateLastAccess(int $a_user_id, int $a_lm_ref_id, int $a_page_id)
Class ilCtrl provides processing control methods.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
Help GUI class.
setScreenIdComponent(string $a_comp)
renderMessageScreen(string $a_content)
Render message screen.
renderNavRestrictionDueToQuestions()
Render message if navigation to page is not allowed due to unanswered questions.
renderNoPageFoundMessage()
Render no page found message.
__construct(ilLMPresentationService $service, ilLMPresentationGUI $parent_gui, ilLanguage $lng, Translations $translation, ilCtrl $ctrl, ilAccessHandler $access, ilObjUser $user, ilHelpGUI $help, int $requested_obj_id)
renderNoPageInChapterMessage()
Render no page in chapter message.
ilLMNavigationStatus $navigation_status
renderPreconditionsOfPage()
Render preconditions of the page.
renderNoPublicAccess()
Render info message, if page is not accessible in public area.
render(int $a_head_foot_page_id=0)
renderNoPageAccess()
Render info message, if page is not accessible in public area.
handleCodeParagraph(int $page_id, int $paragraph_id, string $title, string $text)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(int $a_id)
checks wether a lm content object with specified id exists or not
static _lookupTitle(int $a_obj_id)
static _lookupType(int $a_obj_id, int $a_lm_id=0)
Extension of ilPageObjectGUI for learning modules.
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 _getMissingPreconditionsTopChapter(int $cont_obj_ref_id, int $cont_obj_id, int $page_id)
get top chapter of page for that any precondition is missing
static _checkPreconditionsOfPage(int $cont_ref_id, int $cont_obj_id, int $page_id)
checks whether the preconditions of a page are fulfilled or not
static _getMissingPreconditionsOfPage(int $cont_ref_id, int $cont_obj_id, int $page_id)
gets all missing preconditions of page
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static _lookupActivationData(int $a_id, string $a_parent_type, string $a_lang="-")
Lookup activation data.
static lookupParentId(int $a_id, string $a_type)
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static _getInstance(int $a_usr_id)
static now()
Return current timestamp in Y-m-d H:i:s format.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$service
Definition: ltiresult.php:36
$path
Definition: ltiservices.php:30