ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLMGSToolProvider.php
Go to the documentation of this file.
1<?php
2
7
14{
15 use \ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
16
17 const SHOW_TOC_TOOL = 'show_toc_tool';
18 const LM_QUERY_PARAMS = 'lm_query_params';
19 const LM_OFFLINE = 'lm_offline';
20
21
26 {
27 return $this->context_collection->main()->repository();
28 }
29
30
34 public function getToolsForContextStack(CalledContexts $called_contexts) : array
35 {
36 global $DIC;
37
38 $lng = $DIC->language();
39 $access = $DIC->access();
40
41 $lng->loadLanguageModule("content");
42
43 $tools = [];
44 $additional_data = $called_contexts->current()->getAdditionalData();
45 if ($additional_data->is(self::SHOW_TOC_TOOL, true)) {
46 $iff = function ($id) {
47 return $this->identification_provider->contextAwareIdentifier($id);
48 };
49 $l = function (string $content) {
50 return $this->dic->ui()->factory()->legacy($content);
51 };
52 $ref_id = $called_contexts->current()->getReferenceId()->toInt();
53
54 if (!$access->checkAccess("read", "", $ref_id)) {
55 return $tools;
56 }
57
58
59 $tools[] = $this->getTocTool($additional_data);
60
61 $title = $lng->txt("obj_glo");
62 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("outlined/icon_glo.svg"), $title);
63 $identification = $iff("lm_glossary");
64 $hashed = $this->hash($identification->serialize());
65 $tools[] = $this->factory->tool($identification)
66 ->addComponentDecorator(static function (ILIAS\UI\Component\Component $c) use ($hashed) : ILIAS\UI\Component\Component {
67 if ($c instanceof LegacySlate) {
68 $signal_id = $c->getToggleSignal()->getId();
69 return $c->withAdditionalOnLoadCode(static function ($id) use ($hashed) {
70 return "
71 $('body').on('il-lm-show-glossary-slate', function(){
72 il.UI.maincontrols.mainbar.engageTool('$hashed');
73 });";
74 });
75 }
76 return $c;
77 })
78 ->withInitiallyHidden(true)
79 ->withTitle($title)
80 ->withContentWrapper(function () use ($l) {
81 return $l($this->getLinkSlateContent("glossary"));
82 })
83 ->withSymbol($icon)
84 ->withPosition(11);
85
86 $title = $lng->txt("cont_tool_media");
87 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("outlined/icon_mdia.svg"), $title);
88 $identification = $iff("lm_media");
89 $hashed = $this->hash($identification->serialize());
90 $tools[] = $this->factory->tool($identification)
91 ->addComponentDecorator(static function (ILIAS\UI\Component\Component $c) use ($hashed) : ILIAS\UI\Component\Component {
92 if ($c instanceof LegacySlate) {
93 $signal_id = $c->getToggleSignal()->getId();
94 return $c->withAdditionalOnLoadCode(static function ($id) use ($hashed) {
95 return "
96 $('body').on('il-lm-show-media-slate', function(){
97 il.UI.maincontrols.mainbar.engageTool('$hashed');
98 });";
99 });
100 }
101 return $c;
102 })
103 ->withInitiallyHidden(true)
104 ->withTitle($title)
105 ->withContentWrapper(function () use ($l) {
106 return $l($this->getLinkSlateContent("media"));
107 })
108 ->withSymbol($icon)
109 ->withPosition(12);
110
111 $title = $lng->txt("cont_tool_faq");
112 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("outlined/icon_faq.svg"), $title);
113 $identification = $iff("lm_faq");
114 $hashed = $this->hash($identification->serialize());
115 $tools[] = $this->factory->tool($identification)
116 ->addComponentDecorator(static function (ILIAS\UI\Component\Component $c) use ($hashed) : ILIAS\UI\Component\Component {
117 if ($c instanceof LegacySlate) {
118 $signal_id = $c->getToggleSignal()->getId();
119 return $c->withAdditionalOnLoadCode(static function ($id) use ($hashed) {
120 return "
121 $('body').on('il-lm-show-faq-slate', function(){
122 il.UI.maincontrols.mainbar.engageTool('$hashed');
123 });";
124 });
125 }
126 return $c;
127 })
128 ->withInitiallyHidden(true)
129 ->withTitle($title)
130 ->withContentWrapper(function () use ($l) {
131 return $l($this->getLinkSlateContent("faq"));
132 })
133 ->withSymbol($icon)
134 ->withPosition(13);
135 }
136
137 return $tools;
138 }
139
146 public function getOfflineToolIds()
147 {
148 $iff = function ($id) {
149 return $this->identification_provider->contextAwareIdentifier($id);
150 };
151 return [
152 $this->hash($iff("lm_pres_toc")->serialize()),
153 $this->hash($iff("lm_glossary")->serialize()),
154 $this->hash($iff("lm_media")->serialize()),
155 $this->hash($iff("lm_faq")->serialize())
156 ];
157 }
158
159
166 public function getTocTool($additional_data) : \ILIAS\GlobalScreen\Scope\Tool\Factory\Tool
167 {
168 global $DIC;
169
170 $lng = $DIC->language();
171
172 $iff = function ($id) {
173 return $this->identification_provider->contextAwareIdentifier($id);
174 };
175 $l = function (string $content) {
176 return $this->dic->ui()->factory()->legacy($content);
177 };
178
179 $title = $lng->txt("cont_toc");
180 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("outlined/icon_chp.svg"), $title);
181 return $this->factory->tool($iff("lm_pres_toc"))
182 ->withTitle($title)
183 ->withContentWrapper(function () use ($l, $additional_data) {
184 return $l($this->getToc($additional_data));
185 })
186 ->withSymbol($icon)
187 ->withPosition(10);
188 }
189
190
198 private function getToc($additional_data) : string
199 {
200 global $DIC;
201
202 // get params via additional_data, set query params
203 $params = $additional_data->get(self::LM_QUERY_PARAMS);
204 $offline = $additional_data->is(self::LM_OFFLINE, true);
205 if (!is_array($params)) {
206 $params = $_GET;
207 }
208
209 try {
210 $service = new ilLMPresentationService($DIC->user(), $params, $offline);
211 $renderer = new ilLMSlateTocRendererGUI($service);
212
213 return $renderer->render();
214 } catch (Exception $e) {
215 return "";
216 }
217 }
218
219
225 protected function getLinkSlateContent(string $type) : string
226 {
227 return "<div style='height:100%; overflow:hidden;' id='" . $type . "_area'><iframe style='border:0; padding:0; height:100%; width:100%'></iframe></div>";
228 }
229}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class ilLMGSToolProvider.
getToolsForContextStack(CalledContexts $called_contexts)
@inheritDoc
getToc($additional_data)
toc
getTocTool($additional_data)
Get toc tool.
Main service init and factory.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
withSymbol(Symbol $symbol)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$type
$service
Definition: result.php:17
$lng
$DIC
Definition: xapitoken.php:46