ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilLTIProviderObjectSettingGUI Class Reference

The tab of an ILIAS object that releases it to the platforms allowed for its type, with the local roles the users of each platform get. More...

+ Collaboration diagram for ilLTIProviderObjectSettingGUI:

Public Member Functions

 __construct (private readonly int $ref_id)
 
 hasSettingsAccess ()
 True when the object can be released to some platform and the user may release objects. More...
 
 setCustomRolesForSelection (array $role_ids)
 An object without local roles gets LTI roles of its own, when the administration has created the global LTI role. More...
 
 offerLTIRolesForSelection (bool $offer)
 Kept for the objects that call it, the roles offered are always the ones given above. More...
 
 executeCommand ()
 

Data Fields

const string CMD_SHOW = 'settings'
 
const string CMD_SAVE = 'updateSettings'
 

Private Member Functions

 show (?Form $form=null)
 
 save ()
 
 buildForm ()
 One optional group per platform: releasing the object to it and the roles its users get. More...
 
 getPlatforms ()
 The platforms the object can be released to. More...
 
 isAdvantage (int $platform_id)
 An LTI Advantage platform is registered once for all the objects released to it, so releasing an object only sets the roles. More...
 
 createLocalRoles ()
 
 createLocalRole (string $title, string $description, string $type, array $operations)
 

Private Attributes

readonly ILIAS DI Container $dic
 
array $roles = []
 

Detailed Description

The tab of an ILIAS object that releases it to the platforms allowed for its type, with the local roles the users of each platform get.

The name and the methods are fixed: the objects that can be released (courses, groups, tests, ...) create this class, add its tab and forward to it.

Author
Saúl Díaz sdiaz.nosp@m.@sur.nosp@m.labs..nosp@m.com

Definition at line 32 of file class.ilLTIProviderObjectSettingGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilLTIProviderObjectSettingGUI::__construct ( private readonly int  $ref_id)

Definition at line 43 of file class.ilLTIProviderObjectSettingGUI.php.

44 {
45 global $DIC;
46
47 $this->dic = $DIC;
48 $this->dic->language()->loadLanguageModule('lti');
49 }
global $DIC
Definition: shib_login.php:26

References $DIC.

Member Function Documentation

◆ buildForm()

ilLTIProviderObjectSettingGUI::buildForm ( )
private

One optional group per platform: releasing the object to it and the roles its users get.

Exceptions
ilCtrlException

Definition at line 148 of file class.ilLTIProviderObjectSettingGUI.php.

148 : Form
149 {
150 $lng = $this->dic->language();
151 $factory = $this->dic->ui()->factory();
152 $field = $factory->input()->field();
153
154 $options = [];
155 foreach ($this->roles as $role_id) {
156 $options[(string) $role_id] = ilObjRole::_getTranslation(ilObjRole::_lookupTitle((int) $role_id));
157 }
158
159 $inputs = [];
160 foreach ($this->getPlatforms() as $platform_id => $title) {
161 $release = new ilLTIRelease($this->ref_id, $platform_id);
162 $role = fn(string $txt, int $value) => $field->select($lng->txt($txt), $options)
163 ->withValue(isset($options[(string) $value]) ? (string) $value : null);
164 $roles = [
165 'admin' => $role('lti_admin', $release->getAdminRole()),
166 'tutor' => $role('lti_tutor', $release->getTutorRole()),
167 'member' => $role('lti_member', $release->getMemberRole()),
168 ];
169
170 if ($this->isAdvantage($platform_id)) {
171 // the target link the platform launches the object with, see ilAuthProviderLTI
172 $group = $field->optionalGroup($roles + [
173 'launch_url' => $field->text($lng->txt('lti_launch_url'))
174 ->withValue(ilLTIEndpoint::getUrl(ilLTIEndpoint::LAUNCH, '?ref_id=' . $this->ref_id))
175 ->withDisabled(true),
176 ], $title);
177 $inputs['platform_' . $platform_id] = $release->isReleased() ? $group : $group->withValue(null);
178 continue;
179 }
180
181 $credentials = new ilLTI1p1ProviderObjectCredentials($this->ref_id, $platform_id);
182 $group = $field->optionalGroup($roles + $credentials->getInputs($lng, $factory), $title);
183 $inputs['platform_' . $platform_id] = $credentials->isEnabled() ? $group : $group->withValue(null);
184 }
185
186 return $factory->input()->container()->form()->standard(
187 $this->dic->ctrl()->getFormAction($this, self::CMD_SAVE),
188 ['platforms' => $factory->input()->field()->section($inputs, $lng->txt('lti_object_release_settings_form'))]
189 );
190 }
The LTI 1.1 consumer key and secret an object is released to a platform with: one row of lti2_consume...
static getUrl(string $script, string $suffix='')
The URL of an entry point, with the query or path that follows it.
const string LAUNCH
getPlatforms()
The platforms the object can be released to.
isAdvantage(int $platform_id)
An LTI Advantage platform is registered once for all the objects released to it, so releasing an obje...
The release of an ILIAS object to a platform: which local roles of the object the users of the platfo...
static _getTranslation(string $a_role_title)
static _lookupTitle(int $obj_id)
global $lng
Definition: privfeed.php:26

