ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilMathJaxSettingsGUI Class Reference

GUI for MathJax Settings This GUI maintains the MathJax config stored in the ILIAS settings Since ILIAS 8 these settings can also be written by the ILIAS setup ilMathJaxSettingsGUI: More...

+ Collaboration diagram for ilMathJaxSettingsGUI:

Public Member Functions

 __construct (bool $writable)
 Constructor. More...
 
 executeCommand ()
 Execute a command This should be overridden in the child classes note: permissions are already checked in the object gui. More...
 

Protected Member Functions

 editSettings ()
 Edit the MathJax settings. More...
 
 clearCache ()
 Clear the directory with cached LaTeX graphics. More...
 
 renderLink (string $langvar, string $url, bool $new_tab=true)
 Render an html link. More...
 

Protected Attributes

ILIAS DI Container $dic
 
ilCtrl $ctrl
 
ilTabsGUI $tabs
 
ilLanguage $lng
 
ilGlobalTemplateInterface $tpl
 
ilToolbarGUI $toolbar
 
Psr Http Message ServerRequestInterface $request
 
ILIAS Refinery Factory $refinery
 
ilMathJaxConfigRespository $repository
 
bool $writable = false
 

Detailed Description

GUI for MathJax Settings This GUI maintains the MathJax config stored in the ILIAS settings Since ILIAS 8 these settings can also be written by the ILIAS setup ilMathJaxSettingsGUI:

Definition at line 27 of file class.ilMathJaxSettingsGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilMathJaxSettingsGUI::__construct ( bool  $writable)

Constructor.

Definition at line 45 of file class.ilMathJaxSettingsGUI.php.

References $DIC, $writable, ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\UI\examples\Deck\repository(), ILIAS\Repository\tabs(), and ILIAS\Repository\toolbar().

