-
Notifications
You must be signed in to change notification settings - Fork 38
Tool Settings service
LTI 2.0 introduced a Tool Settings service. Settings can be instantiated at three different levels in the platform:
- system
- context
- resource link
Each of these entities has a getToolSettings
and a setToolSettings
method. For example, at the resource link level, they can be used as follows:
use ceLTIc\LTI\Service\Service;
$settings = $resourceLink->getToolSettings();
Let us assume that the current settings are in place:
Level | Name | Value |
---|---|---|
System | level | consumer |
System | consumer | top |
Context | level | context |
Context | context | middle |
Resource link | level | link |
Resource link | link | bottom |
In this case, the above method call would have returned the following array:
array (
'level' => 'link',
'link' => 'bottom',
)
That is, a simple array containing all the settings for the resource link. This is equivalent to:
$settings = $resourceLink->getToolSettings(null, true);
If the simple
parameter is set to false
then the level will be included in the result array. That is,
$settings = $resourceLink->getToolSettings(null, false);
would generate a result array of:
array (
'link' =>
array (
'level' => 'link',
'link' => 'bottom',
),
)
Settings for all the higher levels could have been included as follows:
$settings = $resourceLink->getToolSettings(LTI\Enum\ToolSettingsMode::All, false);
which would have returned:
array (
'link' =>
array (
'level' => 'link',
'link' => 'bottom',
),
'context' =>
array (
'level' => 'context',
'context' => 'middle',
),
'system' =>
array (
'level' => 'consumer',
'consumer' => 'top',
),
)
Note that passing a value of true
for the simple parameter would have resulted in the method returning a value of false
as the array cannot contain settings from different levels with the same name. However, it is possible to request only settings with distinct names (for those with the same name, the setting at the lowest level will be included):
$settings = $resourceLink->getToolSettings(LTI\Enum\ToolSettingsMode::Distinct);
This would return:
array (
'level' => 'link',
'link' => 'bottom',
'context' => 'middle',
'consumer' => 'top',
)
and
$settings = $resourceLink->getToolSettings(LTI\Enum\ToolSettingsMode::Distinct, false);
would return:
array (
'link' =>
array (
'level' => 'link',
'link' => 'bottom',
),
'context' =>
array (
'context' => 'middle',
),
'system' =>
array (
'consumer' => 'top',
),
)
The setToolSettings
method takes a simple array of the setting names and values for the level at which the method is being called.
The doSettingService($action, $value = null)
method is used to retrieve, save and delete data in the platform resource link.
$setting = $resourceLink->doSettingService(LTI\Enum\ServiceAction::Read);
Note that the setting value may also be obtained from the settings of the ResourceLink
(use getSetting('ext_ims_lti_tool_setting')
). This value is automatically updated whenever a new setting is saved.
$setting = 'Please remember this ...';
$ok = $resourceLink->doSettingService(LTI\Enum\ServiceAction::Write, $setting);
...
$ok = $resourceLink->doSettingService(LTI\Enum\ServiceAction::Delete);
© 2022 Stephen P Vickers. All Rights Reserved.