References ILIAS\UI\Implementation\Component\Input\$inputs, $lng, ILIAS\UI\Implementation\Component\Input\Field\$options, $roles, ilObjRole\_getTranslation(), ilObject\_lookupTitle(), getPlatforms(), ilLTIEndpoint\getUrl(), isAdvantage(), and ilLTIEndpoint\LAUNCH.

Referenced by save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createLocalRole()

ilLTIProviderObjectSettingGUI::createLocalRole ( string  $title,
string  $description,
string  $type,
array  $operations 
)
private
Parameters
string$title
string$description
string$type
array$operations

Definition at line 252 of file class.ilLTIProviderObjectSettingGUI.php.

252 : void
253 {
254 $role = new ilObjRole();
255 $role->setTitle($title);
256 $role->setDescription($description . ' of ' . $type . ' obj_no.' . ilObject::_lookupObjectId($this->ref_id));
257 $role->create();
258
259 $this->dic->rbac()->admin()->assignRoleToFolder($role->getId(), $this->ref_id);
260 $this->dic->rbac()->admin()->grantPermission(
261 $role->getId(),
263 $this->ref_id
264 );
265 }
Class ilObjRole.
static _lookupObjectId(int $ref_id)
static _getOperationIdsByName(array $operations)
get ops_id's by name.

References ilRbacReview\_getOperationIdsByName(), and ilObject\_lookupObjectId().

Referenced by createLocalRoles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createLocalRoles()

ilLTIProviderObjectSettingGUI::createLocalRoles ( )
private

Definition at line 224 of file class.ilLTIProviderObjectSettingGUI.php.

224 : void
225 {
226 if (ilObject::_getIdsForTitle('il_lti_global_role', 'role') === []
227 || $this->dic->rbac()->review()->getRolesOfObject($this->ref_id) !== []) {
228 return;
229 }
230
231 $type = ilObject::_lookupType($this->ref_id, true);
232 $this->createLocalRole('il_lti_learner', 'LTI Learner', $type, ['visible', 'read']);
233
234 if (in_array($type, ['sahs', 'lm', 'svy', 'tst'], true)) {
235 $operations = ['visible', 'read', 'read_learning_progress'];
236 if ($type === 'svy') {
237 $operations[] = 'read_results';
238 }
239 if ($type === 'tst') {
240 $operations[] = 'tst_results';
241 }
242 $this->createLocalRole('il_lti_instructor', 'LTI Instructor', $type, $operations);
243 }
244 }
createLocalRole(string $title, string $description, string $type, array $operations)
static _lookupType(int $id, bool $reference=false)
static _getIdsForTitle(string $title, string $type='', bool $partial_match=false)

