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