ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjLTIAdministrationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Object/classes/class.ilObjectGUI.php';
5// require_once 'Services/LTI/classes/ActiveRecord/class.ilLTIExternalConsumer.php';
6require_once 'Services/LTI/classes/InternalProvider/class.ilLTIToolConsumer.php';
7require_once 'Services/LTI/classes/class.ilLTIDataConnector.php';
8
9
21{
27 private $dataConnector = null;
28
29 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
30 {
31 $this->type = "ltis";
32 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
33 $this->dataConnector = new ilLTIDataConnector();
34
35 $GLOBALS['DIC']->language()->loadLanguageModule('lti');
36 }
37
38 public function executeCommand()
39 {
40 $next_class = $this->ctrl->getNextClass($this);
41 $cmd = $this->ctrl->getCmd();
42
43 $this->prepareOutput();
44
45 switch ($next_class) {
46 case 'ilpermissiongui':
47 $GLOBALS['ilTabs']->activateTab('perm_settings');
48 require_once 'Services/AccessControl/classes/class.ilPermissionGUI.php';
49 $perm_gui = new ilPermissionGUI($this);
50 $this->ctrl->forwardCommand($perm_gui);
51 break;
52
53 case 'illticonsumeradministrationgui':
54 $this->tabs_gui->activateTab('lti_consuming');
56 $this->ctrl->forwardCommand($gui);
57 break;
58
59 default:
60 $this->tabs_gui->activateTab('lti_providing');
61 if (!$cmd || $cmd == 'view') {
62 $cmd = 'listConsumers';
63 } elseif ($cmd == 'createconsumer') {
64 $cmd = "initConsumerForm";
65 }
66 $this->$cmd();
67 break;
68 }
69 }
70
71 public function getType()
72 {
73 return "ltis";
74 }
75
76 public function getAdminTabs()
77 {
78 global $DIC; /* @var \ILIAS\DI\Container $DIC */
79 global $rbacsystem;
80
81 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
82 $this->tabs_gui->addTab(
83 'lti_providing',
84 $this->lng->txt("lti_providing_tab"),
85 $this->ctrl->getLinkTarget($this, "listConsumers")
86 );
87
88 $this->tabs_gui->addTab(
89 'lti_consuming',
90 $this->lng->txt("lti_consuming_tab"),
91 $this->ctrl->getLinkTargetByClass('ilLTIConsumerAdministrationGUI')
92 );
93
94 if ($DIC->ctrl()->getCmdClass() == 'ilobjltiadministrationgui') {
95 $this->addProvidingSubtabs();
96 }
97 }
98
99 if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
100 $this->tabs_gui->addTab(
101 "perm_settings",
102 $this->lng->txt("perm_settings"),
103 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
104 );
105 }
106 }
107
108 protected function addProvidingSubtabs()
109 {
110 global $DIC; /* @var \ILIAS\DI\Container $DIC */
111 $rbacsystem = $DIC->rbac()->system();
112
113 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
114 // currently no general settings.
115 // $this->tabs_gui->addTab("settings",
116 // $this->lng->txt("settings"),
117 // $this->ctrl->getLinkTarget($this, "initSettingsForm"));
118
119 $this->tabs_gui->addSubTab(
120 "consumers",
121 $this->lng->txt("consumers"),
122 $this->ctrl->getLinkTarget($this, "listConsumers")
123 );
124 }
125 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
126 $this->tabs_gui->addSubTab(
127 "releasedObjects",
128 $this->lng->txt("lti_released_objects"),
129 $this->ctrl->getLinkTarget($this, "releasedObjects")
130 );
131 }
132 }
133
134 protected function initSettingsForm(ilPropertyFormGUI $form = null)
135 {
136 if (!($form instanceof ilPropertyFormGUI)) {
137 $form = $this->getSettingsForm();
138 }
139 $this->tabs_gui->activateSubTab("settings");
140 $this->tpl->setContent($form->getHTML());
141 }
142
143
144 protected function getSettingsForm()
145 {
146 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
147
148 $form = new ilPropertyFormGUI();
149 /*
150 $form->setFormAction($this->ctrl->getFormAction($this,'saveSettingsForm'));
151 $form->setTitle($this->lng->txt("lti_settings"));
152
153 // object types
154 $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
155
156 $valid_obj_types = $this->object->getLTIObjectTypes();
157 foreach($valid_obj_types as $obj_type_id => $obj_name)
158 {
159 $cb_obj_types->addOption(new ilCheckboxOption($obj_name, $obj_type_id));
160 }
161 $objs_active = $this->object->getActiveObjectTypes();
162 $cb_obj_types->setValue($objs_active);
163 $form->addItem($cb_obj_types);
164
165 // test roles
166 $roles = $this->object->getLTIRoles();
167 foreach($roles as $role_id => $role_name)
168 {
169 $options[$role_id] = $role_name;
170 }
171 $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'roles');
172 $si_roles->setOptions($options);
173 $si_roles->setValue($this->object->getCurrentRole());
174 $form->addItem($si_roles);
175
176 $form->addCommandButton("saveSettingsForm", $this->lng->txt("save"));
177 */
178 return $form;
179 }
180
181 /*
182 protected function saveSettingsForm()
183 {
184 global $ilCtrl;
185
186 $this->checkPermission("write");
187
188 $form = $this->getSettingsForm();
189 if($form->checkInput())
190 {
191 $obj_types = $form->getInput('types');
192
193 $role = $form->getInput('role');
194
195 $this->object->saveData($obj_types, $role);
196
197 ilUtil::sendSuccess($this->lng->txt("settings_saved"),true);
198 }
199
200 $form->setValuesByPost();
201 $this->initSettingsForm($form);
202 }
203 */
204
205 // create global role LTI-User
206 protected function createLtiUserRole()
207 {
208 global $DIC;
209 $rbacadmin = $DIC['rbacadmin'];
210 // include_once './Services/AccessControl/classes/class.ilObjRole.php';
211 $role = new ilObjRole();
212 $role->setTitle("il_lti_global_role");
213 $role->setDescription("This global role should only contain the permission 'read' for repository and categories.");
214 $role->create();
215 $rbacadmin->assignRoleToFolder($role->getId(), 8, 'y');
216 $rbacadmin->setProtected(8, $role->getId(), 'y');
217 $rbacadmin->setRolePermission($role->getId(), 'root', [3], 8);
218 $rbacadmin->setRolePermission($role->getId(), 'cat', [3], 8);
219 $rbacadmin->grantPermission($role->getId(), [3], ROOT_FOLDER_ID);
220 $role->changeExistingObjects(
221 ROOT_FOLDER_ID,
223 array('cat'),
224 array());
225
226 ilUtil::sendSuccess($this->lng->txt("lti_user_role_created"), true);
227 $this->listConsumers();
228 }
229
230
231 // consumers
232
233 protected function initConsumerForm(ilPropertyFormGUI $form = null)
234 {
235 if (!($form instanceof ilPropertyFormGUI)) {
236 $form = $this->getConsumerForm();
237 }
238 $this->tpl->setContent($form->getHTML());
239 }
240
245 protected function getConsumerForm($a_mode = '')
246 {
247 $this->tabs_gui->activateSubTab("consumers");
248
249 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
250
251 $form = new ilPropertyFormGUI();
252
253 $ti_title = new ilTextInputGUI($this->lng->txt("title"), 'title');
254 $ti_title->setRequired(true);
255 $ti_description = new ilTextInputGUI($this->lng->txt("description"), 'description');
256 $ti_prefix = new ilTextInputGUI($this->lng->txt("prefix"), 'prefix');
257 $ti_prefix->setRequired(true);
258 #$ti_key = new ilTextInputGUI($this->lng->txt("lti_consumer_key"), 'key');
259 #$ti_key->setRequired(true);
260 #$ti_secret = new ilTextInputGUI($this->lng->txt("lti_consumer_secret"), 'secret');
261 #$ti_secret->setRequired(true);
262
263 $languages = $this->lng->getInstalledLanguages();
264 $array_lang = array();
265 foreach ($languages as $lang_key) {
266 $array_lang[$lang_key] = ilLanguage::_lookupEntry($lang_key, "meta", "meta_l_" . $lang_key);
267 }
268
269 $si_language = new ilSelectInputGUI($this->lng->txt("language"), "language");
270 $si_language->setOptions($array_lang);
271
272 $cb_active = new ilCheckboxInputGUI($this->lng->txt('active'), 'active');
273
274 $form->addItem($cb_active);
275 $form->addItem($ti_title);
276 $form->addItem($ti_description);
277 $form->addItem($ti_prefix);
278 #$form->addItem($ti_key);
279 #$form->addItem($ti_secret);
280 $form->addItem($si_language);
281
282 // object types
283 $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
284
285 $valid_obj_types = $this->object->getLTIObjectTypes();
286 foreach ($valid_obj_types as $obj_type) {
287 $object_name = $GLOBALS['DIC']->language()->txt('objs_' . $obj_type);
288 $cb_obj_types->addOption(new ilCheckboxOption($object_name, $obj_type));
289 }
290 $form->addItem($cb_obj_types);
291
292 // test roles
293 $roles = $this->object->getLTIRoles();
294 foreach ($roles as $role_id => $role_name) {
295 $options[$role_id] = $role_name;
296 }
297 $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'role');
298 $si_roles->setOptions($options);
299 $form->addItem($si_roles);
300
301 if ($a_mode == 'edit') {
302 $form->setFormAction($this->ctrl->getFormAction($this, 'editLTIConsumer'));
303 $form->setTitle($this->lng->txt("lti_edit_consumer"));
304 $form->addCommandButton("updateLTIConsumer", $this->lng->txt("save"));
305 } else {
306 $form->setFormAction($this->ctrl->getFormAction($this, 'createLTIConsumer'));
307 $form->setTitle($this->lng->txt("lti_create_consumer"));
308 $form->addCommandButton("createLTIConsumer", $this->lng->txt("save"));
309 $form->addCommandButton('listConsumers', $this->lng->txt('cancel'));
310 }
311
312 return $form;
313 }
314
321 protected function editConsumer(ilPropertyFormGUI $a_form = null)
322 {
323 global $ilCtrl, $tpl;
324 $consumer_id = $_REQUEST["cid"];
325 $ilCtrl->setParameter($this, "cid", $consumer_id);
326
327 if (!$consumer_id) {
328 $ilCtrl->redirect($this, "listConsumers");
329 }
330
331 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
332 if (!$a_form instanceof ilPropertyFormGUI) {
333 $a_form = $this->getConsumerForm('edit');
334 $a_form->getItemByPostVar("title")->setValue($consumer->getTitle());
335 $a_form->getItemByPostVar("description")->setValue($consumer->getDescription());
336 $a_form->getItemByPostVar("prefix")->setValue($consumer->getPrefix());
337 $a_form->getItemByPostVar("language")->setValue($consumer->getLanguage());
338 $a_form->getItemByPostVar("active")->setChecked($consumer->getActive());
339 $a_form->getItemByPostVar("role")->setValue($consumer->getRole());
340 $a_form->getItemByPostVar("types")->setValue($this->object->getActiveObjectTypes($consumer_id));
341 }
342 $tpl->setContent($a_form->getHTML());
343 }
344
348 protected function createLTIConsumer()
349 {
350 $this->checkPermission("write");
351
352 $form = $this->getConsumerForm();
353
354 if ($form->checkInput()) {
355 // $consumer = new ilLTIExternalConsumer();
356 // $dataConnector = new ilLTIDataConnector();
357 $consumer = new ilLTIToolConsumer(null, $this->dataConnector);
358 $consumer->setTitle($form->getInput('title'));
359 $consumer->setDescription($form->getInput('description'));
360 $consumer->setPrefix($form->getInput('prefix'));
361 $consumer->setLanguage($form->getInput('language'));
362 $consumer->setActive($form->getInput('active'));
363 $consumer->setRole($form->getInput('role'));
364 $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
365
366 $this->object->saveConsumerObjectTypes(
367 $consumer->getExtConsumerId(),
368 $form->getInput('types')
369 );
370 ilUtil::sendSuccess($this->lng->txt("lti_consumer_created"), true);
371 $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
372 }
373
374 $form->setValuesByPost();
375 $this->listConsumers();
376 return;
377 }
378
383 protected function updateLTIConsumer()
384 {
385 global $ilCtrl;
386
387 $this->checkPermission("write");
388
389 $consumer_id = $_REQUEST["cid"];
390 if (!$consumer_id) {
391 $ilCtrl->redirect($this, "listConsumers");
392 }
393
394 $ilCtrl->setParameter($this, "cid", $consumer_id);
395
396 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
397 $form = $this->getConsumerForm('edit');
398 if ($form->checkInput()) {
399 $consumer->setTitle($form->getInput('title'));
400 $consumer->setDescription($form->getInput('description'));
401 $consumer->setPrefix($form->getInput('prefix'));
402 $consumer->setLanguage($form->getInput('language'));
403 $consumer->setActive($form->getInput('active'));
404 $consumer->setRole($form->getInput('role'));
405 $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
406 $this->object->saveConsumerObjectTypes($consumer_id, $form->getInput('types'));
407
408 ilUtil::sendSuccess($this->lng->txt("lti_consumer_updated"), true);
409 }
410 $this->listConsumers();
411 }
412
417 protected function deleteLTIConsumer()
418 {
419 global $ilCtrl;
420
421 $consumer_id = $_REQUEST['cid'];
422
423 if (!$consumer_id) {
424 $ilCtrl->redirect($this, "listConsumers");
425 }
426 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
427 $consumer->deleteGlobalToolConsumerSettings($this->dataConnector);
428 ilUtil::sendSuccess($this->lng->txt("lti_consumer_deleted"), true);
429 $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
430 }
431
432
438 protected function listConsumers()
439 {
440 global $ilAccess, $ilToolbar;
441
442 if ($this->checkPermissionBool('write')) {
443 $ilToolbar->addButton(
444 $this->lng->txt('lti_create_consumer'),
445 $this->ctrl->getLinkTarget($this, 'createconsumer')
446 );
447 if (ilObject::_getIdsForTitle("il_lti_global_role", "role", false) == false) {
448 $ilToolbar->addButton(
449 $this->lng->txt('lti_create_lti_user_role'),
450 $this->ctrl->getLinkTarget($this, 'createLtiUserRole')
451 );
452 $ilToolbar->addText($this->lng->txt('lti_user_role_info'));
453 }
454
455 }
456
457 $this->tabs_gui->activateSubTab("consumers");
458
459 include_once "Services/LTI/classes/Consumer/class.ilLTIConsumerTableGUI.php";
460 $tbl = new ilObjectConsumerTableGUI(
461 $this,
462 "listConsumers"
463 );
464 $tbl->setEditable($this->checkPermissionBool('write'));
465 $this->tpl->setContent($tbl->getHTML());
466 }
467
472 protected function changeStatusLTIConsumer()
473 {
474 global $ilCtrl;
475
476 $consumer_id = $_REQUEST["cid"];
477
478 if (!$consumer_id) {
479 $ilCtrl->redirect($this, "listConsumers");
480 }
481
482 $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
483 if ($consumer->getActive()) {
484 $consumer->setActive(0);
485 $msg = "lti_consumer_set_inactive";
486 } else {
487 $consumer->setActive(1);
488 $msg = "lti_consumer_set_active";
489 }
490 $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
491 ilUtil::sendSuccess($this->lng->txt($msg), true);
492
493 $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
494 }
495
499 protected function releasedObjects()
500 {
501 $GLOBALS['DIC']->tabs()->activateSubTab('releasedObjects');
502
503 $table = new ilLTIProviderReleasedObjectsTableGUI($this, 'releasedObjects', 'ltireleases');
504 $table->init();
505 $table->parse();
506
507 $GLOBALS['DIC']->ui()->mainTemplate()->setContent($table->getHTML());
508 }
509}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
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 to represent an LTI Data Connector for ILIAS.
LTI provider for LTI launch.
static fromExternalConsumerId($id, $dataConnector)
static _lookupEntry($a_lang_key, $a_mod, $a_id)
Class ilObjLTIAdministrationGUI.
editConsumer(ilPropertyFormGUI $a_form=null)
Edit consumer @global type $ilCtrl @global type $tpl.
getAdminTabs()
administration tabs show only permissions and trash folder
deleteLTIConsumer()
Delete consumers @global type $ilCtrl.
initConsumerForm(ilPropertyFormGUI $form=null)
$dataConnector
Data connector object or string.
updateLTIConsumer()
Update lti consumer settings @global ilCtrl $ilCtrl.
createLTIConsumer()
Create new lti consumer.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
listConsumers()
List consumers @global type $ilAccess @global type $ilToolbar.
changeStatusLTIConsumer()
Change activation status @global type $ilCtrl.
initSettingsForm(ilPropertyFormGUI $form=null)
Class ilObjRole.
const MODE_UNPROTECTED_KEEP_LOCAL_POLICIES
TableGUI class for LTI consumer listing.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
static _getIdsForTitle($title, $type='', $partialmatch=false)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46