References ilObject\_getIdsForTitle(), ilObject\_lookupType(), and createLocalRole().

Referenced by setCustomRolesForSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilLTIProviderObjectSettingGUI::executeCommand ( )
Exceptions
ilCtrlException

Definition at line 88 of file class.ilLTIProviderObjectSettingGUI.php.

88 : void
89 {
90 if (!$this->hasSettingsAccess()) {
91 $this->dic->ui()->mainTemplate()->setOnScreenMessage('failure', $this->dic->language()->txt('permission_denied'), true);
92 $this->dic->ctrl()->redirectByClass(ilRepositoryGUI::class);
93 }
94
95 match ($this->dic->ctrl()->getCmd(self::CMD_SHOW)) {
96 self::CMD_SAVE => $this->save(),
97 default => $this->show(),
98 };
99 }
hasSettingsAccess()
True when the object can be released to some platform and the user may release objects.

References hasSettingsAccess(), save(), and show().

+ Here is the call graph for this function:

◆ getPlatforms()

ilLTIProviderObjectSettingGUI::getPlatforms ( )
private

The platforms the object can be released to.

Returns
array titles by id

Definition at line 197 of file class.ilLTIProviderObjectSettingGUI.php.

197 : array
198 {
199 return ilLTIRelease::getPlatformsForType(ilObject::_lookupType($this->ref_id, true));
200 }
static getPlatformsForType(string $type)

References ilObject\_lookupType(), and ilLTIRelease\getPlatformsForType().

