ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 initHelp(
318 string $ajax_url
319 ): void {
320 global $DIC;
321
322 $this->initUI();
323 $ilUser = $DIC->user();
324 $ilSetting = $DIC->settings();
325 $ctrl = $DIC->ctrl();
326
327 $a_tpl->addJavaScript("assets/js/ilHelp.js");
328 $a_tpl->addJavaScript("assets/js/accordion.js");
330 $a_tpl->addJavaScript("components/ILIAS/COPage/js/ilCOPagePres.js");
331
332 $this->setCtrlPar();
333 $a_tpl->addOnLoadCode(
334 "il.Help.setAjaxUrl('" .
335 $ctrl->getLinkTargetByClass("ilhelpgui", "", "", true)
336 . "');"
337 );
338
339
340 if ($this->presentation->isHelpActive()) {
341 if (ilSession::get("help_pg") > 0) {
342 $a_tpl->addOnLoadCode("il.Help.showCurrentPage(" . ilSession::get("help_pg") . ");", 3);
343 } else {
344 $a_tpl->addOnLoadCode("il.Help.listHelp(null);", 3);
345 }
346 }
347 }
348
349 public function isHelpPageActive(): bool
350 {
351 return (ilSession::get("help_pg") > 0);
352 }
353
354 public function deactivateTooltips(): void
355 {
356 $ilUser = $this->user;
357
358 $ilUser->writePref("hide_help_tt", "1");
359 }
360
361 public function activateTooltips(): void
362 {
363 $ilUser = $this->user;
364
365 $ilUser->writePref("hide_help_tt", "0");
366 }
367
368 public function getLinkXML(
369 array $a_int_links
370 ): string {
371 $href = "";
372 $link_info = "<IntLinkInfos>";
373 foreach ($a_int_links as $int_link) {
374 $target = $int_link["Target"];
375 if (strpos($target, "il__") === 0) {
376 $target_arr = explode("_", $target);
377 $target_id = $target_arr[count($target_arr) - 1];
378 $type = $int_link["Type"];
379 $targetframe = "None";
380
381 // anchor
382 $anc = $anc_add = "";
383 if (($int_link["Anchor"] ?? "") != "") {
384 $anc = $int_link["Anchor"];
385 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
386 }
387
388 switch ($type) {
389 case "PageObject":
390 case "StructureObject":
391 if ($type === "PageObject") {
392 $href = "#pg_" . $target_id;
393 } else {
394 $href = "#";
395 }
396 break;
397 }
398
399 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
400 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"\" Anchor=\"\"/>";
401 }
402 }
403 $link_info .= "</IntLinkInfos>";
404
405 return $link_info;
406 }
407
411 public function getLinkTargetsXML(): string
412 {
413 $link_info = "<LinkTargets>";
414 $link_info .= "<LinkTarget TargetFrame=\"None\" LinkTarget=\"\" OnClick=\"return il.Help.openLink(event);\" />";
415 $link_info .= "</LinkTargets>";
416 return $link_info;
417 }
418
419 public function search(): void
420 {
422 $ui = $this->ui;
423
424 $term = $this->help_request->getTerm();
425
426 if ($term === "") {
427 $term = ilSession::get("help_search_term");
428 }
429
430 $this->resetCurrentPage();
431
432 $h_tpl = new ilTemplate("tpl.help.html", true, true, "components/ILIAS/Help");
433
434 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) {
435 return
436 "$(\"#$id\").click(function() { return il.Help.listHelp(event, true); return false;});";
437 });
438 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
439
440 $h_tpl->setVariable("HEAD", $lng->txt("help") . " - " .
441 $lng->txt("search_result"));
442
443 $h_tpl->setCurrentBlock("search");
444 $h_tpl->setVariable("GL_SEARCH", $this->symbol()->glyph("search")->render());
445 $h_tpl->setVariable("HELP_SEARCH_LABEL", $this->lng->txt("help_search_label"));
446 $h_tpl->setVariable("VAL_SEARCH", ilLegacyFormElementsUtil::prepareFormOutput($term));
447 $h_tpl->parseCurrentBlock();
448
449 $h_tpl->setVariable("CLOSE_IMG", $this->symbol()->glyph("close")->render());
450
451 $items = [];
452 $module = $this->internal()->domain()->module();
453 foreach ($module->getActiveModules() as $module_id) {
454 $lm_id = $module->lookupModuleLmId($module_id);
455 $s = new ilRepositoryObjectDetailSearch($lm_id);
456 $s->setQueryString($term);
457 $result = $s->performSearch();
458 foreach ($result->getResults() as $r) {
459 $items[] = $this->ui->factory()->button()->shy(
460 ilLMObject::_lookupTitle($r["item_id"]),
461 "#"
462 )->withOnLoadCode(function ($id) use ($r) {
463 return "document.getElementById('$id').addEventListener('click', () => {return il.Help.showPage(" . $r["item_id"] . ");})";
464 });
465 }
466 }
467
468 $list = $this->ui->factory()->listing()->unordered($items);
469 $h_tpl->setVariable("CONTENT", $this->ui->renderer()->renderAsync($list));
470
471 ilSession::set("help_search_term", $term);
472
473 echo $h_tpl->get();
474 exit;
475 }
476
477 protected function replaceMenuItemTags(
478 string $content
479 ): string {
480 global $DIC;
481
482 $mmc = $DIC->globalScreen()->collector()->mainmenu();
483 if ($this->raw_menu_items == null) {
484 $mmc->collectOnce();
485 $this->raw_menu_items = iterator_to_array($mmc->getRawItems());
486 }
487
488 foreach ($this->raw_menu_items as $item) {
489 if ($item instanceof Item\LinkList) {
490 foreach ($item->getLinks() as $link) {
491 $content = $this->replaceItemTag($content, $link);
492 }
493 }
494 $content = $this->replaceItemTag($content, $item);
495 }
496 return $content;
497 }
498
499 protected function replaceItemTag(
500 string $content,
502 ): string {
503 global $DIC;
504 $mmc = $DIC->globalScreen()->collector()->mainmenu();
505
506 $id = $item->getProviderIdentification()->getInternalIdentifier();
507 $ws = "[ \t\r\f\v\n]*";
508
509 // menu item path
510 while (preg_match("~\[(menu" . $ws . "path$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
511 $path = "";
512 if ($item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isChild) {
513 $parent = $mmc->getItemInformation()->getParent($item);
514 if ($parent !== null) {
515 $parent = $mmc->getSingleItemFromRaw($parent);
516 $path = $this->getTitleForItem($parent) . " > ";
517 }
518 }
519 $path .= $this->getTitleForItem($item);
520 $content = preg_replace(
521 '~\[' . $found[1] . '/\]~i',
522 "<strong>" . $path . "</strong>",
523 $content
524 );
525 }
526 // menu item
527 while (preg_match("~\[(menu" . $ws . "item$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
528 $content = preg_replace(
529 '~\[' . $found[1] . '/\]~i',
530 "<strong>" . $this->getTitleForItem($item) . "</strong>",
531 $content
532 );
533 }
534 return $content;
535 }
536
541 protected function getTitleForItem(
542 \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item
543 ): string {
544 global $DIC;
545
547 $i = $item;
548 $mmc = $DIC->globalScreen()->collector()->mainmenu();
549 return $mmc->getItemInformation()->customTranslationForUser($i)->getTitle();
550 }
551
552 public function showTooltips(): bool
553 {
554 return $this->presentation->showTooltips();
555 }
556
557 public function isHelpActive(): bool
558 {
559 return $this->internal()->domain()->module()->isHelpActive();
560 }
561
562 public function areTooltipsActive(): bool
563 {
564 return $this->internal()->domain()->module()->areTooltipsActive();
565 }
566
570 public function internal(): \ILIAS\Help\InternalService
571 {
572 global $DIC;
573
574 if (is_null(self::$internal_service)) {
575 self::$internal_service = new \ILIAS\Help\InternalService(
576 $DIC
577 );
578 }
579 return self::$internal_service;
580 }
581}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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
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
static initMaphilight()
Inits and add maphilight to the general template.
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:58