ILIAS  release_8 Revision v8.24
class.ilECSParticipantSettingsGUI.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
20use ILIAS\UI\Factory as UiFactory;
21
26{
27 private int $server_id ;
28 private int $mid;
29
31
33 protected ilLanguage $lng;
34 protected ilCtrl $ctrl;
35 protected ilTabsGUI $tabs;
36 protected UiFactory $ui_factory;
39
40 public function __construct(int $a_server_id, int $a_mid)
41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $this->tpl = $DIC->ui()->mainTemplate();
46 $this->ctrl = $DIC->ctrl();
47 $this->tabs = $DIC->tabs();
48 $this->ui_factory = $DIC->ui()->factory();
49 $this->toolbar = $DIC->toolbar();
50 $this->settings = $DIC->settings();
51
52 $this->server_id = $a_server_id;
53 $this->mid = $a_mid;
54
55 $this->lng->loadLanguageModule('ecs');
56
57 $this->participant = new ilECSParticipantSetting($this->getServerId(), $this->getMid());
58 }
59
60 public function getServerId(): int
61 {
62 return $this->server_id;
63 }
64
65 public function getMid(): int
66 {
67 return $this->mid;
68 }
69
71 {
72 return $this->participant;
73 }
74
75
79 public function executeCommand(): bool
80 {
81 $this->ctrl->saveParameter($this, 'server_id');
82 $this->ctrl->saveParameter($this, 'mid');
83
84 $next_class = $this->ctrl->getNextClass($this);
85 $cmd = $this->ctrl->getCmd('settings');
86
87 $this->setTabs();
88 $this->$cmd();
89
90 return true;
91 }
92
96 private function abort(): void
97 {
98 $this->ctrl->returnToParent($this);
99 }
100
101
105 private function settings(ilPropertyFormGUI $form = null): void
106 {
107 $this->renderConsentToolbar();
108
109 if (!$form instanceof ilPropertyFormGUI) {
110 $form = $this->initFormSettings();
111 }
112 $this->tpl->setContent($form->getHTML());
113 }
114
115 protected function renderConsentToolbar(): void
116 {
117 $consents = new ilECSParticipantConsents(
118 $this->getServerId(),
119 $this->getMid()
120 );
121 if (!$consents->hasConsents()) {
122 return;
123 }
124
125 $confirm = $this->ui_factory->modal()->interruptive(
126 $this->lng->txt('ecs_consent_reset_confirm_title'),
127 $this->lng->txt('ecs_consent_reset_confirm_title_info'),
128 $this->ctrl->getLinkTarget($this, 'resetConsents')
129 );
130 $this->toolbar->addComponent($confirm);
131
132 $confirmation_trigger = $this->ui_factory->button()->standard(
133 $this->lng->txt('ecs_consent_reset_confirm_title'),
134 ''
135 )->withOnClick($confirm->getShowSignal());
136 $this->toolbar->addComponent($confirmation_trigger);
137 }
138
139 protected function resetConsents()
140 {
141 $consents = new ilECSParticipantConsents($this->getServerId(), $this->getMid());
142 $consents->delete();
143 $this->tpl->setOnScreenMessage('success', $this->lng->txt('ecs_user_consents_deleted'), true);
144 $this->ctrl->redirect($this, 'settings');
145 }
146
150 protected function saveSettings(): void
151 {
152 $form = $this->initFormSettings();
153 if ($form->checkInput()) {
154 $this->getParticipant()->enableToken((bool) $form->getInput('token'));
155 $this->getParticipant()->enableExport((bool) $form->getInput('export'));
156 $this->getParticipant()->setExportTypes($form->getInput('export_types'));
157 $this->getParticipant()->enableImport((bool) $form->getInput('import'));
158 $this->getParticipant()->setImportTypes($form->getInput('import_types'));
159 $this->getParticipant()->enableIncomingLocalAccounts((bool) $form->getInput('incoming_local_accounts'));
160 $this->getParticipant()->setIncomingAuthType((int) $form->getInput('incoming_auth_type'));
161 $this->getParticipant()->setOutgoingAuthModes((array) $form->getInput('outgoing_auth_modes'));
162
163 // placeholders
164 $placeholders = [];
165 foreach ($this->parseAvailableAuthModes() as $authmode_name => $authmode_text) {
166 $placeholders[$authmode_name] = $form->getInput(
167 'username_placeholder_' . $authmode_name
168 );
169 }
170 $this->getParticipant()->setOutgoingUsernamePlaceholders($placeholders);
171
172 // additional validation
173 $error_code = $this->getParticipant()->validate();
174 switch ($error_code) {
176 $form->getItemByPostVar('outgoing_auth_modes')->setAlert(
177 $this->lng->txt('ecs_username_place_holder_err_mssing_placeholder')
178 );
179 break;
180 default:
181 $this->getParticipant()->update();
182 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
183 $this->ctrl->redirect($this, 'settings');
184
185 }
186 }
187 $form->setValuesByPost();
188 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
189 $this->settings($form);
190 }
191
196 {
197 $form = new ilPropertyFormGUI();
198 $form->setFormAction($this->ctrl->getFormAction($this));
199 $form->setTitle($this->lng->txt('ecs_part_settings') . ' ' . $this->getParticipant()->getTitle());
200
201
202 $token = new ilCheckboxInputGUI($this->lng->txt('ecs_token_mechanism'), 'token');
203 $token->setInfo($this->lng->txt('ecs_token_mechanism_info'));
204 $token->setValue("1");
205 $token->setChecked($this->getParticipant()->isTokenEnabled());
206 $form->addItem($token);
207
208 // Export
209 $export = new ilCheckboxInputGUI($this->lng->txt('ecs_tbl_export'), 'export');
210 $export->setValue("1");
211 $export->setChecked($this->getParticipant()->isExportEnabled());
212 $form->addItem($export);
213
214 $auth_types = new ilCheckboxInputGUI(
215 $this->lng->txt('ecs_export_local_account'),
216 'incoming_local_accounts'
217 );
218 $auth_types->setInfo($this->lng->txt('ecs_export_local_account_info'));
219 $auth_types->setChecked($this->getParticipant()->areIncomingLocalAccountsSupported());
220 $export->addSubItem($auth_types);
221
222 // radio group with login page and (optional) shibboleth option
223 $external_auth_type = new ilRadioGroupInputGUI(
224 $this->lng->txt('ecs_export_auth_type'),
225 'incoming_auth_type'
226 );
227 $external_auth_type->setInfo($this->lng->txt('ecs_export_auth_type_info'));
228 $external_auth_type->setValue(
229 (string) $this->getParticipant()->getIncomingAuthType()
230 );
231 $external_auth_type->addOption(
232 new ilRadioOption(
233 $this->lng->txt('ecs_export_auth_type_ilias'),
235 )
236 );
237 if ($this->isShibbolethActive()) {
238 $external_auth_type->addOption(
239 new ilRadioOption(
240 $this->lng->txt('ecs_export_auth_type_shib'),
242 )
243 );
244 }
245 $external_auth_type->addOption(
246 new ilRadioOption(
247 $this->lng->txt('ecs_export_auth_type_none'),
249 )
250 );
251 $export->addSubItem($external_auth_type);
252
253 // Export types
254 $obj_types = new ilCheckboxGroupInputGUI($this->lng->txt('ecs_export_types'), 'export_types');
255 $obj_types->setValue($this->getParticipant()->getExportTypes());
256
257
258 foreach (ilECSUtils::getPossibleReleaseTypes(true) as $type => $trans) {
259 $obj_types->addOption(new ilCheckboxOption($trans, $type));
260 }
261 $export->addSubItem($obj_types);
262
263
264 // Import
265 $import = new ilCheckboxInputGUI($this->lng->txt('ecs_tbl_import'), 'import');
266 $import->setValue("1");
267 $import->setChecked($this->getParticipant()->isImportEnabled());
268 $form->addItem($import);
269
270 // user credentials by auth mode
271 $user_credentials = new ilCheckboxGroupInputGUI(
272 $this->lng->txt('ecs_import_user_credentials_by_auth_mode'),
273 'outgoing_auth_modes'
274 );
275 $user_credentials->setInfo($this->lng->txt('ecs_import_user_credentials_by_auth_mode_info'));
276 $user_credentials->setValue($this->getParticipant()->getOutgoingAuthModes());
277 $import->addSubItem($user_credentials);
278 foreach ($this->parseAvailableAuthModes() as $option_name => $option_text) {
279 $option = new ilCheckboxOption(
280 $this->lng->txt('ecs_import_auth_mode') . ' ' . $option_text,
281 $option_name
282 );
283 $user_credentials->addOption($option);
284 $username_placeholder = new ilTextInputGUI(
285 $this->lng->txt('ecs_outgoing_user_credentials'),
286 'username_placeholder_' . $option_name
287 );
288 $username_placeholder->setRequired(false);
289 $username_placeholder->setInfo($this->lng->txt('ecs_outgoing_user_credentials_info'));
290 $username_placeholder->setValue(
291 $this->getParticipant()->getOutgoingUsernamePlaceholderByAuthMode(
292 $option_name
293 )
294 );
295 $option->addSubItem($username_placeholder);
296 }
297 $option = new ilCheckboxOption(
298 $this->lng->txt('ecs_import_auth_type_default'),
299 'default'
300 );
301 $user_credentials->addOption($option);
302
303 // Import types
304 $imp_types = new ilCheckboxGroupInputGUI($this->lng->txt('ecs_import_types'), 'import_types');
305 $imp_types->setValue($this->getParticipant()->getImportTypes());
306
307
308 foreach (ilECSUtils::getPossibleRemoteTypes(true) as $type => $trans) {
309 $imp_types->addOption(new ilCheckboxOption($trans, $type));
310 }
311 $import->addSubItem($imp_types);
312
313 $form->addCommandButton('saveSettings', $this->lng->txt('save'));
314 $form->addCommandButton('abort', $this->lng->txt('cancel'));
315 return $form;
316 }
317
318 protected function parseAvailableAuthModes($a_mode_incoming = true): array
319 {
320 $options = [];
321 if ($this->isShibbolethActive()) {
322 $options['shibboleth'] = $this->lng->txt('auth_shib');
323 }
326 $options['ldap_' . $server->getServerId()] = $server->getName();
327 }
328 return $options;
329 }
330
331 protected function isShibbolethActive(): bool
332 {
333 return (bool) $this->settings->get('shib_active', '0');
334 }
335
339 private function setTabs(): void
340 {
341 $this->tabs->clearTargets();
342 $this->tabs->setBackTarget(
343 $this->lng->txt('back'),
344 $this->ctrl->getParentReturnByClass(self::class)
345 );
346 }
347}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
settings(ilPropertyFormGUI $form=null)
Settings.
__construct(int $a_server_id, int $a_mid)
static getPossibleReleaseTypes(bool $a_with_captions=false)
Get all possible release object types.
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
static getServerIds()
Get all server ids.
language handling
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$server
global $DIC
Definition: feed.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
$token
Definition: xapitoken.php:70