Referenced by buildForm(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasSettingsAccess()

ilLTIProviderObjectSettingGUI::hasSettingsAccess ( )

True when the object can be released to some platform and the user may release objects.

Definition at line 54 of file class.ilLTIProviderObjectSettingGUI.php.

54 : bool
55 {
57
58 return $admin_ref_id !== null
59 && ilLTIRelease::getPlatformsForType(ilObject::_lookupType($this->ref_id, true)) !== []
60 && $this->dic->rbac()->system()->checkAccess('release_objects', $admin_ref_id);
61 }
static lookupRefId()
The reference of the administration node, which is the only one of its type.

References ilObject\_lookupType(), ilLTIRelease\getPlatformsForType(), and ilObjLTIAdministrationAccess\lookupRefId().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAdvantage()

ilLTIProviderObjectSettingGUI::isAdvantage ( int  $platform_id)
private

An LTI Advantage platform is registered once for all the objects released to it, so releasing an object only sets the roles.

An LTI 1.1 platform gets a registration with a key and secret per object. Earlier releases let each object choose, so an object that has a registration of its own keeps its version, whatever the other objects of the platform use.

Definition at line 208 of file class.ilLTIProviderObjectSettingGUI.php.

208 : bool
209 {
210 $db = $this->dic->database();
211 $db->setLimit(1);
212 $own = $db->fetchAssoc($db->queryF(
213 'SELECT lti_version FROM lti2_consumer WHERE ext_consumer_id = %s AND ref_id = %s ORDER BY consumer_pk DESC',
214 ['integer', 'integer'],
215 [$platform_id, $this->ref_id]
216 ));
217 $version = $own !== null
218 ? (string) $own['lti_version']
219 : ilLTIPlatform::lookupVersion($platform_id);
220
222 }
$version
Definition: plugin.php:24
static lookupVersion(int $platform_id)
The LTI version of a platform of the administration: LTI Advantage when it has an LTI Advantage regis...
const string VERSION_ADVANTAGE

References $version, ilLTIPlatform\lookupVersion(), and ilLTITool\VERSION_ADVANTAGE.

Referenced by buildForm(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ offerLTIRolesForSelection()

ilLTIProviderObjectSettingGUI::offerLTIRolesForSelection ( bool  $offer)

Kept for the objects that call it, the roles offered are always the ones given above.

Definition at line 81 of file class.ilLTIProviderObjectSettingGUI.php.

81 : void
82 {
83 }

◆ save()

ilLTIProviderObjectSettingGUI::save ( )
private
Exceptions
ilCtrlException

Definition at line 112 of file class.ilLTIProviderObjectSettingGUI.php.

112 : void
113 {
114 $form = $this->buildForm()->withRequest($this->dic->http()->request());
115 $data = $form->getData();
116 if ($data === null) {
117 $this->show($form);
118 return;
119 }
120
121 foreach ($this->getPlatforms() as $platform_id => $title) {
122 $release = $data['platforms']['platform_' . $platform_id] ?? null;
123 if ($release !== null) {
124 new ilLTIRelease($this->ref_id, $platform_id)->save(
125 (int) $release['admin'],
126 (int) $release['tutor'],
127 (int) $release['member']
128 );
129 }
130 if ($this->isAdvantage($platform_id)) {
131 if ($release === null) {
132 new ilLTIRelease($this->ref_id, $platform_id)->delete();
133 }
134 continue;
135 }
136 new ilLTI1p1ProviderObjectCredentials($this->ref_id, $platform_id)->save($release ?? [], $release !== null);
137 }
138
139 $this->dic->ui()->mainTemplate()->setOnScreenMessage('success', $this->dic->language()->txt('settings_saved'), true);
140 $this->dic->ctrl()->redirect($this, self::CMD_SHOW);
141 }
save(array $data, bool $enabled)
Stores the credentials the form posted back, the ones it showed.
buildForm()
One optional group per platform: releasing the object to it and the roles its users get.
delete()
Withdraws the object from an LTI Advantage platform.
save(int $admin_role, int $tutor_role, int $member_role)
$data
Definition: storeScorm.php:45

References $data, buildForm(), ilLTIRelease\delete(), getPlatforms(), isAdvantage(), ilLTI1p1ProviderObjectCredentials\save(), ilLTIRelease\save(), and show().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCustomRolesForSelection()

ilLTIProviderObjectSettingGUI::setCustomRolesForSelection ( array  $role_ids)

An object without local roles gets LTI roles of its own, when the administration has created the global LTI role.

Parameters
array$role_ids

Definition at line 69 of file class.ilLTIProviderObjectSettingGUI.php.

69 : void
70 {
71 if ($role_ids === []) {
72 $this->createLocalRoles();
73 $role_ids = $this->dic->rbac()->review()->getLocalRoles($this->ref_id);
74 }
75 $this->roles = $role_ids;
76 }

References createLocalRoles().

+ Here is the call graph for this function:

◆ show()

ilLTIProviderObjectSettingGUI::show ( ?Form  $form = null)
private
Exceptions
ilCtrlException

Definition at line 104 of file class.ilLTIProviderObjectSettingGUI.php.

104 : void
105 {
106 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render($form ?? $this->buildForm()));
107 }

Referenced by executeCommand(), and save().

+ Here is the caller graph for this function:

Field Documentation

◆ $dic

readonly ILIAS DI Container ilLTIProviderObjectSettingGUI::$dic
private

Definition at line 37 of file class.ilLTIProviderObjectSettingGUI.php.

◆ $roles

array ilLTIProviderObjectSettingGUI::$roles = []
private

Definition at line 41 of file class.ilLTIProviderObjectSettingGUI.php.

Referenced by buildForm().

◆ CMD_SAVE

const string ilLTIProviderObjectSettingGUI::CMD_SAVE = 'updateSettings'

Definition at line 35 of file class.ilLTIProviderObjectSettingGUI.php.

◆ CMD_SHOW

const string ilLTIProviderObjectSettingGUI::CMD_SHOW = 'settings'

Definition at line 34 of file class.ilLTIProviderObjectSettingGUI.php.


The documentation for this class was generated from the following file: