ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjLTIAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
32 {
34 
35  private ?int $consumer_id = null;
36 
37  public function __construct(?array $a_data, int $a_id, bool $a_call_by_reference = true, bool $a_prepare_output = true)
38  {
39  global $DIC;
40  $DIC->language()->loadLanguageModule('lti'); //&ltis
41  $this->type = "ltis";
42  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
43  $this->dataConnector = new ilLTIDataConnector();
44 
45  if ($DIC->http()->wrapper()->query()->has("cid")) {
46  $this->consumer_id = (int) $DIC->http()->wrapper()->query()->retrieve("cid", $DIC->refinery()->kindlyTo()->int());
47  }
48  }
49 
50  public function executeCommand(): void
51  {
52  $next_class = $this->ctrl->getNextClass($this);
53  $cmd = $this->ctrl->getCmd();
54 
55  $this->prepareOutput();
56 
57  switch ($next_class) {
58  case 'ilpermissiongui':
59  $GLOBALS['ilTabs']->activateTab('perm_settings');
60  $perm_gui = new ilPermissionGUI($this);
61  $this->ctrl->forwardCommand($perm_gui);
62  break;
63 
64  case 'illticonsumeradministrationgui':
65  $this->tabs_gui->activateTab('lti_consuming');
66  $gui = new ilLTIConsumerAdministrationGUI($this->checkPermissionBool('write'));
67  $this->ctrl->forwardCommand($gui);
68  break;
69 
70  default:
71  $this->tabs_gui->activateTab('lti_providing');
72  if (!$cmd || $cmd == 'view') {
73  $cmd = 'listConsumers';
74  } elseif ($cmd == 'createconsumer') {
75  $cmd = "initConsumerForm";
76  }
77  $this->$cmd();
78  break;
79  }
80  }
81 
82  public function getType(): string
83  {
84  return "ltis";
85  }
86 
87  public function getAdminTabs(): void
88  {
89  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
90  $this->tabs_gui->addTab(
91  'lti_providing',
92  $this->lng->txt("lti_providing_tab"),
93  $this->ctrl->getLinkTarget($this, "listConsumers")
94  );
95 
96  $this->tabs_gui->addTab(
97  'lti_consuming',
98  $this->lng->txt("lti_consuming_tab"),
99  $this->ctrl->getLinkTargetByClass('ilLTIConsumerAdministrationGUI')
100  );
101 
102  if ($this->ctrl->getCmdClass() == 'ilobjltiadministrationgui') {
103  $this->addProvidingSubtabs();
104  }
105  }
106 
107  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
108  $this->tabs_gui->addTab(
109  "perm_settings",
110  $this->lng->txt("perm_settings"),
111  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
112  );
113  }
114  }
115 
116  protected function addProvidingSubtabs(): void
117  {
118  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
119  // currently no general settings.
120  // $this->tabs_gui->addTab("settings",
121  // $this->lng->txt("settings"),
122  // $this->ctrl->getLinkTarget($this, "initSettingsForm"));
123 
124  $this->tabs_gui->addSubTab(
125  "consumers",
126  $this->lng->txt("consumers"),
127  $this->ctrl->getLinkTarget($this, "listConsumers")
128  );
129  }
130  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
131  $this->tabs_gui->addSubTab(
132  "releasedObjects",
133  $this->lng->txt("lti_released_objects"),
134  $this->ctrl->getLinkTarget($this, "releasedObjects")
135  );
136  }
137  }
138 
139  protected function initSettingsForm(ilPropertyFormGUI $form = null): void
140  {
141  if (!($form instanceof ilPropertyFormGUI)) {
142  $form = $this->getSettingsForm();
143  }
144  $this->tabs_gui->activateSubTab("settings");
145  $this->tpl->setContent($form->getHTML());
146  }
147 
148 
149  protected function getSettingsForm(): \ilPropertyFormGUI
150  {
151  $form = new ilPropertyFormGUI();
152  /*
153  $form->setFormAction($this->ctrl->getFormAction($this,'saveSettingsForm'));
154  $form->setTitle($this->lng->txt("lti_settings"));
155 
156  // object types
157  $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
158 
159  $valid_obj_types = $this->object->getLTIObjectTypes();
160  foreach($valid_obj_types as $obj_type_id => $obj_name)
161  {
162  $cb_obj_types->addOption(new ilCheckboxOption($obj_name, $obj_type_id));
163  }
164  $objs_active = $this->object->getActiveObjectTypes();
165  $cb_obj_types->setValue($objs_active);
166  $form->addItem($cb_obj_types);
167 
168  // test roles
169  $roles = $this->object->getLTIRoles();
170  foreach($roles as $role_id => $role_name)
171  {
172  $options[$role_id] = $role_name;
173  }
174  $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'roles');
175  $si_roles->setOptions($options);
176  $si_roles->setValue($this->object->getCurrentRole());
177  $form->addItem($si_roles);
178 
179  $form->addCommandButton("saveSettingsForm", $this->lng->txt("save"));
180  */
181  return $form;
182  }
183 
184  /*
185  protected function saveSettingsForm()
186  {
187  global $ilCtrl;
188 
189  $this->checkPermission("write");
190 
191  $form = $this->getSettingsForm();
192  if($form->checkInput())
193  {
194  $obj_types = $form->getInput('types');
195 
196  $role = $form->getInput('role');
197 
198  $this->object->saveData($obj_types, $role);
199 
200  ilUtil::sendSuccess($this->lng->txt("settings_saved"),true);
201  }
202 
203  $form->setValuesByPost();
204  $this->initSettingsForm($form);
205  }
206  */
207 
208  // create global role LTI-User
209  protected function createLtiUserRole(): void
210  {
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. Do not rename this role.");
214  $role->create();
215  $this->rbac_admin->assignRoleToFolder($role->getId(), 8, 'y');
216  $this->rbac_admin->setProtected(8, $role->getId(), 'y');
217  $this->rbac_admin->setRolePermission($role->getId(), 'root', [3], 8);
218  $this->rbac_admin->setRolePermission($role->getId(), 'cat', [3], 8);
219  $this->rbac_admin->grantPermission($role->getId(), [3], ROOT_FOLDER_ID);
220  $role->changeExistingObjects(
223  array('cat'),
224  array()
225  );
226 
227  $this->tpl->setOnScreenMessage('success', $this->lng->txt("lti_user_role_created"), true);
228  $this->listConsumers();
229  }
230 
231 
232  // consumers
233 
234  protected function initConsumerForm(ilPropertyFormGUI $form = null): void
235  {
236  if (!($form instanceof ilPropertyFormGUI)) {
237  $form = $this->getConsumerForm();
238  }
239  $this->tpl->setContent($form->getHTML());
240  }
241 
242  protected function getConsumerForm(string $a_mode = ''): \ilPropertyFormGUI
243  {
244  $this->tabs_gui->activateSubTab("consumers");
245 
246  $form = new ilPropertyFormGUI();
247 
248  $ti_title = new ilTextInputGUI($this->lng->txt("title"), 'title');
249  $ti_title->setRequired(true);
250  $form->addItem($ti_title);
251  $ti_description = new ilTextInputGUI($this->lng->txt("description"), 'description');
252  $form->addItem($ti_description);
253  $ti_prefix = new ilTextInputGUI($this->lng->txt("prefix"), 'prefix');
254  $ti_prefix->setInfo($this->lng->txt("prefix_info"));
255  $ti_prefix->setRequired(true);
256  $form->addItem($ti_prefix);
257  #$ti_key = new ilTextInputGUI($this->lng->txt("lti_consumer_key"), 'key');
258  #$ti_key->setRequired(true);
259  #$ti_secret = new ilTextInputGUI($this->lng->txt("lti_consumer_secret"), 'secret');
260  #$ti_secret->setRequired(true);
261 
262  $languages = $this->lng->getInstalledLanguages();
263  $array_lang = [];
264  $options = [];
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  $form->addItem($si_language);
272 
273  // object types
274  $cb_obj_types = new ilCheckboxGroupInputGUI($this->lng->txt("act_lti_for_obj_type"), 'types');
275 
276  $valid_obj_types = $this->object->getLTIObjectTypes();
277  foreach ($valid_obj_types as $obj_type) {
278  $object_name = $this->lng->txt('objs_' . $obj_type);
279  $cb_obj_types->addOption(new ilCheckboxOption($object_name, $obj_type));
280  }
281  $form->addItem($cb_obj_types);
282 
283  // test roles
284  $roles = $this->object->getLTIRoles();
285  foreach ($roles as $role_id => $role_name) {
286  $options[$role_id] = $role_name;
287  }
288  $si_roles = new ilSelectInputGUI($this->lng->txt("gbl_roles_to_users"), 'role');
289  $si_roles->setOptions($options);
290  $form->addItem($si_roles);
291 
292  $cb_active = new ilCheckboxInputGUI($this->lng->txt('active'), 'active');
293  $form->addItem($cb_active);
294 
295  if ($a_mode == 'edit') {
296  $form->setFormAction($this->ctrl->getFormAction($this, 'editLTIConsumer'));
297  $form->setTitle($this->lng->txt("lti_edit_consumer"));
298  $form->addCommandButton("updateLTIConsumer", $this->lng->txt("save"));
299  } else {
300  $form->setFormAction($this->ctrl->getFormAction($this, 'createLTIConsumer'));
301  $form->setTitle($this->lng->txt("lti_create_consumer"));
302  $form->addCommandButton("createLTIConsumer", $this->lng->txt("save"));
303  $form->addCommandButton('listConsumers', $this->lng->txt('cancel'));
304  }
305 
306  return $form;
307  }
308 
313  protected function editConsumer(ilPropertyFormGUI $a_form = null): void
314  {
315  $this->ctrl->setParameter($this, "cid", $this->consumer_id);
316 
317  if (!$this->consumer_id) {
318  $this->ctrl->redirect($this, "listConsumers");
319  }
320 
321  $consumer = ilLTIPlatform::fromExternalConsumerId($this->consumer_id, $this->dataConnector);
322  if (!$a_form instanceof ilPropertyFormGUI) {
323  $a_form = $this->getConsumerForm('edit');
324  $a_form->getItemByPostVar("title")->setValue($consumer->getTitle());
325  $a_form->getItemByPostVar("description")->setValue($consumer->getDescription());
326  $a_form->getItemByPostVar("prefix")->setValue($consumer->getPrefix());
327  $a_form->getItemByPostVar("language")->setValue($consumer->getLanguage());
328  $a_form->getItemByPostVar("active")->setChecked($consumer->getActive());
329  $a_form->getItemByPostVar("role")->setValue($consumer->getRole());
330  $a_form->getItemByPostVar("types")->setValue($this->object->getActiveObjectTypes($this->consumer_id));
331  }
332  $this->tpl->setContent($a_form->getHTML());
333  }
334 
338  protected function createLTIConsumer(): void
339  {
340  $this->checkPermission("write");
341 
342  $form = $this->getConsumerForm();
343 
344  if ($form->checkInput()) {
345  // $consumer = new ilLTIExternalConsumer();
346  // $dataConnector = new ilLTIDataConnector();
347  $consumer = new ilLTIPlatform(null, $this->dataConnector);
348  $consumer->setTitle($form->getInput('title'));
349  $consumer->setDescription($form->getInput('description'));
350  $consumer->setPrefix($form->getInput('prefix'));
351  $consumer->setLanguage($form->getInput('language'));
352  $consumer->setActive((bool) $form->getInput('active'));
353  $consumer->setRole((int) $form->getInput('role'));
354  $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
355 
356  $this->object->saveConsumerObjectTypes(
357  $consumer->getExtConsumerId(),
358  $form->getInput('types')
359  );
360  $this->tpl->setOnScreenMessage('success', $this->lng->txt("lti_consumer_created"), true);
361  $this->ctrl->redirect($this, 'listConsumers');
362  }
363 
364  $form->setValuesByPost();
365  $this->listConsumers();
366  return;
367  }
368 
372  protected function updateLTIConsumer(): void
373  {
374  $this->checkPermission("write");
375 
376  if (!$this->consumer_id) {
377  $this->ctrl->redirect($this, "listConsumers");
378  }
379 
380  $this->ctrl->setParameter($this, "cid", $this->consumer_id);
381 
382  $consumer = ilLTIPlatform::fromExternalConsumerId($this->consumer_id, $this->dataConnector);
383  $form = $this->getConsumerForm('edit');
384  if ($form->checkInput()) {
385  $consumer->setTitle($form->getInput('title'));
386  $consumer->setDescription($form->getInput('description'));
387  $consumer->setPrefix($form->getInput('prefix'));
388  $consumer->setLanguage($form->getInput('language'));
389  $consumer->setActive((bool) $form->getInput('active'));
390  $consumer->setRole((int) $form->getInput('role'));
391  $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
392  $this->object->saveConsumerObjectTypes($this->consumer_id, $form->getInput('types'));
393 
394  $this->tpl->setOnScreenMessage('success', $this->lng->txt("lti_consumer_updated"), true);
395  }
396  $this->listConsumers();
397  }
398 
402  protected function deleteLTIConsumer(): void
403  {
404  $consumer_id = 0;
405  if ($this->request_wrapper->has('cid')) {
406  $consumer_id = (int) $this->request_wrapper->retrieve('cid', $this->refinery->kindlyTo()->int());
407  }
408 
409  if ($consumer_id == 0) {
410  $this->ctrl->redirect($this, "listConsumers");
411  }
412  $consumer = ilLTIPlatform::fromExternalConsumerId($consumer_id, $this->dataConnector);
413  $consumer->deleteGlobalToolConsumerSettings($this->dataConnector);
414  $this->tpl->setOnScreenMessage('success', $this->lng->txt("lti_consumer_deleted"), true);
415  $this->ctrl->redirect($this, 'listConsumers');
416  }
417 
418 
422  protected function listConsumers(): void
423  {
424  if ($this->checkPermissionBool('write')) {
425  $this->toolbar->addButton(
426  $this->lng->txt('lti_create_consumer'),
427  $this->ctrl->getLinkTarget($this, 'createconsumer')
428  );
429  if (ilObject::_getIdsForTitle("il_lti_global_role", "role", false) == []) {
430  $this->toolbar->addButton(
431  $this->lng->txt('lti_create_lti_user_role'),
432  $this->ctrl->getLinkTarget($this, 'createLtiUserRole')
433  );
434  $this->toolbar->addText($this->lng->txt('lti_user_role_info'));
435  }
436  }
437 
438  $this->tabs_gui->activateSubTab("consumers");
439  $tbl = new ilObjectConsumerTableGUI(
440  $this,
441  "listConsumers"
442  );
443  $tbl->setEditable($this->checkPermissionBool('write'));
444  $this->tpl->setContent($tbl->getHTML());
445  }
446 
450  protected function changeStatusLTIConsumer(): void
451  {
452  if (!$this->consumer_id) {
453  $this->ctrl->redirect($this, "listConsumers");
454  }
455 
456  $consumer = ilLTIPlatform::fromExternalConsumerId($this->consumer_id, $this->dataConnector);
457  if ($consumer->getActive()) {
458  $consumer->setActive(false);
459  $msg = "lti_consumer_set_inactive";
460  } else {
461  $consumer->setActive(true);
462  $msg = "lti_consumer_set_active";
463  }
464  $consumer->saveGlobalToolConsumerSettings($this->dataConnector);
465  $this->tpl->setOnScreenMessage('success', $this->lng->txt($msg), true);
466 
467  $this->ctrl->redirect($this, 'listConsumers');
468  }
469 
473  protected function releasedObjects(): void
474  {
475  $this->tabs_gui->activateSubTab('releasedObjects');
476 
477  $table = new ilLTIProviderReleasedObjectsTableGUI($this, 'releasedObjects', 'ltireleases');
478  $table->init();
479  $table->parse();
480 
481  $this->tpl->setContent($table->getHTML());
482  }
483 }
Class ilObjRole.
editConsumer(ilPropertyFormGUI $a_form=null)
Edit consumer.
changeStatusLTIConsumer()
Change activation status.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
Class ilObjLTIAdministrationGUI.
createLTIConsumer()
Create new lti consumer.
const ROOT_FOLDER_ID
Definition: constants.php:32
prepareOutput(bool $show_sub_objects=true)
__construct(?array $a_data, int $a_id, bool $a_call_by_reference=true, bool $a_prepare_output=true)
updateLTIConsumer()
Update lti consumer settings.
setOptions(array $a_options)
initSettingsForm(ilPropertyFormGUI $form=null)
initConsumerForm(ilPropertyFormGUI $form=null)
$GLOBALS["DIC"]
Definition: wac.php:30
TableGUI class for LTI consumer listing.
LTI provider for LTI launch.
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getIdsForTitle(string $title, string $type='', bool $partial_match=false)
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
__construct(Container $dic, ilPlugin $plugin)
const MODE_UNPROTECTED_KEEP_LOCAL_POLICIES
static fromExternalConsumerId(int $id, ilLTIDataConnector $dataConnector)
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)