46  {
47  global $DIC;
48 
49  // ILIAS dependencies
50  $this->dic = $DIC;
51  $this->ctrl = $this->dic->ctrl();
52  $this->tabs = $this->dic->tabs();
53  $this->toolbar = $this->dic->toolbar();
54  $this->lng = $this->dic->language();
55  $this->tpl = $this->dic->ui()->mainTemplate();
56  $this->request = $this->dic->http()->request();
57  $this->refinery = $this->dic->refinery();
58 
59  $factory = new ilSettingsFactory($DIC->database());
60  $this->repository = new ilMathJaxConfigSettingsRepository($factory->settingsFor('MathJax'));
61 
62  $this->writable = $writable;
63  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:17
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Repository for storing and loading the MathJax configuration.
+ Here is the call graph for this function:

Member Function Documentation

◆ clearCache()

ilMathJaxSettingsGUI::clearCache ( )
protected

Clear the directory with cached LaTeX graphics.

Definition at line 272 of file class.ilMathJaxSettingsGUI.php.

References ILIAS\Repository\ctrl(), ilMathJax\getInstance(), and ILIAS\Repository\lng().

272  : void
273  {
274  ilMathJax::getInstance()->clearCache();
275  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mathjax_server_cache_cleared'), true);
276  $this->ctrl->redirect($this);
277  }
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
+ Here is the call graph for this function:

◆ editSettings()

ilMathJaxSettingsGUI::editSettings ( )
protected

Edit the MathJax settings.

Definition at line 89 of file class.ilMathJaxSettingsGUI.php.

References $data, ILIAS\Repository\ctrl(), ilMathJax\getIndependent(), ilMathJax\getInstance(), init(), ILIAS\Repository\lng(), ilMathJax\PURPOSE_BROWSER, ILIAS\Repository\refinery(), renderLink(), ILIAS\UI\examples\Deck\repository(), ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation(), and ILIAS\UI\Implementation\Component\Input\withValue().

89  : void
90  {
91  $testcode = 'f(x)=\int_{-\infty}^x e^{-t^2}dt';
92 
93  $config = $this->repository->getConfig();
94  $factory = $this->dic->ui()->factory()->input()->field();
95 
96  // needed for the optional groups
97  $checkbox_transformation = $this->refinery->custom()->transformation(static function ($v) {
98  if (is_array($v) || is_bool($v)) {
99  return $v;
100  }
101  return ($v === 'checked');
102  });
103 
104  // client-side rendering settings
105  $client_enabled = $factory->optionalGroup(
106  [
107 
108  'client_polyfill_url' => $factory->url(
109  $this->lng->txt('mathjax_polyfill_url'),
110  implode('<br />', [
111  $this->lng->txt('mathjax_polyfill_url_desc_line1'),
112  $this->lng->txt('mathjax_polyfill_url_desc_line2')
113  ])
114  )
115  ->withValue($config->getClintPolyfillUrl())
116  ->withDisabled(!$this->writable),
117 
118  'client_script_url' => $factory->url(
119  $this->lng->txt('mathjax_script_url'),
120  implode('<br />', [
121  // Mantis #41564
122  sprintf($this->lng->txt('mathjax_script_url_desc_line1'), $config->getMathJax2DefaultUrl()),
123  sprintf($this->lng->txt('mathjax_script_url_desc_line2'), $config->getMathJax3DefaultUrl()),
124  ])
125  )->withRequired(true) // mantis #31645
126  ->withValue($config->getClientScriptUrl())
127  ->withDisabled(!$this->writable),
128 
129  'client_limiter' => $factory->select(
130  $this->lng->txt('mathjax_limiter'),
131  $config->getClientLimiterOptions(),
132  $this->lng->txt('mathjax_limiter_info')
133  )->withRequired(true)
134  ->withValue($config->getClientLimiter())
135  ->withDisabled(!$this->writable),
136 
137  'client_test' => $factory->text(
138  $this->lng->txt('mathjax_test_expression'),
139  $this->lng->txt('mathjax_test_expression_info_client')
141  $config->withClientEnabled(true)
142  ->withServerEnabled(false),
143  new ilMathJaxFactory()
144  )
146  ->insertLatexImages('<p>[tex]' . $testcode . '[/tex]</p>')
147  )->withDisabled(true)->withValue($testcode)
148 
149  ],
150  $this->lng->txt('mathjax_enable_client'),
151  $this->lng->txt('mathjax_enable_client_info') . ' ' .
152  $this->renderLink('mathjax_home_link', 'https://www.mathjax.org')
153  )->withAdditionalTransformation($checkbox_transformation)
154  ->withDisabled(!$this->writable);
155 
156  // server-side rendering settings
157  $server_enabled = $factory->optionalGroup(
158  [
159  'server_address' => $factory->url(
160  $this->lng->txt('mathjax_server_address'),
161  $this->lng->txt('mathjax_server_address_info')
162  )->withRequired(true)
163  ->withValue($config->getServerAddress())
164  ->withDisabled(!$this->writable),
165 
166  'server_timeout' => $factory->numeric(
167  $this->lng->txt('mathjax_server_timeout'),
168  $this->lng->txt('mathjax_server_timeout_info')
169  )//->withRequired(true) // mantis #31645
170  ->withValue($config->getServerTimeout())
171  ->withDisabled(!$this->writable),
172 
173  'server_for_browser' => $factory->checkbox(
174  $this->lng->txt('mathjax_server_for_browser'),
175  $this->lng->txt('mathjax_server_for_browser_info')
176  )->withValue($config->isServerForBrowser())
177  ->withDisabled(!$this->writable),
178 
179  'server_for_export' => $factory->checkbox(
180  $this->lng->txt('mathjax_server_for_export'),
181  $this->lng->txt('mathjax_server_for_export_info')
182  )->withValue($config->isServerForExport())
183  ->withDisabled(!$this->writable),
184 
185  'server_for_pdf' => $factory->checkbox(
186  $this->lng->txt('mathjax_server_for_pdf'),
187  $this->lng->txt('mathjax_server_for_pdf_info')
188  )->withValue($config->isServerForPdf())
189  ->withDisabled(!$this->writable),
190 
191  'cache_size' => $factory->text(
192  $this->lng->txt('mathjax_server_cache_size'),
193  $this->lng->txt('mathjax_server_cache_size_info') . ' ' .
194  $this->renderLink('mathjax_server_clear_cache', $this->ctrl->getLinkTarget($this, 'clearCache'), false)
195  )->withDisabled(true)->withValue(ilMathJax::getInstance()->getCacheSize())
196  ->withDisabled(!$this->writable),
197 
198  'server_test' => $factory->text(
199  $this->lng->txt('mathjax_test_expression'),
200  $this->lng->txt('mathjax_test_expression_info_server')
202  $config->withClientEnabled(false)
203  ->withServerEnabled(true)
204  ->withServerForBrowser(true),
205  new ilMathJaxFactory()
206  )
208  ->insertLatexImages('<p>[tex]' . $testcode . '[/tex]</p>')
209  )->withDisabled(true)->withValue($testcode)
210  ],
211  $this->lng->txt('mathjax_enable_server'),
212  $this->lng->txt('mathjax_enable_server_info') . ' ' .
213  $this->renderLink('mathjax_server_installation', './components/ILIAS/MathJax/docs/install-server.md')
214  )->withAdditionalTransformation($checkbox_transformation)
215  ->withDisabled(!$this->writable);
216 
217 
218  // build the settings form
219  // uncheck optional groups, if not enabled, see https://mantis.ilias.de/view.php?id=26476
220  $form = $this->dic->ui()->factory()->input()->container()->form()->standard($this->ctrl->getFormAction($this), [
221  'mathjax' => $factory->section([], $this->lng->txt('mathjax_settings')),
222  'client_enabled' => $config->isClientEnabled() ? $client_enabled : $client_enabled->withValue(null),
223  'server_enabled' => $config->isServerEnabled() ? $server_enabled : $server_enabled->withValue(null)
224  ]);
225 
226  if (!$this->writable) {
227  $form = $form->withSubmitLabel($this->lng->txt('refresh'));
228  }
229 
230  // apply posted inputs if form is saved and
231  if ($this->writable && $this->request->getMethod() === "POST") {
232  $form = $form->withRequest($this->request);
233  $data = $form->getData();
234  }
235 
236  // posted inputs exist and are ok => save data
237  if (isset($data)) {
238  if (is_array($data['client_enabled'])) {
239  $client_data = $data['client_enabled'];
240  $config = $config->withClientEnabled(true)
241  ->withClientPolyfillUrl((string) $client_data['client_polyfill_url'])
242  ->withClientScriptUrl((string) $client_data['client_script_url'])
243  ->withClientLimiter((int) $client_data['client_limiter']);
244  } else {
245  $config = $config->withClientEnabled(false);
246  }
247 
248  if (is_array($data['server_enabled'])) {
249  $server_data = $data['server_enabled'];
250  $config = $config->withServerEnabled(true)
251  ->withServerAddress((string) $server_data['server_address'])
252  ->withServerTimeout((int) $server_data['server_timeout'])
253  ->withServerForBrowser((bool) $server_data['server_for_browser'])
254  ->withServerForExport((bool) $server_data['server_for_export'])
255  ->withServerForPdf((bool) $server_data['server_for_pdf']);
256  } else {
257  $config = $config->withServerEnabled(false);
258  }
259  $this->repository->updateConfig($config);
260 
261  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
262  $this->ctrl->redirect($this);
263  }
264 
265  // form is not posted or has valisation errors
266  $this->tpl->setContent($this->dic->ui()->renderer()->render($form));
267  }
renderLink(string $langvar, string $url, bool $new_tab=true)
Render an html link.
Factory for objects used by ilMathJax.
repository()
description: > Example for rendering a repository card
Definition: repository.php:17
const PURPOSE_BROWSER
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
static getIndependent(ilMathJaxConfig $config, ilMathJaxFactory $factory)
Get an independent instance with a specific config for use in unit tests or on the mathjax settings p...
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
+ Here is the call graph for this function:

