ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilHelpGUI.php
Go to the documentation of this file.
1<?php
2
22
29{
30 public const ID_PART_SCREEN = "screen";
31 public const ID_PART_SUB_SCREEN = "sub_screen";
32 public const ID_PART_COMPONENT = "component";
34 protected \ILIAS\Repository\InternalGUIService $gui;
36 protected \ILIAS\Help\Presentation\PresentationManager $presentation;
37 protected \ILIAS\Help\Map\MapManager $help_map;
39
40 protected ilCtrl $ctrl;
42 protected ilLanguage $lng;
43 protected ilObjUser $user;
44 public array $help_sections = array();
45 public array $def_screen_id = array();
46 public array $screen_id = array();
47 protected string $screen_id_component = '';
48 protected \ILIAS\DI\UIServices $ui;
49 protected ?array $raw_menu_items = null;
50
51 public function __construct()
52 {
53 global $DIC;
54
55 $domain = $this->internal()->domain();
56
57 $this->settings = $domain->settings();
58 $this->lng = $domain->lng();
59 $this->user = $domain->user();
60
61 $this->help_map = $domain->map();
62 $this->presentation = $domain->presentation();
63
64 if (!isset($DIC['help.screen_id_collector'])) {
65 $DIC['help.screen_id_collector'] = function () use ($DIC) {
66 return new HelpScreenIdObserver();
67 };
68 }
69 $DIC->ctrl()->attachObserver($DIC['help.screen_id_collector']);
70 $this->observer = $DIC['help.screen_id_collector'];
71 }
72
73 protected function initUI(): void
74 {
75 $this->ui = $this->internal()->gui()->ui();
76 $gui = $this->internal()->gui();
77 $this->ctrl = $gui->ctrl();
78 $this->help_request = $gui->standardRequest();
79 }
80
81 protected function symbol(): \ILIAS\Repository\Symbol\SymbolAdapterGUI
82 {
83 global $DIC;
84 return $DIC->repository()->internal()->gui()->symbol();
85 }
86
87 public function setDefaultScreenId(
88 string $a_part,
89 string $a_id
90 ): void {
91 $this->def_screen_id[$a_part] = $a_id;
92 }
93
94 public function setScreenId(string $a_id): void
95 {
96 $this->screen_id[self::ID_PART_SCREEN] = $a_id;
97 }
98
99 public function setSubScreenId(string $a_id): void
100 {
101 $this->screen_id[self::ID_PART_SUB_SCREEN] = $a_id;
102 }
103
104 public function setScreenIdComponent(string $a_comp): void
105 {
106 $this->screen_id_component = $a_comp;
107 }
108
109 public function getScreenId(): string
110 {
111 return $this->observer->getScreenId();
112
113 $comp = ($this->screen_id_component != "")
114 ? $this->screen_id_component
115 : ($this->def_screen_id[self::ID_PART_COMPONENT] ?? '');
116
117 if ($comp == "") {
118 return "";
119 }
120
121 $scr_id = (isset($this->screen_id[self::ID_PART_SCREEN]) && $this->screen_id[self::ID_PART_SCREEN] != "")
122 ? $this->screen_id[self::ID_PART_SCREEN]
123 : ($this->def_screen_id[self::ID_PART_SCREEN] ?? '');
124
125 $sub_scr_id = (isset($this->screen_id[self::ID_PART_SUB_SCREEN]) && $this->screen_id[self::ID_PART_SUB_SCREEN] != "")
126 ? $this->screen_id[self::ID_PART_SUB_SCREEN]
127 : ($this->def_screen_id[self::ID_PART_SUB_SCREEN] ?? '');
128
129 $screen_id = $comp . "/" .
130 $scr_id . "/" .
131 $sub_scr_id;
132
133 return $screen_id;
134 }
135
136 public function addHelpSection(
137 string $a_help_id,
138 int $a_level = 1
139 ): void {
140 $this->help_sections[] = array("help_id" => $a_help_id, $a_level);
141 }
142
143 public function hasSections(): bool
144 {
145 return $this->help_map->hasScreenIdSections($this->getScreenId());
146 }
147
148 public function getHelpSections(): array
149 {
150 return $this->help_map->getHelpSectionsForId(
151 $this->getScreenId(),
152 $this->help_request->getRefId()
153 );
154 }
155
156 public function setCtrlPar(): void
157 {
158 $ilCtrl = $this->ctrl;
159 $refId = (string) $this->help_request->getRefId();
160 $ilCtrl->setParameterByClass("ilhelpgui", "help_screen_id", $this->getScreenId() . "." . $refId);
161 }
162
163 public function executeCommand(): string
164 {
165 $this->initUI();
166 $cmd = $this->ctrl->getCmd("showHelp") ?: "showHelp";
167 return (string) $this->$cmd();
168 }
169
170 public function showHelp(): void
171 {
173 $lng->loadLanguageModule("help");
174 $ui = $this->ui;
175 if ($this->help_request->getHelpScreenId() !== "") {
176 ilSession::set("help_screen_id", $this->help_request->getHelpScreenId());
177 $help_screen_id = $this->help_request->getHelpScreenId();
178 } else {
179 $help_screen_id = ilSession::get("help_screen_id");
180 }
181
182 ilSession::set("help_search_term", "");
183
184 $this->resetCurrentPage();
185
186 $id_arr = explode(".", $help_screen_id);
187 $help_arr = $this->help_map->getHelpSectionsForId($id_arr[0], (int) $id_arr[1]);
188
189 if (count($help_arr) > 0) {
190 $acc = new ilAccordionGUI();
191 $acc->setId("oh_acc");
192 $acc->setUseSessionStorage(true);
193 $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
194
195 foreach ($help_arr as $h_id) {
196 $st_id = $h_id;
197 if (!ilLMObject::_exists($st_id)) {
198 continue;
199 }
200 $oh_lm_id = ilLMObject::_lookupContObjID($st_id);
201 $pages = ilLMObject::getPagesOfChapter($oh_lm_id, $st_id);
202 $items = [];
203 foreach ($pages as $pg) {
204 $items[] = $this->ui->factory()->button()->shy(
205 $this->replaceMenuItemTags(ilLMObject::_lookupTitle($pg["child"])),
206 "#"
207 )->withOnLoadCode(function ($id) use ($pg) {
208 return "document.getElementById('$id').addEventListener('click', () => {return il.Help.showPage(" . $pg["child"] . ");})";
209 });
210 }
211 $list = $this->ui->factory()->listing()->unordered($items);
212 $acc->addItem(ilLMObject::_lookupTitle($st_id), $this->ui->renderer()->renderAsync($list));
213 }
214
215 $h_tpl = new ilTemplate("tpl.help.html", true, true, "components/ILIAS/Help");
216 $h_tpl->setVariable("HEAD", $lng->txt("help"));
217
218 $h_tpl->setCurrentBlock("search");
219 $h_tpl->setVariable("GL_SEARCH", $this->symbol()->glyph("search")->render());
220 $h_tpl->setVariable("HELP_SEARCH_LABEL", $this->lng->txt("help_search_label"));
221 $h_tpl->parseCurrentBlock();
222
223 if (count($help_arr) > 0) {
224 $h_tpl->setVariable("CONTENT", $acc->getHTML(true));
225 } else {
226 $mess = $ui->factory()->messageBox()->info($lng->txt("help_no_content"));
227 $h_tpl->setVariable("CONTENT", $ui->renderer()->render([$mess]));
228 }
229
230 $h_tpl->setVariable("CLOSE_IMG", $this->symbol()->glyph("close")->render());
231 echo $h_tpl->get();
232 }
233 exit;
234 }
235
236 public function showPage(): void
237 {
239 $ui = $this->ui;
240
241 $page_id = $this->help_request->getHelpPage();
242
243 $h_tpl = new ilTemplate("tpl.help.html", true, true, "components/ILIAS/Help");
244
245 if (($t = ilSession::get("help_search_term")) != "") {
246 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) use ($t) {
247 return
248 "$(\"#$id\").click(function() { return il.Help.search('" . ilLegacyFormElementsUtil::prepareFormOutput(
249 $t
250 ) . "'); return false;});";
251 });
252 } else {
253 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) {
254 return
255 "$(\"#$id\").click(function() { return il.Help.listHelp(event, true); return false;});";
256 });
257 }
258 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
259
260 $h_tpl->setVariable(
261 "HEAD",
262 $this->replaceMenuItemTags(ilLMObject::_lookupTitle($page_id))
263 );
264
265 if (!ilPageUtil::_existsAndNotEmpty("lm", $page_id)) {
266 exit;
267 }
268
269 // get page object
270 $page_gui = new ilLMPageGUI($page_id);
271 $cfg = $page_gui->getPageConfig();
272 $page_gui->setPresentationTitle("");
273 $page_gui->setTemplateOutput(false);
274 $page_gui->setHeader("");
275 $page_gui->setRawPageContent(true);
276 $cfg->setEnablePCType("Map", false);
277 $cfg->setEnablePCType("Tabs", false);
278 $cfg->setEnablePCType("FileList", false);
279
280 $page_gui->getPageObject()->buildDom();
281 $int_links = $page_gui->getPageObject()->getInternalLinks();
282 $link_xml = $this->getLinkXML($int_links);
283 $link_xml .= $this->getLinkTargetsXML();
284 //echo htmlentities($link_xml);
285 $page_gui->setLinkXml($link_xml);
286
287 $ret = $this->replaceMenuItemTags($page_gui->showPage());
288
289 $h_tpl->setVariable("CONTENT", $ret);
290 $h_tpl->setVariable("CLOSE_IMG", $this->symbol()->glyph("close")->render());
291
292 ilSession::set("help_pg", $page_id);
293
294 $page = $h_tpl->get();
295
296 // replace style classes
297 //$page = str_replace("ilc_text_inline_Strong", "ilHelpStrong", $page);
298
299 echo $page;
300 exit;
301 }
302
303 public function resetCurrentPage(): void
304 {
305 ilSession::clear("help_pg");
306 }
307
308 public function getTabTooltipText(string $a_tab_id): string
309 {
310 if ($this->screen_id_component != "") {
311 return $this->internal()->domain()->tooltips()->getTooltipPresentationText($this->screen_id_component . "_" . $a_tab_id);
312 }
313 return "";
314 }
315
316 public function registerTabLink(string $tab_id, \ILIAS\UI\Component\Link\Standard $link): \ILIAS\UI\Component\Link\Standard
317 {
318 $tab_id = $this->screen_id_component . "_" . $tab_id;
319 return $this->internal()->gui()->guidedTour()->guidedTourGUI()
320 ->registerTabLink($tab_id, $link);
321 }
322
323 public function initHelp(
325 string $ajax_url
326 ): void {
327 global $DIC;
328
329 $this->initUI();
330 $ilUser = $DIC->user();
331 $ilSetting = $DIC->settings();
332 $ctrl = $DIC->ctrl();
333
334 $a_tpl->addJavaScript("assets/js/ilHelp.js");
335 $a_tpl->addJavaScript("assets/js/accordion.js");
336 $a_tpl->addJavaScript("components/ILIAS/COPage/js/ilCOPagePres.js");
337
338 $this->setCtrlPar();
339 $a_tpl->addOnLoadCode(
340 "il.Help.setAjaxUrl('" .
341 $ctrl->getLinkTargetByClass("ilhelpgui", "", "", true)
342 . "');"
343 );
344
345
346 if ($this->presentation->isHelpActive()) {
347 if (ilSession::get("help_pg") > 0) {
348 $a_tpl->addOnLoadCode("il.Help.showCurrentPage(" . ilSession::get("help_pg") . ");", 3);
349 } else {
350 $a_tpl->addOnLoadCode("il.Help.listHelp(null);", 3);
351 }
352 }
353 }
354
355 public function isHelpPageActive(): bool
356 {
357 return (ilSession::get("help_pg") > 0);
358 }
359
360 public function deactivateTooltips(): void
361 {
362 $ilUser = $this->user;
363
364 $ilUser->writePref("hide_help_tt", "1");
365 }
366
367 public function activateTooltips(): void
368 {
369 $ilUser = $this->user;
370
371 $ilUser->writePref("hide_help_tt", "0");
372 }
373
374 public function getLinkXML(
375 array $a_int_links
376 ): string {
377 $href = "";
378 $link_info = "<IntLinkInfos>";
379 foreach ($a_int_links as $int_link) {
380 $target = $int_link["Target"];
381 if (strpos($target, "il__") === 0) {
382 $target_arr = explode("_", $target);
383 $target_id = $target_arr[count($target_arr) - 1];
384 $type = $int_link["Type"];
385 $targetframe = "None";
386
387 // anchor
388 $anc = $anc_add = "";
389 if (($int_link["Anchor"] ?? "") != "") {
390 $anc = $int_link["Anchor"];
391 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
392 }
393
394 switch ($type) {
395 case "PageObject":
396 case "StructureObject":
397 if ($type === "PageObject") {
398 $href = "#pg_" . $target_id;
399 } else {
400 $href = "#";
401 }
402 break;
403 }
404
405 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
406 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"\" Anchor=\"\"/>";
407 }
408 }
409 $link_info .= "</IntLinkInfos>";
410
411 return $link_info;
412 }
413
417 public function getLinkTargetsXML(): string
418 {
419 $link_info = "<LinkTargets>";
420 $link_info .= "<LinkTarget TargetFrame=\"None\" LinkTarget=\"\" OnClick=\"return il.Help.openLink(event);\" />";
421 $link_info .= "</LinkTargets>";
422 return $link_info;
423 }
424
425 public function search(): void
426 {
428 $ui = $this->ui;
429
430 $term = $this->help_request->getTerm();
431
432 if ($term === "") {
433 $term = ilSession::get("help_search_term");
434 }
435
436 $this->resetCurrentPage();
437
438 $h_tpl = new ilTemplate("tpl.help.html", true, true, "components/ILIAS/Help");
439
440 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) {
441 return
442 "$(\"#$id\").click(function() { return il.Help.listHelp(event, true); return false;});";
443 });
444 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
445
446 $h_tpl->setVariable("HEAD", $lng->txt("help") . " - " .
447 $lng->txt("search_result"));
448
449 $h_tpl->setCurrentBlock("search");
450 $h_tpl->setVariable("GL_SEARCH", $this->symbol()->glyph("search")->render());
451 $h_tpl->setVariable("HELP_SEARCH_LABEL", $this->lng->txt("help_search_label"));
452 $h_tpl->setVariable("VAL_SEARCH", ilLegacyFormElementsUtil::prepareFormOutput($term));
453 $h_tpl->parseCurrentBlock();
454
455 $h_tpl->setVariable("CLOSE_IMG", $this->symbol()->glyph("close")->render());
456
457 $items = [];
458 $module = $this->internal()->domain()->module();
459 foreach ($module->getActiveModules() as $module_id) {
460 $lm_id = $module->lookupModuleLmId($module_id);
461 $s = new ilRepositoryObjectDetailSearch($lm_id);
462 $s->setQueryString($term);
463 $result = $s->performSearch();
464 foreach ($result->getResults() as $r) {
465 $items[] = $this->ui->factory()->button()->shy(
466 ilLMObject::_lookupTitle($r["item_id"]),
467 "#"
468 )->withOnLoadCode(function ($id) use ($r) {
469 return "document.getElementById('$id').addEventListener('click', () => {return il.Help.showPage(" . $r["item_id"] . ");})";
470 });
471 }
472 }
473
474 $list = $this->ui->factory()->listing()->unordered($items);
475 $h_tpl->setVariable("CONTENT", $this->ui->renderer()->renderAsync($list));
476
477 ilSession::set("help_search_term", $term);
478
479 echo $h_tpl->get();
480 exit;
481 }
482
483 protected function replaceMenuItemTags(
484 string $content
485 ): string {
486 global $DIC;
487
488 $mmc = $DIC->globalScreen()->collector()->mainmenu();
489 if ($this->raw_menu_items == null) {
490 $mmc->collectOnce();
491 $this->raw_menu_items = iterator_to_array($mmc->getRawItems());
492 }
493
494 foreach ($this->raw_menu_items as $item) {
495 if ($item instanceof Item\LinkList) {
496 foreach ($item->getLinks() as $link) {
497 $content = $this->replaceItemTag($content, $link);
498 }
499 }
500 $content = $this->replaceItemTag($content, $item);
501 }
502 return $content;
503 }
504
505 protected function replaceItemTag(
506 string $content,
508 ): string {
509 global $DIC;
510 $mmc = $DIC->globalScreen()->collector()->mainmenu();
511
512 $id = $item->getProviderIdentification()->getInternalIdentifier();
513 $ws = "[ \t\r\f\v\n]*";
514
515 // menu item path
516 while (preg_match("~\[(menu" . $ws . "path$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
517 $path = "";
518 if ($item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isChild) {
519 $parent = $mmc->getItemInformation()->getParent($item);
520 if ($parent !== null) {
521 $parent = $mmc->getSingleItemFromRaw($parent);
522 $path = $this->getTitleForItem($parent) . " > ";
523 }
524 }
525 $path .= $this->getTitleForItem($item);
526 $content = preg_replace(
527 '~\[' . $found[1] . '/\]~i',
528 "<strong>" . $path . "</strong>",
529 $content
530 );
531 }
532 // menu item
533 while (preg_match("~\[(menu" . $ws . "item$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
534 $content = preg_replace(
535 '~\[' . $found[1] . '/\]~i',
536 "<strong>" . $this->getTitleForItem($item) . "</strong>",
537 $content
538 );
539 }
540 return $content;
541 }
542
547 protected function getTitleForItem(
548 \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item
549 ): string {
550 global $DIC;
551
553 $i = $item;
554 $mmc = $DIC->globalScreen()->collector()->mainmenu();
555 return $mmc->getItemInformation()->customTranslationForUser($i)->getTitle();
556 }
557
558 public function showTooltips(): bool
559 {
560 return $this->presentation->showTooltips();
561 }
562
563 public function isHelpActive(): bool
564 {
565 return $this->internal()->domain()->module()->isHelpActive();
566 }
567
568 public function areTooltipsActive(): bool
569 {
570 return $this->internal()->domain()->module()->areTooltipsActive();
571 }
572
576 public function internal(): \ILIAS\Help\InternalService
577 {
578 global $DIC;
579
580 if (is_null(self::$internal_service)) {
581 self::$internal_service = new \ILIAS\Help\InternalService(
582 $DIC
583 );
584 }
585 return self::$internal_service;
586 }
587}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Definition: UI.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
Help GUI class.
initHelp(ilGlobalTemplateInterface $a_tpl, string $ajax_url)
ilObjUser $user
ILIAS Help Presentation PresentationManager $presentation
getLinkXML(array $a_int_links)
string $screen_id_component
StandardGUIRequest $help_request
const ID_PART_COMPONENT
getLinkTargetsXML()
Get XMl for Link Targets.
array $screen_id
ilLanguage $lng
registerTabLink(string $tab_id, \ILIAS\UI\Component\Link\Standard $link)
ILIAS Repository InternalGUIService $gui
setScreenId(string $a_id)
setScreenIdComponent(string $a_comp)
const ID_PART_SCREEN
array $raw_menu_items
setSubScreenId(string $a_id)
const ID_PART_SUB_SCREEN
addHelpSection(string $a_help_id, int $a_level=1)
setDefaultScreenId(string $a_part, string $a_id)
replaceItemTag(string $content, \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item)
ILIAS Help Map MapManager $help_map
array $def_screen_id
ILIAS DI UIServices $ui
replaceMenuItemTags(string $content)
ilSetting $settings
static ILIAS Help InternalService $internal_service
getTabTooltipText(string $a_tab_id)
HelpScreenIdObserver $observer
array $help_sections
static getPagesOfChapter(int $a_lm_id, int $a_chap_id)
Get pages of chapter.
static _exists(int $a_id)
checks wether a lm content object with specified id exists or not
static _lookupContObjID(int $a_id)
get learning module id for lm object
static _lookupTitle(int $a_obj_id)
Extension of ilPageObjectGUI for learning modules.
language handling
static prepareFormOutput($a_str, bool $a_strip=false)
User class.
static _existsAndNotEmpty(string $a_parent_type, int $a_id, string $a_lang="-")
checks whether page exists and is not empty (may return true on some empty pages)
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
exit
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
This describes a symbol.
Definition: Symbol.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:30
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$refId
Definition: xapitoken.php:56