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