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