ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLTIProviderObjectSettingGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
13 const ROLE_ADMIN = 'admin';
14 const ROLE_TUTOR = 'tutor';
15 const ROLE_MEMBER = 'member';
16
17
21 protected $ctrl = null;
22
26 protected $logger = null;
27
31 protected $lng = null;
32
36 protected $tpl = null;
37
41 protected $ref_id = null;
42
47 protected $custom_roles = [];
48
52 protected $use_lti_roles = true;
53
57 public function __construct($a_ref_id)
58 {
59 $this->ref_id = $a_ref_id;
60 $this->logger = $GLOBALS['DIC']->logger()->lti();
61 $this->ctrl = $GLOBALS['DIC']->ctrl();
62 $this->tpl = $GLOBALS['DIC']->ui()->mainTemplate();
63
64 $this->lng = $GLOBALS['DIC']->language();
65 $this->lng->loadLanguageModule('lti');
66 }
67
73 public function hasSettingsAccess()
74 {
75 if (!ilObjLTIAdministration::isEnabledForType(ilObject::_lookupType($this->ref_id, true))) {
76 $this->logger->debug('No LTI consumers activated for object type: ' . ilObject::_lookupType($this->ref_id, true));
77 return false;
78 }
79 $access = $GLOBALS['DIC']->rbac()->system();
80 return $access->checkAccess(
81 'release_objects',
83 );
84 }
85
90 public function setCustomRolesForSelection($a_roles)
91 {
92 if (empty($a_roles)) {
93 $this->checkLocalRole();
94 $a_roles = $GLOBALS['DIC']->rbac()->review()->getLocalRoles($this->ref_id);
95 }
96 $this->custom_roles = $a_roles;
97 }
98
103 public function offerLTIRolesForSelection($a_stat)
104 {
105 $this->use_lti_roles = $a_stat;
106 }
107
108
112 public function executeCommand()
113 {
114 $cmd = $this->ctrl->getCmd('settings');
115 $next_class = $this->ctrl->getNextClass($this);
116
117 switch ($next_class) {
118 default:
119 $this->$cmd();
120 break;
121 }
122 }
123
128 protected function settings(ilPropertyFormGUI $form = null)
129 {
130 if (!$form instanceof ilPropertyFormGUI) {
131 $form = $this->initObjectSettingsForm();
132 }
133 $this->tpl->setContent($form->getHTML());
134 }
135
136
140 protected function initObjectSettingsForm()
141 {
142 $form = new ilPropertyFormGUI();
143 $form->setFormAction($this->ctrl->getFormAction($this));
144 $form->setTitle($this->lng->txt('lti_object_release_settings_form'));
145
146 foreach (ilObjLTIAdministration::getEnabledConsumersForType(ilObject::_lookupType($this->ref_id, true)) as $global_consumer) {
147 $object_info = new ilLTIProviderObjectSetting($this->ref_id, $global_consumer->getExtConsumerId());
148
149 $this->logger->debug($object_info->getAdminRole());
150
151
152 // meta data for external consumers
154 $section->setTitle($global_consumer->getTitle());
155 $section->setInfo($global_consumer->getDescription());
156 $form->addItem($section);
157
158 $connector = new ilLTIDataConnector();
159
161 $global_consumer->getExtConsumerId(),
162 $this->ref_id,
163 $connector
164 );
165
166 $active = new ilCheckboxInputGUI($GLOBALS['lng']->txt('lti_obj_active'), 'lti_active_' . $global_consumer->getExtConsumerId());
167 $active->setInfo($GLOBALS['lng']->txt('lti_obj_active_info'));
168 $active->setValue(1);
169 $form->addItem($active);
170
171 if ($active_consumer->getEnabled()) { // and enabled
172 $active->setChecked(true);
173
174 $url = new ilNonEditableValueGUI($this->lng->txt('lti_launch_url'), 'url');
175 $url->setValue(ILIAS_HTTP_PATH . '/lti.php?client_id=' . CLIENT_ID);
176 $active->addSubItem($url);
177
178 $key = new ilNonEditableValueGUI($this->lng->txt('lti_consumer_key'), 'key');
179 $key->setValue($active_consumer->getKey());
180 $active->addSubItem($key);
181
182 $secret = new ilNonEditableValueGUI($this->lng->txt('lti_consumer_secret'), 'secret');
183 $secret->setValue($active_consumer->getSecret());
184 $active->addSubItem($secret);
185 }
186
187 if ($this->custom_roles) {
188 $admin = new ilSelectInputGUI(
189 $this->lng->txt('lti_admin'),
190 'lti_admin_' . $global_consumer->getExtConsumerId()
191 );
192 $admin->setOptions($this->getRoleSelection());
193 $admin->setValue($object_info->getAdminRole() ? $object_info->getAdminRole() : 0);
194 $active->addSubItem($admin);
195
196 $tutor = new ilSelectInputGUI(
197 $this->lng->txt('lti_tutor'),
198 'lti_tutor_' . $global_consumer->getExtConsumerId()
199 );
200 $tutor->setOptions($this->getRoleSelection());
201 $tutor->setValue($object_info->getTutorRole() ? $object_info->getTutorRole() : 0);
202 $active->addSubItem($tutor);
203
204 $member = new ilSelectInputGUI(
205 $this->lng->txt('lti_member'),
206 'lti_member_' . $global_consumer->getExtConsumerId()
207 );
208 $member->setOptions($this->getRoleSelection());
209 $member->setValue($object_info->getMemberRole() ? $object_info->getMemberRole() : 0);
210 $active->addSubItem($member);
211 }
212 }
213
214 $form->addCommandButton('updateSettings', $this->lng->txt('save'));
215 return $form;
216 }
217
221 protected function updateSettings()
222 {
223 $form = $this->initObjectSettingsForm();
224 if (!$form->checkInput()) {
225 $form->setValuesByPost();
226 $this->settings($form);
227 return;
228 }
229
230 $connector = new ilLTIDataConnector();
231 foreach (ilObjLTIAdministration::getEnabledConsumersForType(ilObject::_lookupType($this->ref_id, true)) as $global_consumer) {
232 $this->saveRoleSelection($form, $global_consumer->getExtConsumerId());
233
235 $global_consumer->getExtConsumerId(),
236 $this->ref_id,
237 $connector
238 );
239 if (!$form->getInput('lti_active_' . $global_consumer->getExtConsumerId())) {
240 // not active anymore => delete consumer
241 if ($consumer->getEnabled()) {
242 $this->logger->info('Deleting lti consumer for object reference: ' . $this->ref_id);
243 $consumer->delete();
244 }
245 } else {
246 // new activation
247 if (!$consumer->getEnabled()) {
248 $this->logger->info('Created new lti release for: ' . $this->ref_id);
249 $consumer->setExtConsumerId($global_consumer->getExtConsumerId());
250 $consumer->createSecret();
251 $consumer->setRefId($this->ref_id);
252 $consumer->setEnabled(true);
253 $consumer->saveLTI($connector);
254 }
255 }
256 }
257
258 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
259 $this->ctrl->redirect($this, 'settings');
260 }
261
267 protected function saveRoleSelection(ilPropertyFormGUI $form, $global_consumer_id)
268 {
269 $object_info = new ilLTIProviderObjectSetting($this->ref_id, $global_consumer_id);
270
271 $admin_role = $form->getInput('lti_admin_' . $global_consumer_id);
272 if ($admin_role > 0) {
273 $object_info->setAdminRole($admin_role);
274 }
275 $tutor_role = $form->getInput('lti_tutor_' . $global_consumer_id);
276 if ($tutor_role > 0) {
277 $object_info->setTutorRole($tutor_role);
278 }
279 $member_role = $form->getInput('lti_member_' . $global_consumer_id);
280 if ($member_role > 0) {
281 $object_info->setMemberRole($member_role);
282 }
283 $object_info->save();
284 }
285
286
291 protected function getRoleSelection()
292 {
293 $options = [];
294 $options[0] = $this->lng->txt('select_one');
295 foreach ($this->custom_roles as $role_id) {
297 $options[$role_id] = $title;
298 }
299 return $options;
300 }
301
305 protected function checkLocalRole()
306 {
307 global $DIC;
308 $a_global_role = ilObject::_getIdsForTitle("il_lti_global_role", "role", false);
309 if (is_array($a_global_role) && !empty($a_global_role)) {
310 $rbacreview = $DIC['rbacreview'];
311 if (count($rbacreview->getRolesOfObject($this->ref_id, false)) == 0) {
312 $rbacadmin = $DIC['rbacadmin'];
313 $type = ilObject::_lookupType($this->ref_id, true);
314 $role = new ilObjRole();
315 $role->setTitle("il_lti_learner");
316 $role->setDescription("LTI Learner of " . $type . " obj_no." . ilObject::_lookupObjectId($this->ref_id));
317 $role->create();
318 $rbacadmin->assignRoleToFolder($role->getId(), $this->ref_id, 'y');
319 $rbacadmin->grantPermission($role->getId(), ilRbacReview::_getOperationIdsByName(array('visible','read')), $this->ref_id);
320 // $rbacadmin->setRolePermission($role->getId(), ilObject::_lookupType($this->ref_id, true), [2,3], $this->ref_id);
321 if ($type == "sahs" || $type == "lm" || $type == "svy" || $type == "tst") {
322 $role = new ilObjRole();
323 $role->setTitle("il_lti_instructor");
324 $role->setDescription("LTI Instructor of " . $type . " obj_no." . ilObject::_lookupObjectId($this->ref_id));
325 $role->create();
326 $rbacadmin->assignRoleToFolder($role->getId(), $this->ref_id, 'y');
327 $ops = ilRbacReview::_getOperationIdsByName(array('visible','read','read_learning_progress'));
328 if ($type == "svy") {
329 $ops[] = ilRbacReview::_getOperationIdsByName(array('read_results'))[0];
330 }
331 if ($type == "tst") {
332 $ops[] = ilRbacReview::_getOperationIdsByName(array('tst_results'))[0];
333 $ops[] = ilRbacReview::_getOperationIdsByName(array('tst_statistics'))[0];
334 }
335 $rbacadmin->grantPermission($role->getId(), $ops, $this->ref_id);
336 }
337 }
338 }
339 }
340}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
This class represents a section header in a property form.
Class to represent an LTI Data Connector for ILIAS.
GUI class for LTI provider object settings.
saveRoleSelection(ilPropertyFormGUI $form, $global_consumer_id)
Save role selection for consumer.
updateSettings()
Update settings (activate deactivate lti access)
setCustomRolesForSelection($a_roles)
Set custom roles for mapping to LTI roles.
hasSettingsAccess()
Check if user has access to lti settings.
offerLTIRolesForSelection($a_stat)
Offer LTI roles for mapping.
settings(ilPropertyFormGUI $form=null)
Show settings.
checkLocalRole()
check for local roles for lti objects which are not grp or crs
static fromGlobalSettingsAndRefId($a_ext_consumer_id, $a_ref_id, ilLTIDataConnector $a_data_connector)
Load consumer from global settings and ref_id.
This class represents a non editable value in a property form.
static lookupLTISettingsRefId()
Lookup ref_id.
Class ilObjRole.
static _getTranslation($a_role_title)
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getIdsForTitle($title, $type='', $partialmatch=false)
This class represents a property form user interface.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static _getOperationIdsByName($operations)
get ops_id's by name.
This class represents a selection list property in a property form.
$type
$url
$DIC
Definition: xapitoken.php:46