ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLMGSToolProvider.php
Go to the documentation of this file.
1<?php
2
25
30{
31 use \ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
32
33 public const SHOW_TOC_TOOL = 'show_toc_tool';
34 public const SHOW_LINK_SLATES = 'show_link_slates';
35 public const LM_QUERY_PARAMS = 'lm_query_params';
36 public const LM_OFFLINE = 'lm_offline';
37
39 {
40 return $this->context_collection->main()->repository();
41 }
42
43 public function getToolsForContextStack(
44 CalledContexts $called_contexts
45 ): array {
46 global $DIC;
47 $lng = $DIC->language();
48 $access = $DIC->access();
49
50 $lng->loadLanguageModule("content");
51
52 $tools = [];
53 $additional_data = $called_contexts->current()->getAdditionalData();
54 $iff = function ($id) {
55 return $this->identification_provider->contextAwareIdentifier($id);
56 };
57 $l = function (string $content) {
58 return $this->dic->ui()->factory()->legacy()->content($content);
59 };
60
61 if ($additional_data->is(self::SHOW_TOC_TOOL, true)) {
62 $ref_id = $called_contexts->current()->getReferenceId()->toInt();
63
64 if (!$access->checkAccess("read", "", $ref_id)) {
65 return $tools;
66 }
67
68 $tools[] = $this->getTocTool($additional_data);
69 }
70
71 if ($additional_data->is(self::SHOW_LINK_SLATES, true)) {
72 $title = $lng->txt("obj_glo");
73 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("standard/icon_glo.svg"), $title);
74 $identification = $iff("lm_glossary");
75 $hashed = $this->hash($identification->serialize());
76 $tools[] = $this->factory->tool($identification)
77 ->addComponentDecorator(static function (ILIAS\UI\Component\Component $c) use ($hashed): ILIAS\UI\Component\Component {
78 if ($c instanceof LegacySlate) {
79 $signal_id = $c->getToggleSignal()->getId();
80 return $c->withAdditionalOnLoadCode(static function ($id) use ($hashed) {
81 return "
82 document.addEventListener('il-lm-show-glossary-slate', function(){
83 il.UI.maincontrols.mainbar.engageTool('$hashed');
84 });";
85 });
86 }
87 return $c;
88 })
89 ->withInitiallyHidden(true)
90 ->withTitle($title)
91 ->withContentWrapper(function () use ($l) {
92 return $l($this->getLinkSlateContent("glossary"));
93 })
94 ->withSymbol($icon)
95 ->withPosition(11);
96
97 $title = $lng->txt("cont_tool_media");
98 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("standard/icon_mdia.svg"), $title);
99 $identification = $iff("lm_media");
100 $hashed = $this->hash($identification->serialize());
101 $tools[] = $this->factory->tool($identification)
102 ->addComponentDecorator(static function (ILIAS\UI\Component\Component $c) use ($hashed): ILIAS\UI\Component\Component {
103 if ($c instanceof LegacySlate) {
104 $signal_id = $c->getToggleSignal()->getId();
105 return $c->withAdditionalOnLoadCode(static function ($id) use ($hashed) {
106 return "
107 document.addEventListener('il-lm-show-media-slate', function(){
108 il.UI.maincontrols.mainbar.engageTool('$hashed');
109 });";
110 });
111 }
112 return $c;
113 })
114 ->withInitiallyHidden(true)
115 ->withTitle($title)
116 ->withContentWrapper(function () use ($l) {
117 return $l($this->getLinkSlateContent("media"));
118 })
119 ->withSymbol($icon)
120 ->withPosition(12);
121
122 $title = $lng->txt("cont_tool_faq");
123 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("standard/icon_faq.svg"), $title);
124 $identification = $iff("lm_faq");
125 $hashed = $this->hash($identification->serialize());
126 $tools[] = $this->factory->tool($identification)
127 ->addComponentDecorator(static function (ILIAS\UI\Component\Component $c) use ($hashed): ILIAS\UI\Component\Component {
128 if ($c instanceof LegacySlate) {
129 $signal_id = $c->getToggleSignal()->getId();
130 return $c->withAdditionalOnLoadCode(static function ($id) use ($hashed) {
131 return "
132 document.addEventListener('il-lm-show-faq-slate', function(){
133 il.UI.maincontrols.mainbar.engageTool('$hashed');
134 });";
135 });
136 }
137 return $c;
138 })
139 ->withInitiallyHidden(true)
140 ->withTitle($title)
141 ->withContentWrapper(function () use ($l) {
142 return $l($this->getLinkSlateContent("faq"));
143 })
144 ->withSymbol($icon)
145 ->withPosition(13);
146 }
147 return $tools;
148 }
149
150 public function getOfflineToolIds(): array
151 {
152 $iff = function ($id) {
153 return $this->identification_provider->contextAwareIdentifier($id);
154 };
155 return [
156 $this->hash($iff("lm_pres_toc")->serialize()),
157 $this->hash($iff("lm_glossary")->serialize()),
158 $this->hash($iff("lm_media")->serialize()),
159 $this->hash($iff("lm_faq")->serialize())
160 ];
161 }
162
163 public function getTocTool(
164 Collection $additional_data
165 ): Tool {
166 global $DIC;
167
168 $lng = $DIC->language();
169
170 $iff = function ($id) {
171 return $this->identification_provider->contextAwareIdentifier($id);
172 };
173 $l = function (string $content) {
174 return $this->dic->ui()->factory()->legacy()->content($content);
175 };
176
177 $title = $lng->txt("cont_toc");
178 $icon = $DIC->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("standard/icon_chp.svg"), $title);
179 return $this->factory->tool($iff("lm_pres_toc"))
180 ->withTitle($title)
181 ->withContentWrapper(function () use ($l, $additional_data) {
182 return $l($this->getToc($additional_data));
183 })
184 ->withSymbol($icon)
185 ->withPosition(10);
186 }
187
188
189 private function getToc(Collection $additional_data): string
190 {
191 global $DIC;
192
193 // get params via additional_data, set query params
194 $params = null;
195 if ($additional_data->exists(self::LM_QUERY_PARAMS)) {
196 $params = $additional_data->get(self::LM_QUERY_PARAMS);
197 }
198 $offline = $additional_data->is(self::LM_OFFLINE, true);
199
200 if (!is_array($params)) {
201 $params = null;
202 }
203 //try {
204 $service = new ilLMPresentationService($DIC->user(), $params, $offline);
206
207 return $renderer->render();
208 //} catch (Exception $e) {
209 // return $e->getMessage();
210 //}
211 }
212
213 protected function getLinkSlateContent(string $type): string
214 {
215 return "<div style='height:100%; overflow:hidden;' id='" . $type . "_area'><iframe style='border:0; padding:0; height:100%; width:100%'></iframe></div>";
216 }
217}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
factory()
$renderer
getTocTool(Collection $additional_data)
getToc(Collection $additional_data)
getToolsForContextStack(CalledContexts $called_contexts)
Main service init and factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$c
Definition: deliver.php:25
$ref_id
Definition: ltiauth.php:66
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$service
Definition: ltiresult.php:36
withSymbol(Symbol $symbol)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26