ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
4 require_once 'Services/Object/classes/class.ilObjectGUI.php';
5 // require_once 'Services/LTI/classes/ActiveRecord/class.ilLTIExternalConsumer.php';
6 require_once 'Services/LTI/classes/InternalProvider/class.ilLTIToolConsumer.php';
7 require_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');
55  $gui = new ilLTIConsumerAdministrationGUI();
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  $DIC->help()->setScreenIdComponent("ltis");
82 
83  if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
84  $this->tabs_gui->addTab(
85  'lti_providing',
86  $this->lng->txt("lti_providing_tab"),
87  $this->ctrl->getLinkTarget($this, "listConsumers")
88  );
89 
90  $this->tabs_gui->addTab(
91  'lti_consuming',
92  $this->lng->txt("lti_consuming_tab"),
93  $this->ctrl->getLinkTargetByClass('ilLTIConsumerAdministrationGUI')
94  );
95 
96  if ($DIC->ctrl()->getCmdClass() == 'ilobjltiadministrationgui') {
97  $this->addProvidingSubtabs();
98  }
99  }
100 
101  if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
102  $this->tabs_gui->addTab(
103  "perm_settings",
104  $this->lng->txt("perm_settings"),
105  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
106  );
107  }
108  }
109 
110  protected function addProvidingSubtabs()
111  {
112  global $DIC; /* @var \ILIAS\DI\Container $DIC */
113  $rbacsystem = $DIC->rbac()->system();
114 
115  if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
116  // currently no general settings.
117  // $this->tabs_gui->addTab("settings",
118  // $this->lng->txt("settings"),
119  // $this->ctrl->getLinkTarget($this, "initSettingsForm"));
120 
121  $this->tabs_gui->addSubTab(
122  "consumers",
123  $this->lng->txt("consumers"),
124  $this->ctrl->getLinkTarget($this, "listConsumers")
125  );
126  }
127  if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
128  $this->tabs_gui->addSubTab(
129  "releasedObjects",
130  $this->lng->txt("lti_released_objects"),
131  $this->ctrl->getLinkTarget($this, "releasedObjects")
132  );
133  }
134  }
135 
136  protected function initSettingsForm(ilPropertyFormGUI $form = null)
137  {
138  if (!($form instanceof ilPropertyFormGUI)) {
139  $form = $this->getSettingsForm();
140  }
141  $this->tabs_gui->activateSubTab("settings");
142  $this->tpl->setContent($form->getHTML());
143  }
144 
145 
146  protected function getSettingsForm()
147  {
148  require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
149 
150  $form = new ilPropertyFormGUI();
151  /*
152  $form->setFormAction($this->ctrl->getFormAction($this,'saveSettingsForm'));
153  $form->setTitle($this->lng->txt("lti_settings"));
154 
155  // object types
156  $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
157 
158  $valid_obj_types = $this->object->getLTIObjectTypes();
159  foreach($valid_obj_types as $obj_type_id => $obj_name)
160  {
161  $cb_obj_types->addOption(new ilCheckboxOption($obj_name, $obj_type_id));
162  }
163  $objs_active = $this->object->getActiveObjectTypes();
164  $cb_obj_types->setValue($objs_active);
165  $form->addItem($cb_obj_types);
166 
167  // test roles
168  $roles = $this->object->getLTIRoles();
169  foreach($roles as $role_id => $role_name)
170  {
171  $options[$role_id] = $role_name;
172  }
173  $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'roles');
174  $si_roles->setOptions($options);
175  $si_roles->setValue($this->object->getCurrentRole());
176  $form->addItem($si_roles);
177 
178  $form->addCommandButton("saveSettingsForm", $this->lng->txt("save"));
179  */
180  return $form;
181  }
182 
183  /*
184  protected function saveSettingsForm()
185  {
186  global $ilCtrl;
187 
188  $this->checkPermission("write");
189 
190  $form = $this->getSettingsForm();
191  if($form->checkInput())
192  {
193  $obj_types = $form->getInput('types');
194 
195  $role = $form->getInput('role');
196 
197  $this->object->saveData($obj_types, $role);
198 
199  ilUtil::sendSuccess($this->lng->txt("settings_saved"),true);
200  }
201 
202  $form->setValuesByPost();
203  $this->initSettingsForm($form);
204  }
205  */
206 
207  // create global role LTI-User
208  protected function createLtiUserRole()
209  {
210  global $DIC;
211  $rbacadmin = $DIC['rbacadmin'];
212  // include_once './Services/AccessControl/classes/class.ilObjRole.php';
213  $role = new ilObjRole();
214  $role->setTitle("il_lti_global_role");
215  $role->setDescription("This global role should only contain the permission 'read' for repository and categories.");
216  $role->create();
217  $rbacadmin->assignRoleToFolder($role->getId(), 8, 'y');
218  $rbacadmin->setProtected(8, $role->getId(), 'y');
219  $rbacadmin->setRolePermission($role->getId(), 'root', [3], 8);
220  $rbacadmin->setRolePermission($role->getId(), 'cat', [3], 8);
221  $rbacadmin->grantPermission($role->getId(), [3], ROOT_FOLDER_ID);
222  $role->changeExistingObjects(
225  array('cat'),
226  array()
227  );
228 
229  ilUtil::sendSuccess($this->lng->txt("lti_user_role_created"), true);
230  $this->listConsumers();
231  }
232 
233 
234  // consumers
235 
236  protected function initConsumerForm(ilPropertyFormGUI $form = null)
237  {
238  if (!($form instanceof ilPropertyFormGUI)) {
239  $form = $this->getConsumerForm();
240  }
241  $this->tpl->setContent($form->getHTML());
242  }
243 
248  protected function getConsumerForm($a_mode = '')
249  {
250  $this->tabs_gui->activateSubTab("consumers");
251 
252  require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
253 
254  $form = new ilPropertyFormGUI();
255 
256  $ti_title = new ilTextInputGUI($this->lng->txt("title"), 'title');
257  $ti_title->setRequired(true);
258  $ti_description = new ilTextInputGUI($this->lng->txt("description"), 'description');
259  $ti_prefix = new ilTextInputGUI($this->lng->txt("prefix"), 'prefix');
260  $ti_prefix->setRequired(true);
261  #$ti_key = new ilTextInputGUI($this->lng->txt("lti_consumer_key"), 'key');
262  #$ti_key->setRequired(true);
263  #$ti_secret = new ilTextInputGUI($this->lng->txt("lti_consumer_secret"), 'secret');
264  #$ti_secret->setRequired(true);
265 
266  $languages = $this->lng->getInstalledLanguages();
267  $array_lang = array();
268  foreach ($languages as $lang_key) {
269  $array_lang[$lang_key] = ilLanguage::_lookupEntry($lang_key, "meta", "meta_l_" . $lang_key);
270  }
271 
272  $si_language = new ilSelectInputGUI($this->lng->txt("language"), "language");
273  $si_language->setOptions($array_lang);
274 
275  $cb_active = new ilCheckboxInputGUI($this->lng->txt('active'), 'active');
276 
277  $form->addItem($cb_active);
278  $form->addItem($ti_title);
279  $form->addItem($ti_description);
280  $form->addItem($ti_prefix);
281  #$form->addItem($ti_key);
282  #$form->addItem($ti_secret);
283  $form->addItem($si_language);
284 
285  // object types
286  $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
287 
288  $valid_obj_types = $this->object->getLTIObjectTypes();
289  foreach ($valid_obj_types as $obj_type) {
290  $object_name = $GLOBALS['DIC']->language()->txt('objs_' . $obj_type);
291  $cb_obj_types->addOption(new ilCheckboxOption($object_name, $obj_type));
292  }
293  $form->addItem($cb_obj_types);
294 
295  // test roles
296  $roles = $this->object->getLTIRoles();
297  foreach ($roles as $role_id => $role_name) {
298  $options[$role_id] = $role_name;
299  }
300  $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'role');
301  $si_roles->setOptions($options);
302  $form->addItem($si_roles);
303 
304  if ($a_mode == 'edit') {
305  $form->setFormAction($this->ctrl->getFormAction($this, 'editLTIConsumer'));
306  $form->setTitle($this->lng->txt("lti_edit_consumer"));
307  $form->addCommandButton("updateLTIConsumer", $this->lng->txt("save"));
308  } else {
309  $form->setFormAction($this->ctrl->getFormAction($this, 'createLTIConsumer'));
310  $form->setTitle($this->lng->txt("lti_create_consumer"));
311  $form->addCommandButton("createLTIConsumer", $this->lng->txt("save"));
312  $form->addCommandButton('listConsumers', $this->lng->txt('cancel'));
313  }
314 
315  return $form;
316  }
317 
324  protected function editConsumer(ilPropertyFormGUI $a_form = null)
325  {
326  global $ilCtrl, $tpl;
327  $consumer_id = $_REQUEST["cid"];
328  $ilCtrl->setParameter($this, "cid", $consumer_id);
329 
330  if (!$consumer_id) {
331  $ilCtrl->redirect($this, "listConsumers");
332  }
333 
334  $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
335  if (!$a_form instanceof ilPropertyFormGUI) {
336  $a_form = $this->getConsumerForm('edit');
337  $a_form->getItemByPostVar("title")->setValue($consumer->getTitle());
338  $a_form->getItemByPostVar("description")->setValue($consumer->getDescription());
339  $a_form->getItemByPostVar("prefix")->setValue($consumer->getPrefix());
340  $a_form->getItemByPostVar("language")->setValue($consumer->getLanguage());
341  $a_form->getItemByPostVar("active")->setChecked($consumer->getActive());
342  $a_form->getItemByPostVar("role")->setValue($consumer->getRole());
343  $a_form->getItemByPostVar("types")->setValue($this->object->getActiveObjectTypes($consumer_id));
344  }
345  $tpl->setContent($a_form->getHTML());
346  }
347 
351  protected function createLTIConsumer()
352  {
353  $this->checkPermission("write");
354 
355  $form = $this->getConsumerForm();
356 
357  if ($form->checkInput()) {
358  // $consumer = new ilLTIExternalConsumer();
359  // $dataConnector = new ilLTIDataConnector();
360  $consumer = new ilLTIToolConsumer(null, $this->dataConnector);
361  $consumer->setTitle($form->getInput('title'));
362  $consumer->setDescription($form->getInput('description'));
363  $consumer->setPrefix($form->getInput('prefix'));
364  $consumer->setLanguage($form->getInput('language'));
365  $consumer->setActive($form->getInput('active'));
366  $consumer->setRole($form->getInput('role'));
367  $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
368 
369  $this->object->saveConsumerObjectTypes(
370  $consumer->getExtConsumerId(),
371  $form->getInput('types')
372  );
373  ilUtil::sendSuccess($this->lng->txt("lti_consumer_created"), true);
374  $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
375  }
376 
377  $form->setValuesByPost();
378  $this->listConsumers();
379  return;
380  }
381 
386  protected function updateLTIConsumer()
387  {
388  global $ilCtrl;
389 
390  $this->checkPermission("write");
391 
392  $consumer_id = $_REQUEST["cid"];
393  if (!$consumer_id) {
394  $ilCtrl->redirect($this, "listConsumers");
395  }
396 
397  $ilCtrl->setParameter($this, "cid", $consumer_id);
398 
399  $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
400  $form = $this->getConsumerForm('edit');
401  if ($form->checkInput()) {
402  $consumer->setTitle($form->getInput('title'));
403  $consumer->setDescription($form->getInput('description'));
404  $consumer->setPrefix($form->getInput('prefix'));
405  $consumer->setLanguage($form->getInput('language'));
406  $consumer->setActive($form->getInput('active'));
407  $consumer->setRole($form->getInput('role'));
408  $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
409  $this->object->saveConsumerObjectTypes($consumer_id, $form->getInput('types'));
410 
411  ilUtil::sendSuccess($this->lng->txt("lti_consumer_updated"), true);
412  }
413  $this->listConsumers();
414  }
415 
420  protected function deleteLTIConsumer()
421  {
422  global $ilCtrl;
423 
424  $consumer_id = $_REQUEST['cid'];
425 
426  if (!$consumer_id) {
427  $ilCtrl->redirect($this, "listConsumers");
428  }
429  $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
430  $consumer->deleteGlobalToolConsumerSettings($this->dataConnector);
431  ilUtil::sendSuccess($this->lng->txt("lti_consumer_deleted"), true);
432  $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
433  }
434 
435 
441  protected function listConsumers()
442  {
443  global $ilAccess, $ilToolbar;
444 
445  if ($this->checkPermissionBool('write')) {
446  $ilToolbar->addButton(
447  $this->lng->txt('lti_create_consumer'),
448  $this->ctrl->getLinkTarget($this, 'createconsumer')
449  );
450  if (ilObject::_getIdsForTitle("il_lti_global_role", "role", false) == false) {
451  $ilToolbar->addButton(
452  $this->lng->txt('lti_create_lti_user_role'),
453  $this->ctrl->getLinkTarget($this, 'createLtiUserRole')
454  );
455  $ilToolbar->addText($this->lng->txt('lti_user_role_info'));
456  }
457  }
458 
459  $this->tabs_gui->activateSubTab("consumers");
460 
461  include_once "Services/LTI/classes/Consumer/class.ilLTIConsumerTableGUI.php";
462  $tbl = new ilObjectConsumerTableGUI(
463  $this,
464  "listConsumers"
465  );
466  $tbl->setEditable($this->checkPermissionBool('write'));
467  $this->tpl->setContent($tbl->getHTML());
468  }
469 
474  protected function changeStatusLTIConsumer()
475  {
476  global $ilCtrl;
477 
478  $consumer_id = $_REQUEST["cid"];
479 
480  if (!$consumer_id) {
481  $ilCtrl->redirect($this, "listConsumers");
482  }
483 
484  $consumer = ilLTIToolConsumer::fromExternalConsumerId($consumer_id, $this->dataConnector);
485  if ($consumer->getActive()) {
486  $consumer->setActive(0);
487  $msg = "lti_consumer_set_inactive";
488  } else {
489  $consumer->setActive(1);
490  $msg = "lti_consumer_set_active";
491  }
492  $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
493  ilUtil::sendSuccess($this->lng->txt($msg), true);
494 
495  $GLOBALS['DIC']->ctrl()->redirect($this, 'listConsumers');
496  }
497 
501  protected function releasedObjects()
502  {
503  $GLOBALS['DIC']->tabs()->activateSubTab('releasedObjects');
504 
505  $table = new ilLTIProviderReleasedObjectsTableGUI($this, 'releasedObjects', 'ltireleases');
506  $table->init();
507  $table->parse();
508 
509  $GLOBALS['DIC']->ui()->mainTemplate()->setContent($table->getHTML());
510  }
511 }
Class ilObjRole.
editConsumer(ilPropertyFormGUI $a_form=null)
Edit consumer type $ilCtrl type $tpl.
changeStatusLTIConsumer()
Change activation status type $ilCtrl.
This class represents an option in a checkbox group.
Class ilObjLTIAdministrationGUI.
This class represents a property form user interface.
createLTIConsumer()
Create new lti consumer.
const ROOT_FOLDER_ID
Definition: constants.php:30
Class to represent an LTI Data Connector for ILIAS.
LTI provider for LTI launch.
$dataConnector
Data connector object or string.
deleteLTIConsumer()
Delete consumers type $ilCtrl.
This class represents a checkbox property in a property form.
updateLTIConsumer()
Update lti consumer settings ilCtrl $ilCtrl.
static _lookupEntry($a_lang_key, $a_mod, $a_id)
initSettingsForm(ilPropertyFormGUI $form=null)
initConsumerForm(ilPropertyFormGUI $form=null)
prepareOutput($a_show_subobjects=true)
prepare output
TableGUI class for LTI consumer listing.
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
This class represents a property in a property form.
listConsumers()
List consumers type $ilAccess type $ilToolbar.
__construct(Container $dic, ilPlugin $plugin)
const MODE_UNPROTECTED_KEEP_LOCAL_POLICIES
static _getIdsForTitle($title, $type='', $partialmatch=false)
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static fromExternalConsumerId($id, $dataConnector)
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
setRequired($a_required)
Set Required.