ILIAS  release_8 Revision v8.24
class.ilLTIProviderObjectSettingGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28{
29 public const ROLE_ADMIN = 'admin';
30 public const ROLE_TUTOR = 'tutor';
31 public const ROLE_MEMBER = 'member';
32
36 protected ?ilCtrl $ctrl = null;
37
41 protected ?ilLogger $logger = null;
42
46 protected ?ilLanguage $lng = null;
47
48 protected ?\ilGlobalPageTemplate $tpl = null;
49
53 protected ?int $ref_id = null;
54
59 protected array $custom_roles = [];
60
64 protected bool $use_lti_roles = true;
65
69
73 public function __construct(int $a_ref_id)
74 {
75 global $DIC;
76 $this->ref_id = $a_ref_id;
77 $this->logger = ilLoggerFactory::getLogger('ltis');
78 $this->ctrl = $DIC->ctrl();
79 $this->tpl = $DIC['tpl'];
80 $this->rbacSystem = $DIC->rbac()->system();
81 $this->rbacReview = $DIC->rbac()->review();
82 $this->rbacAdmin = $DIC->rbac()->admin();
83
84 $this->lng = $DIC->language();
85 $this->lng->loadLanguageModule('lti');
86 }
87
92 public function hasSettingsAccess(): bool
93 {
94 if (!ilObjLTIAdministration::isEnabledForType(ilObject::_lookupType($this->ref_id, true))) {
95 $this->logger->debug('No LTI consumers activated for object type: ' . ilObject::_lookupType($this->ref_id, true));
96 return false;
97 }
98 return $this->rbacSystem->checkAccess(
99 'release_objects',
101 );
102 }
103
108 public function setCustomRolesForSelection(array $a_roles): void
109 {
110 if (empty($a_roles)) {
111 $this->checkLocalRole();
112 $a_roles = $this->rbacReview->getLocalRoles($this->ref_id);
113 }
114 $this->custom_roles = $a_roles;
115 }
116
120 public function offerLTIRolesForSelection(bool $a_stat): void
121 {
122 $this->use_lti_roles = $a_stat;
123 }
124
125
129 public function executeCommand(): void
130 {
131 $cmd = $this->ctrl->getCmd('settings');
132 $next_class = $this->ctrl->getNextClass($this);
133
134 // switch ($next_class) {
135 // default:
136 $this->$cmd();
137 // break;
138 // }
139 }
140
145 protected function settings(ilPropertyFormGUI $form = null): void
146 {
147 if (!$form instanceof ilPropertyFormGUI) {
148 $form = $this->initObjectSettingsForm();
149 }
150 $this->tpl->setContent($form->getHTML());
151 }
152
153
158 {
159 $form = new ilPropertyFormGUI();
160 $form->setFormAction($this->ctrl->getFormAction($this));
161 $form->setTitle($this->lng->txt('lti_object_release_settings_form'));
162
163 foreach (ilObjLTIAdministration::getEnabledConsumersForType(ilObject::_lookupType($this->ref_id, true)) as $global_consumer) {
164 $object_info = new ilLTIProviderObjectSetting($this->ref_id, $global_consumer->getExtConsumerId());
165
166 $this->logger->debug((string) $object_info->getAdminRole());
167
168
169 // meta data for external consumers
170 $section = new ilFormSectionHeaderGUI();
171 $section->setTitle($global_consumer->getTitle());
172 $section->setInfo($global_consumer->getDescription());
173 $form->addItem($section);
174
175 $connector = new ilLTIDataConnector();
176
178 $global_consumer->getExtConsumerId(),
179 $this->ref_id,
180 $connector
181 );
182 $active = new ilCheckboxInputGUI($this->lng->txt('lti_obj_active'), 'lti_active_' . $global_consumer->getExtConsumerId());
183 $active->setInfo($this->lng->txt('lti_obj_active_info'));
184 $active->setValue("1");//check
185 if ($active_consumer->getEnabled()) { // and enabled
186 $active->setChecked(true);
187 }
188 if ($this->custom_roles) {
189 $admin = new ilSelectInputGUI(
190 $this->lng->txt('lti_admin'),
191 'lti_admin_' . $global_consumer->getExtConsumerId()
192 );
193 $admin->setOptions($this->getRoleSelection());
194 $admin->setValue($object_info->getAdminRole() ? $object_info->getAdminRole() : 0);
195 $active->addSubItem($admin);
196
197 $tutor = new ilSelectInputGUI(
198 $this->lng->txt('lti_tutor'),
199 'lti_tutor_' . $global_consumer->getExtConsumerId()
200 );
201 $tutor->setOptions($this->getRoleSelection());
202 $tutor->setValue($object_info->getTutorRole() ? $object_info->getTutorRole() : 0);
203 $active->addSubItem($tutor);
204
205 $member = new ilSelectInputGUI(
206 $this->lng->txt('lti_member'),
207 'lti_member_' . $global_consumer->getExtConsumerId()
208 );
209 $member->setOptions($this->getRoleSelection());
210 $member->setValue($object_info->getMemberRole() ? $object_info->getMemberRole() : 0);
211 $active->addSubItem($member);
212 }
213 $form->addItem($active);
214
215 $version = new ilRadioGroupInputGUI($this->lng->txt('lti_obj_version'), 'version_' . $global_consumer->getExtConsumerId());
216 $version->setRequired(true);
217 if (!is_null($active_consumer->ltiVersion)) {
218 $version->setValue($active_consumer->ltiVersion);
219 }
220 // $version->setInfo($this->lng->txt('lti_obj_version_info'));
221 $op1 = new ilRadioOption($this->lng->txt("lti_obj_version_13"), ILIAS\LTI\ToolProvider\Util::LTI_VERSION1P3);
222 $sh = new ilNonEditableValueGUI($this->lng->txt('lti_13_step1'), '');
223 $sh->setValue($this->lng->txt("lti_13_step1_info"));
224 $op1->addSubItem($sh);
225 $url = new ilNonEditableValueGUI($this->lng->txt('lti_launch_url'), 'url');
226 $url->setValue(ILIAS_HTTP_PATH . '/lti.php?client_id=' . CLIENT_ID);
227 $op1->addSubItem($url);
228 $url = new ilNonEditableValueGUI($this->lng->txt('lti_con_key_type_jwk'), 'jwt');
229 $url->setValue(ILIAS_HTTP_PATH . '/Modules/LTIConsumer/lticerts.php');
230 // $url->setInfo($this->lng->txt("lti_con_key_type_jwk_info"));
231 $op1->addSubItem($url);
232
233 // $url = new ilNonEditableValueGUI($this->lng->txt('lti_13_initiate_url'), 'url');
234 // $url->setValue(ILIAS_HTTP_PATH . '/lti.php?client_id=' . CLIENT_ID);
235 // $version->addSubItem($url);
236 // $url = new ilNonEditableValueGUI($this->lng->txt('lti_13_redirection_url'), 'url');
237 // $url->setValue(ILIAS_HTTP_PATH . '/lti.php?client_id=' . CLIENT_ID);
238 // $active->addSubItem($url);
239 $sh = new ilNonEditableValueGUI($this->lng->txt('lti_13_step2'), '');
240 $sh->setValue($this->lng->txt("lti_13_step2_info"));
241 $op1->addSubItem($sh);
242 $tf = new ilTextInputGUI($this->lng->txt('lti_13_platform_id'), 'platform_id_' . $global_consumer->getExtConsumerId());
243 $tf->setValue($active_consumer->platformId);
244 $op1->addSubItem($tf);
245 $tf = new ilTextInputGUI($this->lng->txt('lti_13_client_id'), 'client_id_' . $global_consumer->getExtConsumerId());
246 $tf->setValue($active_consumer->clientId);
247 $op1->addSubItem($tf);
248 $tf = new ilTextInputGUI($this->lng->txt('lti_13_deployment_id'), 'deployment_id_' . $global_consumer->getExtConsumerId());
249 $tf->setValue($active_consumer->deploymentId);
250 $op1->addSubItem($tf);
251 $tf = new ilTextInputGUI($this->lng->txt('lti_13_keyset_url'), 'keyset_url_' . $global_consumer->getExtConsumerId());
252 $tf->setValue($active_consumer->jku);
253 $op1->addSubItem($tf);
254 $tf = new ilTextInputGUI($this->lng->txt('lti_13_token_url'), 'token_url_' . $global_consumer->getExtConsumerId());
255 $tf->setValue($active_consumer->accessTokenUrl);
256 $op1->addSubItem($tf);
257 $tf = new ilTextInputGUI($this->lng->txt('lti_13_authentication_url'), 'authentication_url_' . $global_consumer->getExtConsumerId());
258 $tf->setValue($active_consumer->authenticationUrl);
259 $op1->addSubItem($tf);
260 $version->addOption($op1);
261
262 $op0 = new ilRadioOption($this->lng->txt("lti_obj_version_11"), ILIAS\LTI\ToolProvider\Util::LTI_VERSION1);
263 $url = new ilNonEditableValueGUI($this->lng->txt('lti_launch_url'), 'url');
264 $url->setValue(ILIAS_HTTP_PATH . '/lti.php?client_id=' . CLIENT_ID);
265 $op0->addSubItem($url);
266 $key = new ilNonEditableValueGUI($this->lng->txt('lti_consumer_key'), 'key_' . $global_consumer->getExtConsumerId());
267 if (is_null($active_consumer->getKey())) {
268 $active_consumer->setKey(\ILIAS\LTI\ToolProvider\Util::getRandomString(10));//create $id .
269 }
270 $key->setValue($active_consumer->getKey());
271 $op0->addSubItem($key);
272 $secret = new ilNonEditableValueGUI($this->lng->txt('lti_consumer_secret'), 'secret_' . $global_consumer->getExtConsumerId());
273 if (is_null($active_consumer->getSecret())) {
274 $active_consumer->createSecret();
275 }
276 $secret->setValue($active_consumer->getSecret());
277 $op0->addSubItem($secret);
278 $version->addOption($op0);
279
280 $active->addSubItem($version);
281 }
282
283 $form->addCommandButton('updateSettings', $this->lng->txt('save'));
284 return $form;
285 }
286
290 protected function updateSettings(): void
291 {
292 $form = $this->initObjectSettingsForm();
293 if (!$form->checkInput()) {
294 $form->setValuesByPost();
295 $this->settings($form);
296 return;
297 }
298
299 $connector = new ilLTIDataConnector();
300 foreach (ilObjLTIAdministration::getEnabledConsumersForType(ilObject::_lookupType($this->ref_id, true)) as $global_consumer) {
301 $this->saveRoleSelection($form, (string) $global_consumer->getExtConsumerId());
302
304 $global_consumer->getExtConsumerId(),
305 $this->ref_id,
306 $connector
307 );
308 if (!$form->getInput('lti_active_' . $global_consumer->getExtConsumerId())) {
309 // not active anymore
310 if ($consumer->getEnabled()) {
311 $this->logger->info('Deleting lti consumer for object reference: ' . $this->ref_id);
312 $consumer->setEnabled(false);
313 $consumer->saveLTI($connector);
314 }
315 } else {
316 $consumer->ltiVersion = $form->getInput('version_' . $global_consumer->getExtConsumerId());
317 $this->logger->info('Created new lti release for: ' . $this->ref_id);
318 $consumer->setExtConsumerId($global_consumer->getExtConsumerId());
319 $consumer->setKey((string) $form->getInput('key_' . $global_consumer->getExtConsumerId()));
320 $consumer->setSecret((string) $form->getInput('secret_' . $global_consumer->getExtConsumerId()));
321 $consumer->setRefId($this->ref_id);
322 $consumer->setEnabled(true);
323 if ($form->getInput('platform_id_' . $global_consumer->getExtConsumerId())) {
324 $consumer->platformId = (string) $form->getInput('platform_id_' . $global_consumer->getExtConsumerId());
325 } else {
326 $consumer->platformId = null;
327 }
328 if ($form->getInput('client_id_' . $global_consumer->getExtConsumerId())) {
329 $consumer->clientId = $form->getInput('client_id_' . $global_consumer->getExtConsumerId());
330 } else {
331 $consumer->clientId = null;
332 }
333 if ($form->getInput('deployment_id_' . $global_consumer->getExtConsumerId())) {
334 $consumer->deploymentId = $form->getInput('deployment_id_' . $global_consumer->getExtConsumerId());
335 } else {
336 $consumer->deploymentId = null;
337 }
338 if ($form->getInput('keyset_url_' . $global_consumer->getExtConsumerId())) {
339 $consumer->jku = $form->getInput('keyset_url_' . $global_consumer->getExtConsumerId());
340 } else {
341 $consumer->jku = '';
342 }
343 if ($form->getInput('token_url_' . $global_consumer->getExtConsumerId())) {
344 $consumer->accessTokenUrl = $form->getInput('token_url_' . $global_consumer->getExtConsumerId());
345 } else {
346 $consumer->accessTokenUrl = '';
347 }
348 if ($form->getInput('authentication_url_' . $global_consumer->getExtConsumerId())) {
349 $consumer->authenticationUrl = $form->getInput('authentication_url_' . $global_consumer->getExtConsumerId());
350 } else {
351 $consumer->authenticationUrl = '';
352 }
353 $consumer->saveLTI($connector);
354 }
355 }
356
357 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
358 $this->ctrl->redirect($this, 'settings');
359 }
360
366 protected function saveRoleSelection(ilPropertyFormGUI $form, string $global_consumer_id): void
367 {
368 $object_info = new ilLTIProviderObjectSetting($this->ref_id, (int) $global_consumer_id);
369
370 $admin_role = (int) $form->getInput('lti_admin_' . $global_consumer_id);
371 if ($admin_role > 0) {
372 $object_info->setAdminRole($admin_role);
373 }
374 $tutor_role = (int) $form->getInput('lti_tutor_' . $global_consumer_id);
375 if ($tutor_role > 0) {
376 $object_info->setTutorRole($tutor_role);
377 }
378 $member_role = (int) $form->getInput('lti_member_' . $global_consumer_id);
379 if ($member_role > 0) {
380 $object_info->setMemberRole($member_role);
381 }
382 $object_info->save();
383 }
384
389 protected function getRoleSelection(): array
390 {
391 $options = [];
392 $options[0] = $this->lng->txt('select_one');
393 foreach ($this->custom_roles as $role_id) {
395 $options[$role_id] = $title;
396 }
397 return $options;
398 }
399
403 protected function checkLocalRole(): void
404 {
405 $a_global_role = ilObject::_getIdsForTitle("il_lti_global_role", "role", false);
406 if (is_array($a_global_role) && !empty($a_global_role)) {
407 if (count($this->rbacReview->getRolesOfObject($this->ref_id, false)) == 0) {
408 $rbacadmin = $this->rbacAdmin;
409 $type = ilObject::_lookupType($this->ref_id, true);
410 $role = new ilObjRole();
411 $role->setTitle("il_lti_learner");
412 $role->setDescription("LTI Learner of " . $type . " obj_no." . ilObject::_lookupObjectId($this->ref_id));
413 $role->create();
414 $rbacadmin->assignRoleToFolder($role->getId(), $this->ref_id, 'y');
415 $rbacadmin->grantPermission($role->getId(), ilRbacReview::_getOperationIdsByName(array('visible','read')), $this->ref_id);
416 // $rbacadmin->setRolePermission($role->getId(), ilObject::_lookupType($this->ref_id, true), [2,3], $this->ref_id);
417 if ($type == "sahs" || $type == "lm" || $type == "svy" || $type == "tst") {
418 $role = new ilObjRole();
419 $role->setTitle("il_lti_instructor");
420 $role->setDescription("LTI Instructor of " . $type . " obj_no." . ilObject::_lookupObjectId($this->ref_id));
421 $role->create();
422 $rbacadmin->assignRoleToFolder($role->getId(), $this->ref_id, 'y');
423 $ops = ilRbacReview::_getOperationIdsByName(array('visible','read','read_learning_progress'));
424 if ($type == "svy") {
425 $ops[] = ilRbacReview::_getOperationIdsByName(array('read_results'))[0];
426 }
427 if ($type == "tst") {
428 $ops[] = ilRbacReview::_getOperationIdsByName(array('tst_results'))[0];
429 $ops[] = ilRbacReview::_getOperationIdsByName(array('tst_statistics'))[0];
430 }
431 $rbacadmin->grantPermission($role->getId(), $ops, $this->ref_id);
432 }
433 }
434 }
435 }
436}
$version
Definition: plugin.php:24
This class represents a checkbox property in a property form.
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static fromGlobalSettingsAndRefId(int $a_ext_consumer_id, int $a_ref_id, ilLTIDataConnector $a_data_connector)
Load consumer from global settings and ref_id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
offerLTIRolesForSelection(bool $a_stat)
Offer LTI roles for mapping.
updateSettings()
Update settings (activate deactivate lti access)
saveRoleSelection(ilPropertyFormGUI $form, string $global_consumer_id)
Save role selection for consumer.
hasSettingsAccess()
Check if user has access to lti settings.
settings(ilPropertyFormGUI $form=null)
Show settings.
setCustomRolesForSelection(array $a_roles)
Set custom roles for mapping to LTI roles.
checkLocalRole()
check for local roles for lti objects which are not grp or crs
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupLTISettingsRefId()
Lookup ref_id.
Class ilObjRole.
static _getTranslation(string $a_role_title)
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _getIdsForTitle(string $title, string $type='', bool $partial_match=false)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
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...
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
static _getOperationIdsByName(array $operations)
get ops_id's by name.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This class represents a selection list property in a property form.
This class represents a text property in a property form.
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193
string $secret
Shared secret.
Definition: System.php:43
Class ChatMainBarProvider \MainMenu\Provider.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
$url