ILIAS  release_8 Revision v8.24
class.ilLMContentRendererGUI.php
Go to the documentation of this file.
1<?php
2
23{
24 public const STATUS_ACCESS = 0;
25 public const STATUS_NO_ACCESS = 1;
26 public const STATUS_NO_PUBLIC_ACCESS = 2;
29 public const STATUS_NO_PAGE_IN_CHAPTER = 5;
30 public const STATUS_DEACTIVATED_PAGE = 6;
31 public const STATUS_NO_PAGE_FOUND = 7;
33
35 protected int $requested_obj_id = 0;
36 protected ?string $search_string;
37 protected ?int $focus_id;
38 protected bool $deactivated_page;
41 protected ilObjUser $user;
42 protected ilHelpGUI $help;
43 protected ?int $current_page = null;
45 protected ilLanguage $lng;
46 protected bool $offline;
48 protected ilCtrl $ctrl;
49 protected ilLMTree $lm_tree;
51 protected ilSetting $lm_set;
52 protected string $lang;
54 protected string $requested_frame;
56 protected string $concrete_lang = "";
57
58 public function __construct(
67 ) {
68 $this->access = $access;
69 $this->user = $user;
70 $this->help = $help;
71 $this->ctrl = $ctrl;
72 $this->lm_tree = $service->getLMTree();
73 $this->lang = $service->getPresentationStatus()->getLang();
74 $this->current_page = $service->getNavigationStatus()->getCurrentPage();
75 $this->lm = $service->getLearningModule();
76 $this->lm_set = $service->getSettings();
77 $this->lng = $lng;
78 $this->offline = $service->getPresentationStatus()->offline;
79 $this->tracker = $service->getTracker();
80 $this->linker = $service->getLinker();
81 $this->parent_gui = $parent_gui;
82 $this->chapter_has_no_active_page = $service->getNavigationStatus()->isChapterWithoutActivePage();
83 $this->deactivated_page = $service->getNavigationStatus()->isDeactivatedPage();
84 $this->focus_id = $service->getPresentationStatus()->getFocusId();
85 $this->concrete_lang = $service->getPresentationStatus()->getConcreteLang();
86 $this->search_string = $service->getPresentationStatus()->getSearchString();
87 $this->requested_obj_id = $requested_obj_id;
88 $this->requested_focus_return = $service->getPresentationStatus()->getFocusReturn();
89 $this->requested_frame = $service->getRequest()->getFrame();
90 $this->navigation_status = $service->getNavigationStatus();
91 $this->ot = ilObjectTranslation::getInstance($this->lm->getId());
92 }
93
94 protected function initHelp(): void
95 {
96 $ilHelp = $this->help;
97 $ilHelp->setScreenIdComponent("lm");
98 $ilHelp->setScreenId("content");
99 $ilHelp->setSubScreenId("content");
100 }
101
102 protected function determineStatus(): int
103 {
105
106 $status = self::STATUS_ACCESS;
107 // check page id
108 $requested_page_lm = ilLMPage::lookupParentId($this->current_page, "lm");
109 if ($requested_page_lm != $this->lm->getId()) {
110 $status = self::STATUS_NO_ACCESS;
111 }
112
113
114 // check if page is (not) visible in public area
115 if ($user->getId() == ANONYMOUS_USER_ID &&
116 $this->lm->getPublicAccessMode() == 'selected') {
117 if (!ilLMObject::_isPagePublic($this->current_page)) {
119 }
120 }
121
122 // preconditions
123 if (!ilObjContentObject::_checkPreconditionsOfPage($this->lm->getRefId(), $this->lm->getId(), $this->current_page)) {
125 }
126
127 // if navigation is restricted based on correct answered questions
128 // check if we have preceeding pages including unsanswered/incorrect answered questions
129 if (!$this->offline) {
130 if ($this->lm->getRestrictForwardNavigation()) {
131 if ($this->tracker->hasPredIncorrectAnswers($this->current_page)) {
133 }
134 }
135 }
136
137 // no active page found in chapter
138 if ($this->chapter_has_no_active_page &&
139 ilLMObject::_lookupType($this->requested_obj_id) == "st") {
141 }
142
143 if ($this->deactivated_page) {
145 }
146
147 if ($this->current_page == 0) {
149 }
150
151 return $status;
152 }
153
154 protected function initSearchHighlighting(): void
155 {
157
158 if ($this->search_string != "" && !$this->offline) {
160 $cache->switchSearchType(ilUserSearchCache::LAST_QUERY);
161 $search_string = $cache->getQuery();
162
163 // advanced search?
164 if (is_array($search_string)) {
165 $search_string = $search_string["lom_content"];
166 }
167
169 $p->parse();
170
171 $words = $p->getQuotedWords();
172 if (is_array($words)) {
173 foreach ($words as $w) {
174 ilTextHighlighterGUI::highlight("ilLMPageContent", $w);
175 }
176 }
177 }
178 }
179
180 public function render(
181 int $a_head_foot_page_id = 0
182 ): string {
183 $ilUser = $this->user;
184
185 $head = $foot = "";
186
187 $this->initHelp();
188
189 switch ($this->determineStatus()) {
191 return $this->renderNoPageAccess();
192
194 return $this->renderNoPublicAccess();
195
197 return $this->renderPreconditionsOfPage();
198
201
203 return $this->renderNoPageInChapterMessage();
204
206 return $this->renderDeactivatedPageMessage();
207
209 return $this->renderNoPageFoundMessage();
210
211 }
212
213 // page id is e.g. > 0 when footer or header page is processed
214 if ($a_head_foot_page_id == 0) {
215 $page_id = $this->current_page;
216 $this->initSearchHighlighting();
217 } else {
218 $page_id = $a_head_foot_page_id;
219 }
220
221 // check if page is out of focus
222 $focus_mess = $this->renderFocusMessage();
223 $page_object_gui = $this->getLMPageGUI($page_id);
224
225 // @todo 6.0 (factor this out (maybe to ilLMPageGUI)
226 $this->parent_gui->basicPageGuiInit($page_object_gui);
227
228 $page_object = $page_object_gui->getPageObject();
229 $page_object->buildDom();
230 $page_object->registerOfflineHandler($this);
231
232 $page_object_gui->setTemplateOutput(false);
233
234 // Update course items
235 ilCourseLMHistory::_updateLastAccess($ilUser->getId(), $this->lm->getRefId(), $page_id);
236
237 // read link targets
238 $page_object_gui->setPageLinker($this->linker);
239
240 // get lm page object
241 $lm_pg_obj = new ilLMPageObject($this->lm, $page_id);
242 $lm_pg_obj->setLMId($this->lm->getId());
243
244 // determine target frames for internal links
245 $page_object_gui->setLinkFrame($this->requested_frame);
246
247 // page title and tracking (not for header or footer page)
248 if ($page_id == 0 || ($page_id != $this->lm->getHeaderPage() &&
249 $page_id != $this->lm->getFooterPage())) {
250 $page_object_gui->setPresentationTitle(
252 $lm_pg_obj->getId(),
253 $this->lm->getPageHeader(),
254 $this->lm->isActiveNumbering(),
255 (bool) $this->lm_set->get("time_scheduled_page_activation"),
256 false,
257 0,
258 $this->lang
259 )
260 );
261
262 // track access
263 if ($page_id != 0 && !$this->offline) {
264 $this->tracker->trackAccess($page_id, $ilUser->getId());
265 }
266 } else {
267 $page_object_gui->setEnabledPageFocus(false);
268 $page_object_gui->getPageConfig()->setEnableSelfAssessment(false);
269 }
270
271 // ADDED FOR CITATION
272 $page_object_gui->setLinkParams("ref_id=" . $this->lm->getRefId());
273 $page_object_gui->setTemplateTargetVar("PAGE_CONTENT");
274 // @todo 6.0
275 // $page_object_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadLink());
276
277 $ret = $page_object_gui->presentation($page_object_gui->getOutputMode());
278
279 // process header
280 if ($this->lm->getHeaderPage() > 0 &&
281 $page_id != $this->lm->getHeaderPage() &&
282 ($page_id == 0 || $page_id != $this->lm->getFooterPage())) {
283 if (ilLMObject::_exists($this->lm->getHeaderPage())) {
284 $head = $this->render($this->lm->getHeaderPage());
285 }
286 }
287
288 // process footer
289 if ($this->lm->getFooterPage() > 0 &&
290 $page_id != $this->lm->getFooterPage() &&
291 ($page_id == 0 || $page_id != $this->lm->getHeaderPage())) {
292 if (ilLMObject::_exists($this->lm->getFooterPage())) {
293 $foot = $this->render($this->lm->getFooterPage());
294 }
295 }
296 return $head . $focus_mess . $ret . $foot;
297 }
298
299 public function getLMPageGUI(int $a_id): ilLMPageGUI
300 {
301 if ($this->lang != "-" && ilPageObject::_exists("lm", $a_id, $this->lang)) {
302 $page_gui = new ilLMPageGUI($a_id, 0, false, $this->lang, $this->concrete_lang);
303 } else {
304 if ($this->lang != "-" && ilPageObject::_exists("lm", $a_id, $this->ot->getFallbackLanguage())) {
305 $page_gui = new ilLMPageGUI($a_id, 0, false, $this->ot->getFallbackLanguage(), $this->concrete_lang);
306 } else {
307 $page_gui = new ilLMPageGUI($a_id, 0, false, "", $this->concrete_lang);
308 }
309 }
310 if ($this->offline) {
311 $page_gui->setOutputMode(ilPageObjectGUI::OFFLINE);
312 }
313 return $page_gui;
314 }
315
316 public function handleCodeParagraph(
317 int $page_id,
318 int $paragraph_id,
319 string $title,
320 string $text
321 ): void {
322 $directory = $this->parent_gui->getOfflineDirectory() . "/codefiles/" . $page_id . "/" . $paragraph_id;
323 ilFileUtils::makeDirParents($directory);
324 $file = $directory . "/" . $title;
325 if (!($fp = fopen($file, "w+"))) {
326 die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
327 " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
328 }
329 chmod($file, 0770);
330 fwrite($fp, $text);
331 fclose($fp);
332 }
333
334 protected function renderFocusMessage(): string
335 {
336 $focus_mess = "";
337 if ($this->focus_id > 0) {
338 $path = $this->lm_tree->getPathId($this->current_page);
339
340 // out of focus
341 if (!in_array($this->focus_id, $path)) {
342 $mtpl = new ilTemplate(
343 "tpl.out_of_focus_message.html",
344 true,
345 true,
346 "Modules/LearningModule"
347 );
348 $mtpl->setVariable("MESSAGE", $this->lng->txt("cont_out_of_focus_message"));
349 $mtpl->setVariable("TXT_SHOW_CONTENT", $this->lng->txt("cont_show_content_after_focus"));
350
351 if ($this->requested_focus_return == 0 || ilObject::_lookupType((int) $this->requested_focus_return, true) != "crs") {
352 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_beginning"));
353 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->focus_id);
354 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
355 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->requested_obj_id);
356 } else {
357 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_return_crs"));
358 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", ilLink::_getLink($this->requested_focus_return));
359 }
360
361 $this->ctrl->setParameter($this->parent_gui, "focus_id", null);
362 $mtpl->setVariable("LINK_SHOW_CONTENT", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
363 $this->ctrl->setParameter($this->parent_gui, "focus_id", $this->requested_obj_id);
364
365 $focus_mess = $mtpl->get();
366 } else {
367 $succ_page_id = $this->navigation_status->getSuccessorPageId();
368 $path2 = array();
369 if ($succ_page_id > 0) {
370 $path2 = $this->lm_tree->getPathId($succ_page_id);
371 }
372 if ($succ_page_id == 0 || !in_array($this->focus_id, $path2)) {
373 $mtpl = new ilTemplate(
374 "tpl.out_of_focus_message.html",
375 true,
376 true,
377 "Modules/LearningModule"
378 );
379 $mtpl->setVariable("MESSAGE", $this->lng->txt("cont_out_of_focus_message_last_page"));
380 $mtpl->setVariable("TXT_SHOW_CONTENT", $this->lng->txt("cont_show_content_after_focus"));
381
382 if ($this->requested_focus_return == 0 || ilObject::_lookupType($this->requested_focus_return, true) != "crs") {
383 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_beginning"));
384 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->focus_id);
385 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
386 $this->ctrl->setParameter($this->parent_gui, "obj_id", $this->requested_obj_id);
387 } else {
388 $mtpl->setVariable("TXT_BACK_BEGINNING", $this->lng->txt("cont_to_focus_return_crs"));
389 $mtpl->setVariable("LINK_BACK_TO_BEGINNING", ilLink::_getLink($this->requested_focus_return));
390 }
391
392 $this->ctrl->setParameter($this->parent_gui, "focus_id", null);
393 $mtpl->setVariable("LINK_SHOW_CONTENT", $this->ctrl->getLinkTarget($this->parent_gui, "layout"));
394 $this->ctrl->setParameter($this->parent_gui, "focus_id", $this->requested_obj_id);
395
396 $focus_mess = $mtpl->get();
397 }
398 }
399 }
400 return $focus_mess;
401 }
402
403
407 protected function renderNoPageAccess(): string
408 {
409 return $this->renderMessageScreen($this->lng->txt("msg_no_page_access"));
410 }
411
415 protected function renderMessageScreen(string $a_content): string
416 {
417 // content style
418 $tpl = new ilTemplate("tpl.page_message_screen.html", true, true, "Modules/LearningModule");
419 $tpl->setVariable("TXT_PAGE_NO_PUBLIC_ACCESS", $a_content);
420
421 return $tpl->get();
422 }
423
427 protected function renderNoPublicAccess(): string
428 {
429 return $this->renderMessageScreen($this->lng->txt("msg_page_no_public_access"));
430 }
431
436 protected function renderNavRestrictionDueToQuestions(): string
437 {
438 return $this->renderMessageScreen($this->lng->txt("cont_no_page_access_unansw_q"));
439 }
440
444 protected function renderNoPageInChapterMessage(): string
445 {
446 $mtpl = new ilTemplate(
447 "tpl.no_content_message.html",
448 true,
449 true,
450 "Modules/LearningModule"
451 );
452 $mtpl->setVariable("MESSAGE", $this->lng->txt("cont_no_page_in_chapter"));
453 $mtpl->setVariable(
454 "ITEM_TITLE",
455 ilLMObject::_lookupTitle($this->requested_obj_id)
456 );
457 return $mtpl->get();
458 }
459
463 protected function renderNoPageFoundMessage(): string
464 {
465 return $this->renderMessageScreen($this->lng->txt("cont_no_page"));
466 }
467
468 protected function renderDeactivatedPageMessage(): string
469 {
470 $mtpl = new ilTemplate(
471 "tpl.no_content_message.html",
472 true,
473 true,
474 "Modules/LearningModule"
475 );
476 $m = $this->lng->txt("cont_page_currently_deactivated");
477 $act_data = ilLMPage::_lookupActivationData($this->requested_obj_id, $this->lm->getType());
478 if ($act_data["show_activation_info"] &&
479 (ilUtil::now() < $act_data["activation_start"])) {
480 $m .= "<p>" . sprintf(
481 $this->lng->txt("cont_page_activation_on"),
483 new ilDateTime($act_data["activation_start"], IL_CAL_DATETIME)
484 )
485 ) .
486 "</p>";
487 }
488 $mtpl->setVariable("MESSAGE", $m);
489 $mtpl->setVariable(
490 "ITEM_TITLE",
491 ilLMObject::_lookupTitle($this->requested_obj_id)
492 );
493 return $mtpl->get();
494 }
495
496
500 public function renderPreconditionsOfPage(): string
501 {
502 $succ_node = "";
503 $conds = ilObjContentObject::_getMissingPreconditionsOfPage($this->lm->getRefId(), $this->lm->getId(), $this->current_page);
504 $topchap = ilObjContentObject::_getMissingPreconditionsTopChapter($this->lm->getRefId(), $this->lm->getId(), $this->current_page);
505
506 $ptpl = new ilTemplate("tpl.page_preconditions.html", true, true, "Modules/LearningModule");
507
508 // list all missing preconditions
509 foreach ($conds as $cond) {
510 $obj_link = ilLink::_getLink($cond["trigger_ref_id"]);
511 $ptpl->setCurrentBlock("condition");
512 $ptpl->setVariable("VAL_ITEM", ilObject::_lookupTitle($cond["trigger_obj_id"]));
513 $ptpl->setVariable("LINK_ITEM", $obj_link);
514 if ($cond["operator"] == "passed") {
515 $cond_str = $this->lng->txt("passed");
516 } else {
517 $cond_str = $this->lng->txt("condition_" . $cond["operator"]);
518 }
519 $ptpl->setVariable("VAL_CONDITION", $cond_str . " " . $cond["value"]);
520 $ptpl->parseCurrentBlock();
521 }
522
523 $ptpl->setVariable(
524 "TXT_MISSING_PRECONDITIONS",
525 sprintf(
526 $this->lng->txt("cont_missing_preconditions"),
528 )
529 );
530 $ptpl->setVariable("TXT_ITEM", $this->lng->txt("object"));
531 $ptpl->setVariable("TXT_CONDITION", $this->lng->txt("condition"));
532
533 // output skip chapter link
534 $parent = $this->lm_tree->getParentId($topchap);
535 $childs = $this->lm_tree->getChildsByType($parent, "st");
536 $j = -2;
537 $i = 1;
538 foreach ($childs as $child) {
539 if ($child["child"] == $topchap) {
540 $j = $i;
541 }
542 if ($i++ == ($j + 1)) {
543 $succ_node = $this->lm_tree->fetchSuccessorNode($child["child"], "pg");
544 }
545 }
546 if ($succ_node != "") {
547 $link = "<br /><a href=\"" .
548 $this->linker->getLink("layout", $succ_node["obj_id"], $this->requested_frame) .
549 "\">" . $this->lng->txt("cont_skip_chapter") . "</a>";
550 $ptpl->setVariable("LINK_SKIP_CHAPTER", $link);
551 }
552
553 return $ptpl->get();
554 }
555}
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)
@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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
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.
__construct(ilLMPresentationService $service, ilLMPresentationGUI $parent_gui, ilLanguage $lng, ilCtrl $ctrl, ilAccessHandler $access, ilObjUser $user, ilHelpGUI $help, int $requested_obj_id)
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 _isPagePublic(int $a_node_id, bool $a_check_public_mode=false)
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...
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...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $obj_id)
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
const ANONYMOUS_USER_ID
Definition: constants.php:27
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$path
Definition: ltiservices.php:32
$service
Definition: ltiservices.php:43
$i
Definition: metadata.php:41