ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilAuthPageEditorGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
30 {
31  final public const string DEFAULT_COMMAND = 'showPageEditorLanguages';
32  final public const string LANGUAGE_TABLE_ACTIONS_COMMAND = 'handlePageActions';
33  final public const string CONTEXT_HTTP_PARAM = 'auth_ipe_context';
34 
36  private ilLanguage $lng;
38  private ilTabsGUI $tabs;
39  private \ILIAS\HTTP\Services $http;
40  private \ILIAS\Refinery\Factory $refinery;
41  private \ILIAS\UI\Factory $ui_factory;
42  private \ILIAS\UI\Renderer $ui_renderer;
43  private \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
44  private ?string $redirect_source = null;
45  private ?int $requested_language_id = null;
47  private int $ref_id;
48  private ?string $request_ipe_context;
49 
50  public function __construct(int $a_ref_id)
51  {
52  global $DIC;
53 
54  $this->ctrl = $DIC->ctrl();
55  $this->tpl = $DIC->ui()->mainTemplate();
56  $this->tabs = $DIC->tabs();
57 
58  $this->http = $DIC->http();
59  $this->refinery = $DIC->refinery();
60  $this->ui_factory = $DIC->ui()->factory();
61  $this->ui_renderer = $DIC->ui()->renderer();
62 
63  $this->lng = $DIC['lng'];
64 
65  $this->lng->loadLanguageModule('auth');
66 
67  $this->ref_id = $a_ref_id;
68 
69  $content_style = $DIC->contentStyle();
70  $this->content_style_domain = $content_style
71  ->domain()
72  ->styleForRefId($a_ref_id);
73  $this->content_style_gui = $content_style->gui();
74 
75  $query_wrapper = $DIC->http()->wrapper()->query();
76  $post_wrapper = $DIC->http()->wrapper()->post();
77  $refinery = $DIC->refinery();
78 
79  if ($query_wrapper->has('redirectSource')) {
80  $this->redirect_source = $query_wrapper->retrieve('redirectSource', $refinery->kindlyTo()->string());
81  }
82 
83  if ($post_wrapper->has('key')) {
84  $this->requested_language_id = $post_wrapper->retrieve('key', $refinery->kindlyTo()->int());
85  } elseif ($query_wrapper->has('key')) {
86  $this->requested_language_id = $query_wrapper->retrieve('key', $refinery->kindlyTo()->int());
87  }
88 
89  $this->request_ipe_context = $query_wrapper->retrieve(
90  self::CONTEXT_HTTP_PARAM,
91  $refinery->byTrying([
92  $refinery->kindlyTo()->string(),
93  $refinery->always(null)
94  ])
95  );
96  $this->ctrl->setParameter($this, self::CONTEXT_HTTP_PARAM, $this->request_ipe_context);
97  }
98 
99  public function getUnsafeGetCommands(): array
100  {
101  return [
102  self::LANGUAGE_TABLE_ACTIONS_COMMAND
103  ];
104  }
105 
106  public function getSafePostCommands(): array
107  {
108  return [];
109  }
110 
111  public function executeCommand(): void
112  {
113  switch (strtolower($this->ctrl->getNextClass($this) ?? '')) {
114  case strtolower(ilLoginPageGUI::class):
115  case strtolower(ilLogoutPageGUI::class):
116  $this->tabs->clearTargets();
117  $this->tabs->setBackTarget(
118  $this->lng->txt('back'),
119  $this->ctrl->getLinkTarget($this, self::DEFAULT_COMMAND)
120  );
121 
122  if (strtolower($this->redirect_source ?? '') !== strtolower(ilInternalLinkGUI::class)) {
123  $this->forwardToPageObject();
124  }
125  break;
126 
127  default:
128  if (!$cmd = $this->ctrl->getCmd()) {
129  $cmd = 'showPageEditorLanguages';
130  }
131  $this->$cmd();
132  break;
133  }
134  }
135 
137  {
138  return AuthPageEditorContext::from($this->request_ipe_context);
139  }
140 
141  private function forwardToPageObject(): void
142  {
143  if (!$this->requested_language_id) {
144  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('language_does_not_exist'), true);
145  $this->ctrl->returnToParent($this);
146  }
147 
148  $this->lng->loadLanguageModule('content');
149 
150  $this->tabs->activateSubTab($this->getRequestedAuthPageEditorContext()->tabIdentifier());
151 
152  $ipe_gui_class = $this->getRequestedAuthPageEditorContext()->pageUiClass();
153  $ipe_class = $this->getRequestedAuthPageEditorContext()->pageClass();
154  $ipe_page_type = $this->getRequestedAuthPageEditorContext()->pageType();
155 
156  $this->ctrl->setParameter($this, 'key', $this->requested_language_id);
157 
158  if (!$ipe_class::_exists($ipe_page_type, $this->requested_language_id)) {
159  $new_page_object = new $ipe_class();
160  $new_page_object->setParentId($this->requested_language_id);
161  $new_page_object->setId($this->requested_language_id);
162  $new_page_object->createFromXML();
163  }
164 
165  $this->ctrl->setReturnByClass($ipe_gui_class, 'edit');
166  $page_gui = new ($ipe_gui_class)($this->requested_language_id);
167 
168  $this->tpl->addCss(ilObjStyleSheet::getContentStylePath(0));
169  $this->tpl->addCss(ilObjStyleSheet::getSyntaxStylePath());
170  $this->content_style_gui->addCss($this->tpl, $this->ref_id);
171 
172  $page_gui->setTemplateTargetVar('ADM_CONTENT');
173  $page_gui->setStyleId($this->content_style_domain->getEffectiveStyleId());
174  $page_gui->setTemplateOutput(false);
175 
176  $html = $this->ctrl->forwardCommand($page_gui);
177 
178  if ($html !== '') {
179  $this->tpl->setContent($html);
180  }
181  }
182 
183  private function handlePageActions(): void
184  {
185  $action = $this->http->wrapper()->query()->retrieve(
186  'authpage_languages_action',
187  $this->refinery->byTrying([
188  $this->refinery->kindlyTo()->string(),
189  $this->refinery->always('')
190  ])
191  );
192 
193  $keys = $this->http->wrapper()->query()->retrieve(
194  'authpage_languages_key',
195  $this->refinery->byTrying([
196  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
197  $this->refinery->always([])
198  ])
199  );
200 
201  switch ($action) {
202  case AuthPageLanguagesOverviewTable::DEACTIVATE:
203  $this->deactivate();
204  break;
205 
206  case AuthPageLanguagesOverviewTable::ACTIVATE:
207  $this->activate();
208  break;
209 
210  case AuthPageLanguagesOverviewTable::EDIT:
211  $language_id = ilLanguage::lookupId((string) current($keys));
212  if ($language_id) {
213  $this->ctrl->setParameter($this, 'key', $language_id);
214  $this->ctrl->redirectByClass(
215  $this->getRequestedAuthPageEditorContext()->pageUiClass(),
216  'edit'
217  );
218  }
219  }
220 
221  $this->ctrl->redirect($this, self::DEFAULT_COMMAND);
222  }
223 
227  private function getLangKeysToUpdate(): array
228  {
229  $keys = $this->http->wrapper()->query()->retrieve(
230  'authpage_languages_key',
231  $this->refinery->byTrying([
232  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
233  $this->refinery->always([])
234  ])
235  );
236 
237  $lang_keys = $this->lng->getInstalledLanguages();
238 
239  if ((string) current($keys) !== 'ALL_OBJECTS') {
240  $lang_keys = array_intersect($keys, $lang_keys);
241  }
242 
243  return $lang_keys;
244  }
245 
246  private function activate(): void
247  {
248  $lang_keys = $this->getLangKeysToUpdate();
251  );
252 
253  foreach ($lang_keys as $lang_key) {
254  $settings->enableIliasEditor($lang_key, true);
255  }
256 
257  $settings->update();
258 
259  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
260  $this->ctrl->redirect($this, self::DEFAULT_COMMAND);
261  }
262 
263  private function deactivate(): void
264  {
265  $lang_keys = $this->getLangKeysToUpdate();
268  );
269 
270  foreach ($lang_keys as $lang_key) {
271  $settings->enableIliasEditor($lang_key, false);
272  }
273 
274  $settings->update();
275 
276  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
277  $this->ctrl->redirect($this, self::DEFAULT_COMMAND);
278  }
279 
280  private function showPageEditorLanguages(): void
281  {
282  $this->tabs->activateSubTab($this->getRequestedAuthPageEditorContext()->tabIdentifier());
284  $this->ctrl,
285  $this->lng,
286  $this->http,
287  $this->ui_factory,
288  $this->ui_renderer,
290  );
291 
292  $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
293  }
294 }
ILIAS Style Content Object ObjectFacade $content_style_domain
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
final const string DEFAULT_COMMAND
Facade for consumer gui interface.
final const string CONTEXT_HTTP_PARAM
final const string LANGUAGE_TABLE_ACTIONS_COMMAND
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
ilGlobalTemplateInterface $tpl
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
ilAuthPageEditorGUI: ilObjAuthSettingsGUI ilAuthPageEditorGUI: ilLoginPageGUI, ilLogoutPageGUI ...
global $DIC
Definition: shib_login.php:26
static lookupId(string $a_lang_key)
Lookup obj_id of language.
getSafePostCommands()
This method must return a list of safe POST commands.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
ILIAS Refinery Factory $refinery
static getInstance(AuthPageEditorContext $context)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...