◆ executeCommand()

ilMathJaxSettingsGUI::executeCommand ( )

Execute a command This should be overridden in the child classes note: permissions are already checked in the object gui.

Definition at line 70 of file class.ilMathJaxSettingsGUI.php.

References ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

70  : void
71  {
72  $this->lng->loadLanguageModule('mathjax');
73 
74  $cmd = $this->ctrl->getCmd('editSettings');
75  switch ($cmd) {
76  case 'editSettings':
77  case 'clearCache':
78  $this->$cmd();
79  break;
80 
81  default:
82  $this->tpl->setContent('unknown command: ' . $cmd);
83  }
84  }
+ Here is the call graph for this function:

◆ renderLink()

ilMathJaxSettingsGUI::renderLink ( string  $langvar,
string  $url,
bool  $new_tab = true 
)
protected

Render an html link.

Definition at line 282 of file class.ilMathJaxSettingsGUI.php.

References $url, ILIAS\Repository\lng(), and ILIAS\GlobalScreen\Scope\Footer\Factory\withOpenInNewViewport().

Referenced by editSettings().

282  : string
283  {
284  $link = $this->dic->ui()->factory()->link()->standard(
285  $this->lng->txt($langvar),
286  $url
287  )->withOpenInNewViewport($new_tab);
288  return $this->dic->ui()->renderer()->render($link);
289  }
$url
Definition: shib_logout.php:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

ilCtrl ilMathJaxSettingsGUI::$ctrl
protected

Definition at line 30 of file class.ilMathJaxSettingsGUI.php.

◆ $dic

ILIAS DI Container ilMathJaxSettingsGUI::$dic
protected

Definition at line 29 of file class.ilMathJaxSettingsGUI.php.

◆ $lng

ilLanguage ilMathJaxSettingsGUI::$lng
protected

Definition at line 32 of file class.ilMathJaxSettingsGUI.php.

◆ $refinery

ILIAS Refinery Factory ilMathJaxSettingsGUI::$refinery
protected

Definition at line 36 of file class.ilMathJaxSettingsGUI.php.

◆ $repository

ilMathJaxConfigRespository ilMathJaxSettingsGUI::$repository
protected

Definition at line 38 of file class.ilMathJaxSettingsGUI.php.

◆ $request

Psr Http Message ServerRequestInterface ilMathJaxSettingsGUI::$request
protected

Definition at line 35 of file class.ilMathJaxSettingsGUI.php.

◆ $tabs

ilTabsGUI ilMathJaxSettingsGUI::$tabs
protected

Definition at line 31 of file class.ilMathJaxSettingsGUI.php.

◆ $toolbar

ilToolbarGUI ilMathJaxSettingsGUI::$toolbar
protected

Definition at line 34 of file class.ilMathJaxSettingsGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilMathJaxSettingsGUI::$tpl
protected

Definition at line 33 of file class.ilMathJaxSettingsGUI.php.

◆ $writable

bool ilMathJaxSettingsGUI::$writable = false
protected

Definition at line 40 of file class.ilMathJaxSettingsGUI.php.

Referenced by __construct().


The documentation for this class was generated from the following file: