ILIAS  release_8 Revision v8.24
class.ilHelpGUI.php
Go to the documentation of this file.
1<?php
2
21
28{
29 public const ID_PART_SCREEN = "screen";
30 public const ID_PART_SUB_SCREEN = "sub_screen";
31 public const ID_PART_COMPONENT = "component";
33
34 protected ilCtrl $ctrl;
36 protected ilLanguage $lng;
37 protected ilObjUser $user;
38 public array $help_sections = array();
39 public array $def_screen_id = array();
40 public array $screen_id = array();
41 protected string $screen_id_component = '';
42 protected \ILIAS\DI\UIServices $ui;
43 protected ?array $raw_menu_items = null;
44
45 public function __construct()
46 {
47 global $DIC;
48
49 $this->settings = $DIC->settings();
50 $this->lng = $DIC->language();
51 $this->user = $DIC->user();
52 $ilCtrl = $DIC->ctrl();
53
54 $this->ctrl = $ilCtrl;
55 $this->ui = $DIC->ui();
56 $this->help_request = new StandardGUIRequest(
57 $DIC->http(),
58 $DIC->refinery()
59 );
60 }
61
62 public function setDefaultScreenId(
63 string $a_part,
64 string $a_id
65 ): void {
66 $this->def_screen_id[$a_part] = $a_id;
67 }
68
69 public function setScreenId(string $a_id): void
70 {
71 $this->screen_id[self::ID_PART_SCREEN] = $a_id;
72 }
73
74 public function setSubScreenId(string $a_id): void
75 {
76 $this->screen_id[self::ID_PART_SUB_SCREEN] = $a_id;
77 }
78
79 public function setScreenIdComponent(string $a_comp): void
80 {
81 $this->screen_id_component = $a_comp;
82 }
83
84 public function getScreenId(): string
85 {
86 $comp = ($this->screen_id_component != "")
87 ? $this->screen_id_component
88 : ($this->def_screen_id[self::ID_PART_COMPONENT] ?? '');
89
90 if ($comp == "") {
91 return "";
92 }
93
94 $scr_id = (isset($this->screen_id[self::ID_PART_SCREEN]) && $this->screen_id[self::ID_PART_SCREEN] != "")
95 ? $this->screen_id[self::ID_PART_SCREEN]
96 : ($this->def_screen_id[self::ID_PART_SCREEN] ?? '');
97
98 $sub_scr_id = (isset($this->screen_id[self::ID_PART_SUB_SCREEN]) && $this->screen_id[self::ID_PART_SUB_SCREEN] != "")
99 ? $this->screen_id[self::ID_PART_SUB_SCREEN]
100 : ($this->def_screen_id[self::ID_PART_SUB_SCREEN] ?? '');
101
102 $screen_id = $comp . "/" .
103 $scr_id . "/" .
104 $sub_scr_id;
105
106 return $screen_id;
107 }
108
109 public function addHelpSection(
110 string $a_help_id,
111 int $a_level = 1
112 ): void {
113 $this->help_sections[] = array("help_id" => $a_help_id, $a_level);
114 }
115
116 public function hasSections(): bool
117 {
118 return ilHelpMapping::hasScreenIdSections($this->getScreenId());
119 }
120
121 public function getHelpSections(): array
122 {
124 $this->getScreenId(),
125 $this->help_request->getRefId()
126 );
127 }
128
129 public function setCtrlPar(): void
130 {
131 $ilCtrl = $this->ctrl;
132 $refId = (string) $this->help_request->getRefId();
133 $ilCtrl->setParameterByClass("ilhelpgui", "help_screen_id", $this->getScreenId() . "." . $refId);
134 }
135
136 public function executeCommand(): string
137 {
138 $cmd = $this->ctrl->getCmd("showHelp") ?: "showHelp";
139 return (string) $this->$cmd();
140 }
141
142 public function showHelp(): void
143 {
145 $lng->loadLanguageModule("help");
146 $ui = $this->ui;
147
148 if ($this->help_request->getHelpScreenId() !== "") {
149 ilSession::set("help_screen_id", $this->help_request->getHelpScreenId());
150 $help_screen_id = $this->help_request->getHelpScreenId();
151 } else {
152 $help_screen_id = ilSession::get("help_screen_id");
153 }
154
155 ilSession::set("help_search_term", "");
156
157 $this->resetCurrentPage();
158
159 $id_arr = explode(".", $help_screen_id);
160 $help_arr = ilHelpMapping::getHelpSectionsForId($id_arr[0], $id_arr[1]);
161 $oh_lm_id = ilHelp::getHelpLMId();
162
163 if ($oh_lm_id > 0) {
164 $acc = new ilAccordionGUI();
165 $acc->setId("oh_acc");
166 $acc->setUseSessionStorage(true);
167 $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
168
169 foreach ($help_arr as $h_id) {
170 $st_id = $h_id;
171 if (!ilLMObject::_exists($st_id)) {
172 continue;
173 }
174
175 $pages = ilLMObject::getPagesOfChapter($oh_lm_id, $st_id);
176 $grp_list = new ilGroupedListGUI();
177 foreach ($pages as $pg) {
178 $grp_list->addEntry(
179 $this->replaceMenuItemTags(ilLMObject::_lookupTitle($pg["child"])),
180 "#",
181 "",
182 "return il.Help.showPage(" . $pg["child"] . ");"
183 );
184 }
185
186 $acc->addItem(ilLMObject::_lookupTitle($st_id), $grp_list->getHTML());
187 }
188
189 $h_tpl = new ilTemplate("tpl.help.html", true, true, "Services/Help");
190 $h_tpl->setVariable("HEAD", $lng->txt("help"));
191
192 $h_tpl->setCurrentBlock("search");
193 $h_tpl->setVariable("GL_SEARCH", ilGlyphGUI::get(ilGlyphGUI::SEARCH));
194 $h_tpl->setVariable("HELP_SEARCH_LABEL", $this->lng->txt("help_search_label"));
195 $h_tpl->parseCurrentBlock();
196
197 if (count($help_arr) > 0) {
198 $h_tpl->setVariable("CONTENT", $acc->getHTML(true));
199 } else {
200 $mess = $ui->factory()->messageBox()->info($lng->txt("help_no_content"));
201 $h_tpl->setVariable("CONTENT", $ui->renderer()->render([$mess]));
202 }
203
204 $h_tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
205 echo $h_tpl->get();
206 }
207 exit;
208 }
209
210 public function showPage(): void
211 {
213 $ui = $this->ui;
214
215 $page_id = $this->help_request->getHelpPage();
216
217 $h_tpl = new ilTemplate("tpl.help.html", true, true, "Services/Help");
218
219 if (($t = ilSession::get("help_search_term")) != "") {
220 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) use ($t) {
221 return
222 "$(\"#$id\").click(function() { return il.Help.search('" . ilLegacyFormElementsUtil::prepareFormOutput(
223 $t
224 ) . "'); return false;});";
225 });
226 } else {
227 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) {
228 return
229 "$(\"#$id\").click(function() { return il.Help.listHelp(event, true); return false;});";
230 });
231 }
232 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
233
234 $h_tpl->setVariable(
235 "HEAD",
236 $this->replaceMenuItemTags(ilLMObject::_lookupTitle($page_id))
237 );
238
239 if (!ilPageUtil::_existsAndNotEmpty("lm", $page_id)) {
240 exit;
241 }
242
243 // get page object
244 $page_gui = new ilLMPageGUI($page_id);
245 $cfg = $page_gui->getPageConfig();
246 $page_gui->setPresentationTitle("");
247 $page_gui->setTemplateOutput(false);
248 $page_gui->setHeader("");
249 $page_gui->setRawPageContent(true);
250 $cfg->setEnablePCType("Map", false);
251 $cfg->setEnablePCType("Tabs", false);
252 $cfg->setEnablePCType("FileList", false);
253
254 $page_gui->getPageObject()->buildDom();
255 $int_links = $page_gui->getPageObject()->getInternalLinks();
256 $link_xml = $this->getLinkXML($int_links);
257 $link_xml .= $this->getLinkTargetsXML();
258 //echo htmlentities($link_xml);
259 $page_gui->setLinkXml($link_xml);
260
261 $ret = $this->replaceMenuItemTags($page_gui->showPage());
262
263 $h_tpl->setVariable("CONTENT", $ret);
264 $h_tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
265
266 ilSession::set("help_pg", $page_id);
267
268 $page = $h_tpl->get();
269
270 // replace style classes
271 //$page = str_replace("ilc_text_inline_Strong", "ilHelpStrong", $page);
272
273 echo $page;
274 exit;
275 }
276
277 public function resetCurrentPage(): void
278 {
279 ilSession::clear("help_pg");
280 }
281
282 public function getTabTooltipText(string $a_tab_id): string
283 {
284 if ($this->screen_id_component != "") {
285 return ilHelp::getTooltipPresentationText($this->screen_id_component . "_" . $a_tab_id);
286 }
287 return "";
288 }
289
290 public function initHelp(
292 string $ajax_url
293 ): void {
294 global $DIC;
295
296 $ilUser = $DIC->user();
297 $ilSetting = $DIC->settings();
298 $ctrl = $DIC->ctrl();
299
301 $a_tpl->addJavaScript("./Services/Help/js/ilHelp.js");
302 $a_tpl->addJavaScript("./Services/Accordion/js/accordion.js");
304 $a_tpl->addJavaScript("./Services/COPage/js/ilCOPagePres.js");
305
306 $this->setCtrlPar();
307 $a_tpl->addOnLoadCode(
308 "il.Help.setAjaxUrl('" .
309 $ctrl->getLinkTargetByClass("ilhelpgui", "", "", true)
310 . "');"
311 );
312
313
314 $module_id = (int) $ilSetting->get("help_module");
315
316 if (((int) OH_REF_ID > 0 || $module_id > 0) && $ilUser->getLanguage() === "de") {
317 if (ilSession::get("help_pg") > 0) {
318 $a_tpl->addOnLoadCode("il.Help.showCurrentPage(" . ilSession::get("help_pg") . ");", 3);
319 } else {
320 $a_tpl->addOnLoadCode("il.Help.listHelp(null);", 3);
321 }
322
323
324 if ($ilUser->getPref("hide_help_tt")) {
325 $a_tpl->addOnLoadCode("if (il && il.Help) {il.Help.switchTooltips();}", 3);
326 }
327 }
328 }
329
330 public function isHelpPageActive(): bool
331 {
332 return (ilSession::get("help_pg") > 0);
333 }
334
335 public function deactivateTooltips(): void
336 {
337 $ilUser = $this->user;
338
339 $ilUser->writePref("hide_help_tt", "1");
340 }
341
342 public function activateTooltips(): void
343 {
344 $ilUser = $this->user;
345
346 $ilUser->writePref("hide_help_tt", "0");
347 }
348
349 public function getLinkXML(
350 array $a_int_links
351 ): string {
352 $href = "";
353 $link_info = "<IntLinkInfos>";
354 foreach ($a_int_links as $int_link) {
355 $target = $int_link["Target"];
356 if (strpos($target, "il__") === 0) {
357 $target_arr = explode("_", $target);
358 $target_id = $target_arr[count($target_arr) - 1];
359 $type = $int_link["Type"];
360 $targetframe = "None";
361
362 // anchor
363 $anc = $anc_add = "";
364 if (($int_link["Anchor"] ?? "") != "") {
365 $anc = $int_link["Anchor"];
366 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
367 }
368
369 switch ($type) {
370 case "PageObject":
371 case "StructureObject":
372 if ($type === "PageObject") {
373 $href = "#pg_" . $target_id;
374 } else {
375 $href = "#";
376 }
377 break;
378
379 }
380
381 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
382 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"\" Anchor=\"\"/>";
383 }
384 }
385 $link_info .= "</IntLinkInfos>";
386
387 return $link_info;
388 }
389
393 public function getLinkTargetsXML(): string
394 {
395 $link_info = "<LinkTargets>";
396 $link_info .= "<LinkTarget TargetFrame=\"None\" LinkTarget=\"\" OnClick=\"return il.Help.openLink(event);\" />";
397 $link_info .= "</LinkTargets>";
398 return $link_info;
399 }
400
401 public function search(): void
402 {
404 $ui = $this->ui;
405
406 $term = $this->help_request->getTerm();
407
408 if ($term === "") {
409 $term = ilSession::get("help_search_term");
410 }
411
412 $this->resetCurrentPage();
413
414 $h_tpl = new ilTemplate("tpl.help.html", true, true, "Services/Help");
415
416 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) {
417 return
418 "$(\"#$id\").click(function() { return il.Help.listHelp(event, true); return false;});";
419 });
420 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
421
422 $h_tpl->setVariable("HEAD", $lng->txt("help") . " - " .
423 $lng->txt("search_result"));
424
425 $h_tpl->setCurrentBlock("search");
426 $h_tpl->setVariable("GL_SEARCH", ilGlyphGUI::get(ilGlyphGUI::SEARCH));
427 $h_tpl->setVariable("HELP_SEARCH_LABEL", $this->lng->txt("help_search_label"));
428 $h_tpl->setVariable("VAL_SEARCH", ilLegacyFormElementsUtil::prepareFormOutput($term));
429 $h_tpl->parseCurrentBlock();
430
431 $h_tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
432
433 $lm_id = ilHelp::getHelpLMId();
434 $s = new ilRepositoryObjectDetailSearch($lm_id);
435 $s->setQueryString($term);
436 $result = $s->performSearch();
437
438 $grp_list = new ilGroupedListGUI();
439 foreach ($result->getResults() as $r) {
440 $grp_list->addEntry(
441 ilLMObject::_lookupTitle($r["item_id"]),
442 "#",
443 "",
444 "return il.Help.showPage(" . $r["item_id"] . ");"
445 );
446 }
447 $h_tpl->setVariable("CONTENT", $grp_list->getHTML());
448
449 ilSession::set("help_search_term", $term);
450
451 echo $h_tpl->get();
452 exit;
453 }
454
455 protected function replaceMenuItemTags(
456 string $content
457 ): string {
458 global $DIC;
459
460 $mmc = $DIC->globalScreen()->collector()->mainmenu();
461 if ($this->raw_menu_items == null) {
462 $mmc->collectOnce();
463 $this->raw_menu_items = iterator_to_array($mmc->getRawItems());
464 }
465
466 foreach ($this->raw_menu_items as $item) {
467 if ($item instanceof Item\LinkList) {
468 foreach ($item->getLinks() as $link) {
469 $content = $this->replaceItemTag($content, $link);
470 }
471 }
472 $content = $this->replaceItemTag($content, $item);
473 }
474 return $content;
475 }
476
477 protected function replaceItemTag(
478 string $content,
479 \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item
480 ): string {
481 global $DIC;
482 $mmc = $DIC->globalScreen()->collector()->mainmenu();
483
484 $id = $item->getProviderIdentification()->getInternalIdentifier();
485 $ws = "[ \t\r\f\v\n]*";
486
487 // menu item path
488 while (preg_match("~\[(menu" . $ws . "path$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
489 $path = "";
490 if ($item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isChild) {
491 $parent = $mmc->getItemInformation()->getParent($item);
492 if ($parent !== null) {
493 $parent = $mmc->getSingleItemFromRaw($parent);
494 $path = $this->getTitleForItem($parent) . " > ";
495 }
496 }
497 $path .= $this->getTitleForItem($item);
498 $content = preg_replace(
499 '~\[' . $found[1] . '/\]~i',
500 "<strong>" . $path . "</strong>",
501 $content
502 );
503 }
504 // menu item
505 while (preg_match("~\[(menu" . $ws . "item$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
506 $content = preg_replace(
507 '~\[' . $found[1] . '/\]~i',
508 "<strong>" . $this->getTitleForItem($item) . "</strong>",
509 $content
510 );
511 }
512 return $content;
513 }
514
519 protected function getTitleForItem(
520 \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item
521 ): string {
522 global $DIC;
523
525 $i = $item;
526 $mmc = $DIC->globalScreen()->collector()->mainmenu();
527 return $mmc->getItemInformation()->customTranslationForUser($i)->getTitle();
528 }
529}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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
static get(string $a_glyph, string $a_text="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Help GUI class.
initHelp(ilGlobalTemplateInterface $a_tpl, string $ajax_url)
ilObjUser $user
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
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)
array $def_screen_id
ILIAS DI UIServices $ui
replaceMenuItemTags(string $content)
ilSetting $settings
getTabTooltipText(string $a_tab_id)
array $help_sections
static getHelpSectionsForId(string $a_screen_id, int $a_ref_id)
static hasScreenIdSections(string $a_screen_id)
Has given screen Id any sections? Note: We removed the "ref_id" parameter here, since this method sho...
static getTooltipPresentationText(string $a_tt_id)
static getHelpLMId()
Get help lm id.
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 _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.
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 initConnection(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
static initMaphilight()
Inits and add maphilight to the general template.
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
$target_arr
Definition: goto.php:50
$ilUser
Definition: imgupload.php:34
Interface ilCtrlBaseClassInterface describes ilCtrl base classes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
exit
Definition: login.php:28
$path
Definition: ltiservices.php:32
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Complex.php:21
Class ChatMainBarProvider \MainMenu\Provider.
global $ilSetting
Definition: privfeed.php:17
$type
$lng
$refId
Definition: xapitoken.php:58