ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjLTIConsumerGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
39 {
40  public const CFORM_CUSTOM_NEW = 99;
41  public const CFORM_DYNAMIC_REGISTRATION = 98; //
42 
43  public const TAB_ID_INFO = 'tab_info';
44  public const TAB_ID_CONTENT = 'tab_content';
45  public const TAB_ID_SETTINGS = 'tab_settings';
46  public const TAB_ID_STATEMENTS = 'tab_statements';
47  public const TAB_ID_SCORING = 'tab_scoring';
48  public const TAB_ID_GRADE_SYNCHRONIZATION = 'tab_grade_synchronization';
49  public const TAB_ID_METADATA = 'tab_metadata';
50  public const TAB_ID_LEARNING_PROGRESS = 'learning_progress';
51  public const TAB_ID_PERMISSIONS = 'perm_settings';
52 
53  public const DEFAULT_CMD = 'launch';
54 
55  public ?ilObject $object = null;
57 
58  public int $parent_node_id = 0; //check
59 
60  public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
61  {
62  global $DIC;
63  /* @var \ILIAS\DI\Container $DIC */
64 
65  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
66  $this->parent_node_id = $a_parent_node_id;
67  if ($this->object instanceof ilObjLTIConsumer) {
68  $this->ltiAccess = new ilLTIConsumerAccess($this->object);
69  }
70 
71  $DIC->language()->loadLanguageModule("lti");
72  $DIC->language()->loadLanguageModule("rep");
73  }
74 
75  public function getType(): string
76  {
77  return 'lti';
78  }
79 
83  protected function initCreationForms(string $a_new_type): array
84  {
85  $forms = array(
86  self::CFORM_NEW => $this->initCreateForm($a_new_type)
87  );
88 
90  $forms[self::CFORM_DYNAMIC_REGISTRATION] = $this->initDynRegForm($a_new_type);
91  $forms[self::CFORM_CUSTOM_NEW] = $this->initCustomCreateForm($a_new_type);
92  }
93 
94  //$forms[self::CFORM_IMPORT] = $this->initImportForm($a_new_type), // no import yet
95  $forms[self::CFORM_CLONE] = $this->fillCloneTemplate(null, $a_new_type);
96 
97  return $forms;
98  }
99 
100  protected function initCreateForm(string $a_new_type): \ilLTIConsumerProviderSelectionFormTableGUI
101  {
102  global $DIC;
103  /* @var \ILIAS\DI\Container $DIC */
104 
105  $form = $this->buildProviderSelectionForm($a_new_type);
106 
107  $globalProviderList = new ilLTIConsumeProviderList();
108  $globalProviderList->setAvailabilityFilter((string) ilLTIConsumeProvider::AVAILABILITY_CREATE);
109  $globalProviderList->setScopeFilter(ilLTIConsumeProviderList::SCOPE_GLOBAL);
110 
111  $userProviderList = new ilLTIConsumeProviderList();
112  $userProviderList->setAvailabilityFilter((string) ilLTIConsumeProvider::AVAILABILITY_CREATE);
113  $userProviderList->setScopeFilter(ilLTIConsumeProviderList::SCOPE_USER);
114  $userProviderList->setCreatorFilter($DIC->user()->getId());
115 
116  if ($form->getFilter('title')) {
117  $globalProviderList->setTitleFilter($form->getFilter('title'));
118  $userProviderList->setTitleFilter($form->getFilter('title'));
119  }
120 
121  if ($form->getFilter('category')) {
122  $globalProviderList->setCategoryFilter($form->getFilter('category'));
123  $userProviderList->setCategoryFilter($form->getFilter('category'));
124  }
125 
126  if ($form->getFilter('keyword')) {
127  $globalProviderList->setKeywordFilter($form->getFilter('keyword'));
128  $userProviderList->setKeywordFilter($form->getFilter('keyword'));
129  }
130 
131  if ($form->getFilter('outcome')) {
132  $globalProviderList->setHasOutcomeFilter(true);
133  $userProviderList->setHasOutcomeFilter(true);
134  }
135 
136  if ($form->getFilter('internal')) {
137  $globalProviderList->setIsExternalFilter(false);
138  $userProviderList->setIsExternalFilter(false);
139  }
140 
141  if ($form->getFilter('with_key')) {
142  $globalProviderList->setIsProviderKeyCustomizableFilter(false);
143  $userProviderList->setIsProviderKeyCustomizableFilter(false);
144  }
145 
146  $globalProviderList->load();
147  $userProviderList->load();
148 
149  $form->setData([...$globalProviderList->getTableData(), ...$userProviderList->getTableData()]);
150 
151  return $form;
152  }
153 
154  public function initDynRegForm(string $a_new_type): \ilLTIConsumeProviderFormGUI
155  {
156  global $DIC;
157  /* @var \ILIAS\DI\Container $DIC */
160  $form->initDynRegForm($this->ctrl->getFormAction($this, "cancelDynReg"));
161  $form->setTitle($DIC->language()->txt($a_new_type . '_dynamic_registration'));
162  return $form;
163  }
164 
165  public function initShowToolConfig(string $a_new_type, int $a_provider_id): \ilLTIConsumeProviderFormGUI
166  {
167  global $DIC;
168 
169  //ToDo: Error Handling
170  $provider = new ilLTIConsumeProvider($a_provider_id);
171 
173 
174  $form->initToolConfigForm($this->ctrl->getFormAction($this, "cancelDynReg"), '', '');
175 
176  $form->clearCommandButtons();
177  $form->addCommandButton("saveDynReg", $this->lng->txt('save'));
178  $form->addCommandButton("cancelDynReg", $this->lng->txt("cancel"));
179 
180  $form->setTitle($DIC->language()->txt($a_new_type . '_custom_new'));
181 
182  return $form;
183  }
184 
185  public function initCustomCreateForm(string $a_new_type): \ilLTIConsumeProviderFormGUI
186  {
187  global $DIC;
188  /* @var \ILIAS\DI\Container $DIC */
189 
191 
193 
194  $form->initForm($this->ctrl->getFormAction($this, "save"), '', '');
195 
196  $form->clearCommandButtons();
197  $form->addCommandButton("saveCustom", $this->lng->txt($a_new_type . "_add_own_provider"));
198  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
199 
200  $form->setTitle($DIC->language()->txt($a_new_type . '_custom_new'));
201 
202  return $form;
203  }
204 
206  {
208  $a_new_type,
209  $this,
210  'create',
211  'applyProviderFilter',
212  'resetProviderFilter'
213  );
214  }
215 
216  protected function applyProviderFilter(): void
217  {
218  $form = $this->buildProviderSelectionForm('');
219  $form->applyFilter();
220  $this->createObject();
221  }
222 
223  protected function resetProviderFilter(): void
224  {
225  $form = $this->buildProviderSelectionForm('');
226  $form->resetFilter();
227  $this->createObject();
228  }
229 
230  protected function createNewObject(string $newType, string $title, string $description): ilObject
231  {
232  $classname = "ilObj" . $this->obj_definition->getClassName($newType);
233 
234  $newObj = new $classname();
235  $newObj->setType($newType);
236  $newObj->setTitle($title);
237  $newObj->setDescription($description);
238  $newObj->create();
239  $this->putObjectInTree($newObj);
240  return $newObj;
241  }
242 
243  public function saveCustom(): void
244  {
246  throw new ilLtiConsumerException('permission denied!');
247  }
248 
249  global $DIC;
250  /* @var \ILIAS\DI\Container $DIC */
251 
252  $new_type = $this->getRequestValue("new_type");
253 
254  $DIC->ctrl()->setParameter($this, "new_type", $new_type);
255 
256  $DIC->language()->loadLanguageModule($new_type);
257 
258  $form = $this->initCustomCreateForm($new_type);
259 
260  if ($form->checkInput()) {
261  $DIC->ctrl()->setParameter($this, "new_type", "");
262 
263  // create object
264  $newObj = $this->createNewObject(
265  $new_type,
266  $form->getInput('title'),
267  $form->getInput('desc')
268  );
269 
270  // apply didactic template?
271  $dtpl = $this->getDidacticTemplateVar("dtpl");
272  if ($dtpl) {
273  $newObj->applyDidacticTemplate($dtpl);
274  }
275 
276  $this->afterSave($newObj);
277 
278  return;
279  }
280 
281  $form->setValuesByPost();
282 
283  $DIC->ui()->mainTemplate()->setContent($form->getHtml());
284  }
285 
286  public function addDynReg(): void
287  {
288  global $DIC;
290  throw new ilLtiConsumerException('permission denied!');
291  }
292  $new_type = $this->getRequestValue("new_type");
293 
294  $DIC->ctrl()->setParameter($this, "new_type", $new_type);
295 
296  $DIC->language()->loadLanguageModule($new_type);
297  $form = $this->initDynRegForm($new_type);
298  $error = ($this->getRequestValue('error') != null) ? $this->getRequestValue('error') : "";
299  $form->setValuesByPost();
300  if (!empty($error)) {
301  $DIC->ctrl()->setParameter($this, "new_type", "");
302  $DIC->ui()->mainTemplate()->setOnScreenMessage('failure', base64_decode($error));
303  $DIC->ui()->mainTemplate()->setContent($form->getDynRegError());
304  return;
305  }
306  if ($form->checkInput()) {
307  $DIC->ctrl()->setParameter($this, "new_type", "");
308  $DIC->ui()->mainTemplate()->setContent($form->getDynRegRequest());
309  return;
310  }
311  $DIC->ui()->mainTemplate()->setContent($form->getHTML());
312  }
313 
314  public function cancelDynReg(): void
315  {
316  global $DIC;
318  throw new ilLtiConsumerException('permission denied!');
319  }
320  $new_type = $this->getRequestValue("new_type");
321  //$provider_id = $this->getRequestValue("provider_id");
322  if (ilSession::has('lti_dynamic_registration_client_id')) {
323  $providerId = ilLTIConsumeProvider::getProviderIdFromClientId(ilSession::get('lti_dynamic_registration_client_id'));
324  if ($providerId > 0) {
325  try {
327  //ToDo: check if provider is in use? should never happen...
328  $provider->delete();
329  } catch (\ILIAS\Filesystem\Exception\IOException $e) {
330  //ToDo: error handling
331  }
332  }
333  }
334  $DIC->ctrl()->setParameterByClass(ilRepositoryGUI::class, 'new_type', $new_type);
335  $DIC->ctrl()->redirectByClass(ilRepositoryGUI::class, 'create');
336  }
337 
338  public function showToolConfig(): void
339  {
340  global $DIC;
342  throw new ilLtiConsumerException('permission denied!');
343  }
344  $new_type = $this->getRequestValue("new_type");
345  $DIC->ctrl()->setParameter($this, "new_type", $new_type);
346  $provider_id = $this->getRequestValue("provider_id");
347  $DIC->ctrl()->setParameter($this, "provider_id", $provider_id);
348  $DIC->language()->loadLanguageModule($new_type);
349  $form = $this->initShowToolConfig($new_type, (int) $provider_id);
350  $DIC->ui()->mainTemplate()->setContent($form->getHTML());
351  }
352 
353  public function saveDynReg(): void
354  {
355  global $DIC;
357  throw new ilLtiConsumerException('permission denied!');
358  }
359  $new_type = $this->getRequestValue("new_type");
360  $DIC->ctrl()->setParameter($this, "new_type", $new_type);
361  $provider_id = $this->getRequestValue("provider_id");
362  $DIC->ctrl()->setParameter($this, "provider_id", $provider_id);
363  $DIC->language()->loadLanguageModule($new_type);
364  ilSession::clear('lti_dynamic_registration_client_id');
365  ilSession::clear('lti_dynamic_registration_custom_params');
366  $form = $this->initShowToolConfig($new_type, (int) $provider_id);
367  $form->setValuesByPost();
368  if ($form->checkInput()) { // update only overridable fields
369  $provider = $form->getProvider();
370  $form->initProvider($provider);
371  $provider->update();
372  // jump to provider selection is one option:
373  // $DIC->ctrl()->redirectByClass([ilRepositoryGUI::class, ilObjLTIConsumerGUI::class],"create");
374  // direct redirection to save is onle less click (there is a switch for save | contentSelection in GUI class):
375  $DIC->ctrl()->redirectByClass([ilRepositoryGUI::class, ilObjLTIConsumerGUI::class], "save");
376  return;
377  }
378  $DIC->ui()->mainTemplate()->setContent($form->getHTML());
379  }
380 
381  public function contentSelection(string $providerId, string $newType, string $refId, ilLTIConsumeProvider $provider): void
382  {
383  global $DIC;
385  throw new ilLtiConsumerException('permission denied!');
386  }
387  $DIC->ctrl()->setParameter($this, "new_type", $newType);
388  $DIC->ctrl()->setParameter($this, "provider_id", $providerId);
389  $DIC->ctrl()->setParameter($this, "ref_id", $refId);
390 
391  $form = new ilLTIConsumeProviderFormGUI($provider);
392  $formaction = $this->ctrl->getFormAction($this, "cancelContentSelection");
393  $DIC->ui()->mainTemplate()->setContent($form->getContentSelectionFrame($formaction));
394  }
395 
396  public function contentSelectionRequest(): void
397  {
398  global $DIC;
400  throw new ilLtiConsumerException('permission denied!');
401  }
402  $new_type = $this->getRequestValue("new_type");
403  $DIC->ctrl()->setParameter($this, "new_type", $new_type);
404  $provider_id = $this->getRequestValue("provider_id");
405  $DIC->ctrl()->setParameter($this, "provider_id", $provider_id);
406  $ref_id = $this->getRequestValue("ref_id");
407  $DIC->ctrl()->setParameter($this, "ref_id", $ref_id);
408  $DIC->language()->loadLanguageModule($new_type);
409  $provider = new ilLTIConsumeProvider((int) $provider_id);
410  $redirectUrl = $DIC->ctrl()->getLinkTarget($this, 'contentSelectionRequest');
411 
412  if (!ilSession::has('lti13_login_data')) {
413  $userIdLTI = ilCmiXapiUser::getIdent($provider->getPrivacyIdent(), $DIC->user()); //was: getIdentAsId
414  //$emailPrimary = ilCmiXapiUser::getIdent($provider->getPrivacyIdent(), $DIC->user());
415  $ltiMessageHint = (string) $ref_id . ":" . CLIENT_ID . ":" . base64_encode($redirectUrl);
416  $tplLogin = new ilTemplate("tpl.lti_initial_login.html", true, true, "Modules/LTIConsumer");
417  $tplLogin->setVariable("LTI_INITIAL_LOGIN_ACTION", $provider->getInitiateLogin());
418  $tplLogin->setVariable("ISS", ilObjLTIConsumer::getIliasHttpPath());
419  $tplLogin->setVariable("TARGET_LINK_URL", $provider->getProviderUrl());
420  $tplLogin->setVariable("LOGIN_HINT", $userIdLTI);
421  $tplLogin->setVariable("LTI_MESSAGE_HINT", $ltiMessageHint);
422  $tplLogin->setVariable("CLIENT_ID", $provider->getClientId());
423  $tplLogin->setVariable("LTI_DEPLOYMENT_ID", (string) $provider->getId());
424  echo $tplLogin->get();
425  exit; //TODO: no exit
426  } else {
427  $loginData = ilSession::get('lti13_login_data');
428  // ToDo: correct Link!! replace ILIAS_HTTP_PATH
429  $data = ilObjLTIConsumer::buildContentSelectionParameters($provider, (int) $ref_id, ilObjLTIConsumer::getIliasHttpPath() . "/" . $DIC->ctrl()->getLinkTarget($this, 'contentSelectionResponse'), $loginData['nonce']);
430  $tplContentSelection = new ilTemplate("tpl.lti_jwt_autosubmit.html", true, true, "Modules/LTIConsumer");
431  $tplContentSelection->setVariable("LTI_JWT_FORM_ACTION", $provider->getContentItemUrl());
432  $tplContentSelection->setVariable("LTI_JWT_ID_TOKEN", $data['id_token']);
433  $tplContentSelection->setVariable("LTI_JWT_STATE", $loginData['state']);
434  ilSession::clear('lti13_login_data');
435  echo $tplContentSelection->get();
436  exit; //TODO: no exit
437  }
438  }
439 
440  public function contentSelectionResponse(): void
441  {
442  global $DIC;
444  throw new ilLtiConsumerException('permission denied!');
445  }
446  $new_type = $this->getRequestValue("new_type");
447  $DIC->ctrl()->setParameter($this, "new_type", $new_type);
448  $provider_id = $this->getRequestValue("provider_id");
449  $DIC->ctrl()->setParameter($this, "provider_id", $provider_id);
450  $ref_id = $this->getRequestValue("ref_id");
451  $DIC->ctrl()->setParameter($this, "ref_id", $ref_id);
452  $DIC->language()->loadLanguageModule($new_type);
453  $token = '';
454  if ($DIC->http()->wrapper()->post()->has('JWT')) {
455  $token = $DIC->http()->wrapper()->post()->retrieve('JWT', $DIC->refinery()->kindlyTo()->string());
456  }
457  if ($DIC->http()->wrapper()->post()->has('jwt')) {
458  $token = $DIC->http()->wrapper()->post()->retrieve('jwt', $DIC->refinery()->kindlyTo()->string());
459  }
460  if (!empty($token)) {
461  $provider = new ilLTIConsumeProvider((int) $provider_id);
463  } else {
464  echo "no token";
465  exit;
466  //ToDo:
467  }
468  }
469 
470  public function cancelContentSelection(): void
471  {
472  global $DIC;
474  throw new ilLtiConsumerException('permission denied!');
475  }
476  $new_type = $this->getRequestValue("new_type");
477  $DIC->ctrl()->setParameterByClass(ilRepositoryGUI::class, 'new_type', $new_type);
478  $DIC->ctrl()->redirectByClass(ilRepositoryGUI::class, 'create');
479  }
480 
482  {
483  if ($provider->getKeyType() == 'RSA_KEY') {
484  $key = $provider->getPublicKey();
485  $keys = new Firebase\JWT\Key($key, "RS256");
486  } else {
487  $jwks = file_get_contents($provider->getPublicKeyset());
488  //ToDo: Errorhandling
489  $keyset = json_decode($jwks, true);
491  }
493  //ilObjLTIConsumer::getLogger()->debug(var_export($data,TRUE));
494  $refId = $this->getRequestValue('ref_id');
495 
496  foreach ($data->{'https://purl.imsglobal.org/spec/lti-dl/claim/content_items'} as $item) {
497  $gui = new ilObjLTIConsumerGUI(0, self::REPOSITORY_NODE_ID, (int) $refId);
498  $description = "";
499  if (isset($item->description)) {
500  $description = $item->description;
501  }
502  $newObj = $gui->createNewObject('lti', $item->title, $description);
503  $dtpl = $gui->getDidacticTemplateVar("dtpl");
504  if ($dtpl) {
505  $newObj->applyDidacticTemplate($dtpl);
506  }
507 
508  $newObj->setProviderId($provider->getId());
509  $newObj->setProvider($provider);
510  // custom params
511  $customParams = [];
512  foreach ($item->{'custom'} as $key => $value) {
513  $customParams[] = $key . "=" . $value;
514  }
515  if (count($customParams) > 0) {
516  $newObj->setCustomParams(implode(";", $customParams));
517  }
518  $newObj->save();
519  $this->initMetadata($newObj);
520  }
522  $template = new ilTemplate('tpl.lti_content_selection_finished.html', true, true, 'Modules/LTIConsumer');
523  $redirect = ilObjLTIConsumer::getIliasHttpPath() . "/" . "goto.php?target=" . $type . "_" . $refId;
524  $template->setVariable("CONTENT_SELECTION_REDIRECT", $redirect);
525  echo $template->get();
526  exit;
527  }
528 
529  protected function afterSave(\ilObject $newObject): void
530  {
531  global $DIC; //check
532 
533  if ($DIC->http()->wrapper()->query()->has('provider_id')) {
534  $newObject->setProviderId((int) $DIC->http()->wrapper()->query()->retrieve('provider_id', $DIC->refinery()->kindlyTo()->int()));
535  $newObject->initProvider();
536  $newObject->save();
537 
538  $newObject->setTitle($newObject->getProvider()->getTitle());
539  $newObject->setMasteryScore($newObject->getProvider()->getMasteryScore());
540  $newObject->update();
541 
542  $this->initMetadata($newObject);
543 
544  $DIC->ctrl()->redirectByClass(ilLTIConsumerSettingsGUI::class);
545  }
546 
548  throw new ilLtiConsumerException('permission denied!');
549  }
550 
551  $form = $this->initCustomCreateForm($newObject->getType());
552 
553  if ($form->checkInput()) {
555  $form->initProvider($provider);
557  $provider->setIsGlobal(false);
558  $provider->setCreator($DIC->user()->getId());
559  $provider->save();
560 
561  $newObject->setProviderId($provider->getId());
562  $newObject->setProvider($provider);
563  $newObject->save();
564 
565  $newObject->setTitle($provider->getTitle());
566  $newObject->setMasteryScore($newObject->getProvider()->getMasteryScore());
567  $newObject->update();
568 
569  $this->initMetadata($newObject);
570 
571  $DIC->ctrl()->redirectByClass(ilObjLTIConsumerGUI::class);
572  }
573 
574  throw new ilLtiConsumerException(
575  'form validation seems to not have worked in ilObjLTIConsumer::saveCustom()!'
576  );
577  }
578 
579  public function initMetadata(\ilObject $object): void
580  {
581  $metadata = new ilMD($object->getId(), $object->getId(), $object->getType());
582 
583  $generalMetadata = $metadata->getGeneral();
584 
585  if (!$generalMetadata) {
586  $generalMetadata = $metadata->addGeneral();
587  }
588 
589  $generalMetadata->setTitle($object->getTitle());
590  $generalMetadata->save();
591 
592  $id = $generalMetadata->addIdentifier();
593  $id->setCatalog('ILIAS');
594  $id->setEntry('il__' . $object->getType() . '_' . $object->getId());
595  $id->save();
596 
597  $keywords = $object->getProvider()->getKeywordsArray();
598 
599  // language needed now
600  $ulang = $this->user->getLanguage();
601  $keywords = array($ulang => $keywords);
602 
603  ilMDKeyword::updateKeywords($generalMetadata, $keywords);
604  }
605 
610  protected function initHeaderAction(?string $a_sub_type = null, ?int $a_sub_id = null): ?\ilObjectListGUI
611  {
612  global $DIC;
613  /* @var \ILIAS\DI\Container $DIC */
614 
615  $return = parent::initHeaderAction($a_sub_type, $a_sub_id);
616 
617  if ($this->creation_mode) {
618  return $return;
619  }
620 
621  $validator = new ilCertificateDownloadValidator();
622  if ($validator->isCertificateDownloadable($DIC->user()->getId(), $this->object->getId())) {
623  $certLink = $DIC->ctrl()->getLinkTargetByClass(
624  [ilObjLTIConsumerGUI::class, ilLTIConsumerSettingsGUI::class],
626  );
627 
628  $DIC->language()->loadLanguageModule('certificate');
629 
630  $return->addCustomCommand($certLink, 'download_certificate');
631 
632  $return->addHeaderIcon(
633  'cert_icon',
634  ilUtil::getImagePath('icon_cert.svg'),
635  $DIC->language()->txt('download_certificate'),
636  null,
637  null,
638  $certLink
639  );
640  }
641 
642  return $return;
643  }
644 
645  public static function _goto(string $a_target): void
646  {
647  global $DIC;
648  $main_tpl = $DIC->ui()->mainTemplate();
649  /* @var \ILIAS\DI\Container $DIC */
650  $err = $DIC['ilErr'];
651  /* @var ilErrorHandling $err */
652  $ctrl = $DIC->ctrl();
653  $request = $DIC->http()->request();
654  $access = $DIC->access();
655  $lng = $DIC->language();
656 
657  $targetParameters = explode('_', $a_target);
658  $id = (int) $targetParameters[0];
659 
660  if ($id <= 0) {
661  $err->raiseError($lng->txt('msg_no_perm_read'), $err->FATAL);
662  }
663 
664  if ($access->checkAccess('read', '', $id)) {
665  $ctrl->setTargetScript('ilias.php');
666  $ctrl->setParameterByClass(ilObjLTIConsumerGUI::class, 'ref_id', $id);
667  $ctrl->redirectByClass([ilRepositoryGUI::class, ilObjLTIConsumerGUI::class]);
668  } elseif ($access->checkAccess('visible', '', $id)) {
669  ilObjectGUI::_gotoRepositoryNode($id, 'infoScreen');
670  } elseif ($access->checkAccess('read', '', ROOT_FOLDER_ID)) {
671  $main_tpl->setOnScreenMessage(
672  'info',
673  sprintf(
674  $DIC->language()->txt('msg_no_perm_read_item'),
676  ),
677  true
678  );
679 
681  }
682 
683  $err->raiseError($DIC->language()->txt("msg_no_perm_read_lm"), $err->FATAL);
684  }
685 
689  public function executeCommand(): void
690  {
691  global $DIC;
692  /* @var \ILIAS\DI\Container $DIC */
693 
695  $this->prepareOutput();
696  $this->addHeaderAction();
697  }
698 
699  if (!$this->creation_mode) {
700  $this->trackObjectReadEvent();
701 
702  if ($this->object->getProvider()->hasProviderIcon()) {
703  $DIC->ui()->mainTemplate()->setTitleIcon(
704  $this->object->getProvider()->getProviderIcon()->getAbsoluteFilePath(),
705  'Icon ' . $this->object->getProvider()->getTitle()
706  );
707  }
708 
709  $link = ilLink::_getLink($this->object->getRefId(), $this->object->getType());
710  $navigationHistory = $DIC['ilNavigationHistory'];
711  /* @var ilNavigationHistory $navigationHistory */
712  $navigationHistory->addItem($this->object->getRefId(), $link, $this->object->getType());
713  }
714 
716  $obj = $this->object;
717 
718  switch ($DIC->ctrl()->getNextClass()) {
719  case strtolower(ilObjectCopyGUI::class):
720 
721  $gui = new ilObjectCopyGUI($this);
722  $gui->setType($this->getType());
723  $DIC->ctrl()->forwardCommand($gui);
724  break;
725 
726  case strtolower(ilCommonActionDispatcherGUI::class):
727 
729  $DIC->ctrl()->forwardCommand($gui);
730  break;
731 
732  case strtolower(ilLearningProgressGUI::class):
733 
734  if (!$DIC->access()->checkAccess('read', '', $this->object->getRefId())) {
735  $DIC['ilErr']->raiseError($DIC->language()->txt("msg_no_perm_read"));
736  } else {
737  $DIC->tabs()->activateTab(self::TAB_ID_LEARNING_PROGRESS);
738 
739  $gui = new ilLearningProgressGUI(
741  $this->object->getRefId()
742  );
743 
744  $DIC->ctrl()->forwardCommand($gui);
745  }
746 
747  break;
748 
749  case strtolower(ilObjectMetaDataGUI::class):
750 
751  if (!$DIC->access()->checkAccess('write', '', $this->object->getRefId())) {
752  $DIC['ilErr']->raiseError($DIC->language()->txt("msg_no_perm_write"));
753  } else {
754 
755  $DIC->tabs()->activateTab(self::TAB_ID_METADATA);
756 
757  $gui = new ilObjectMetaDataGUI($obj);
758  $DIC->ctrl()->forwardCommand($gui);
759  }
760  break;
761 
762  case strtolower(ilPermissionGUI::class):
763 
764  $DIC->tabs()->activateTab(self::TAB_ID_PERMISSIONS);
765 
766  $gui = new ilPermissionGUI($this);
767  $DIC->ctrl()->forwardCommand($gui);
768  break;
769 
770  case strtolower(ilLTIConsumerSettingsGUI::class):
771 
772  if (!$DIC->access()->checkAccess('write', '', $this->object->getRefId())) {
773  $DIC['ilErr']->raiseError($DIC->language()->txt("msg_no_perm_write"));
774  } else {
775  $DIC->tabs()->activateTab(self::TAB_ID_SETTINGS);
776 
777  $gui = new ilLTIConsumerSettingsGUI($obj, $this->ltiAccess);
778  $DIC->ctrl()->forwardCommand($gui);
779  }
780  break;
781 
782  case strtolower(ilLTIConsumerXapiStatementsGUI::class):
783 
784  if (!$DIC->access()->checkAccess('read', '', $this->object->getRefId())) {
785  $DIC['ilErr']->raiseError($DIC->language()->txt("msg_no_perm_read"));
786  } else {
787 
788  $DIC->tabs()->activateTab(self::TAB_ID_STATEMENTS);
789 
790  $gui = new ilLTIConsumerXapiStatementsGUI($obj);
791  $DIC->ctrl()->forwardCommand($gui);
792  }
793 
794  break;
795 
796  case strtolower(ilLTIConsumerScoringGUI::class):
797 
798  if (!$DIC->access()->checkAccess('read', '', $this->object->getRefId())) {
799  $DIC['ilErr']->raiseError($DIC->language()->txt("msg_no_perm_read"));
800  } else {
801  $DIC->tabs()->activateTab(self::TAB_ID_SCORING);
802 
803  $gui = new ilLTIConsumerScoringGUI($obj);
804  $DIC->ctrl()->forwardCommand($gui);
805  }
806 
807  break;
808 
809  case strtolower(ilLTIConsumerGradeSynchronizationGUI::class):
810 
811  if (!$DIC->access()->checkAccess('read', '', $this->object->getRefId())) {
812  $DIC['ilErr']->raiseError($DIC->language()->txt("msg_no_perm_read"));
813  } else {
814  $DIC->tabs()->activateTab(self::TAB_ID_GRADE_SYNCHRONIZATION);
815 
816  $gui = new ilLTIConsumerGradeSynchronizationGUI($obj);
817  $DIC->ctrl()->forwardCommand($gui);
818  }
819 
820  break;
821 
822  case strtolower(ilLTIConsumerContentGUI::class):
823 
824  if (!$DIC->access()->checkAccess('read', '', $this->object->getRefId())) {
825  $DIC['ilErr']->raiseError($DIC->language()->txt("msg_no_perm_read"));
826  } else {
827  $DIC->tabs()->activateTab(self::TAB_ID_CONTENT);
828 
829  $gui = new ilLTIConsumerContentGUI($obj);
830  $DIC->ctrl()->forwardCommand($gui);
831  }
832 
833  break;
834 
835  case strtolower(ilInfoScreenGUI::class):
836 
837  $DIC->tabs()->activateTab(self::TAB_ID_INFO);
838  $this->infoScreen();
839 
840  break;
841 
842  default:
843  if ($DIC->ctrl()->getCmd() === 'save') {
844  $this->checkContentSelection();
845  } else {
846  $command = $DIC->ctrl()->getCmd(self::DEFAULT_CMD);
847  $this->{$command}();
848  }
849  }
850  }
851 
852  protected function checkContentSelection(): void
853  {
854  global $DIC;
855  $providerId = $this->getRequestValue('provider_id');
856  $newType = $this->getRequestValue('new_type');
857  $refId = $this->getRequestValue('ref_id');
858  if ($providerId !== null && $newType == 'lti' && $refId != null) {
860  // check if post variables from contentSelectionResponse
861  if ($DIC->http()->wrapper()->post()->has('JWT')) {
862  // ToDo:
863  } else {
864  if ($provider->isContentItem() && !empty($provider->getContentItemUrl())) {
865  $this->contentSelection($providerId, $newType, $refId, $provider);
866  } else {
867  $this->save();
868  }
869  }
870  } else {
871  $this->save();
872  }
873  }
874 
875  protected function setTabs(): void
876  {
877  global $DIC;
878 
879  /* @var \ILIAS\DI\Container $DIC */
880  $DIC->language()->loadLanguageModule('lti');
881 
882  if (!$this->object->getOfflineStatus() &&
883  $this->object->getProvider()->getAvailability() != ilLTIConsumeProvider::AVAILABILITY_NONE
884  ) {
885  $DIC->tabs()->addTab(
886  self::TAB_ID_CONTENT,
887  $DIC->language()->txt(self::TAB_ID_CONTENT),
888  $DIC->ctrl()->getLinkTargetByClass(ilLTIConsumerContentGUI::class)
889  );
890  }
891 
892  $DIC->tabs()->addTab(
893  self::TAB_ID_INFO,
894  $DIC->language()->txt(self::TAB_ID_INFO),
895  $this->ctrl->getLinkTargetByClass(ilInfoScreenGUI::class)
896  );
897 
898  if ($this->ltiAccess->hasWriteAccess()) {
899  $DIC->tabs()->addTab(
900  self::TAB_ID_SETTINGS,
901  $DIC->language()->txt(self::TAB_ID_SETTINGS),
902  $DIC->ctrl()->getLinkTargetByClass(ilLTIConsumerSettingsGUI::class)
903  );
904  }
905 
906  if ($this->ltiAccess->hasStatementsAccess()) {
907  $DIC->tabs()->addTab(
908  self::TAB_ID_STATEMENTS,
909  $DIC->language()->txt(self::TAB_ID_STATEMENTS),
910  $DIC->ctrl()->getLinkTargetByClass(ilLTIConsumerXapiStatementsGUI::class)
911  );
912  }
913 
914  if ($this->ltiAccess->hasHighscoreAccess()) {
915  //$DIC->language()->loadLanguageModule('lti');
916  $DIC->tabs()->addTab(
917  self::TAB_ID_SCORING,
918  $DIC->language()->txt(self::TAB_ID_SCORING),
919  $DIC->ctrl()->getLinkTargetByClass(ilLTIConsumerScoringGUI::class)
920  );
921  }
922 
923  if ($this->object->getProvider()->isGradeSynchronization()) {
924  $DIC->tabs()->addTab(
925  self::TAB_ID_GRADE_SYNCHRONIZATION,
926  $DIC->language()->txt(self::TAB_ID_GRADE_SYNCHRONIZATION),
927  $DIC->ctrl()->getLinkTargetByClass(ilLTIConsumerGradeSynchronizationGUI::class)
928  );
929  }
930 
931  if ($this->ltiAccess->hasLearningProgressAccess() && $this->object->getProvider()->getHasOutcome()) {
932  $DIC->tabs()->addTab(
933  self::TAB_ID_LEARNING_PROGRESS,
934  $DIC->language()->txt(self::TAB_ID_LEARNING_PROGRESS),
935  $DIC->ctrl()->getLinkTargetByClass(ilLearningProgressGUI::class)
936  );
937  }
938 
939  if ($this->ltiAccess->hasWriteAccess()) {
940  $gui = new ilObjectMetaDataGUI($this->object);
941  $link = $gui->getTab();
942 
943  if (strlen($link)) {
944  $DIC->tabs()->addTab(
945  self::TAB_ID_METADATA,
946  $DIC->language()->txt('meta_data'),
947  $link
948  );
949  }
950  }
951 
952  if ($this->ltiAccess->hasEditPermissionsAccess()) {
953  $DIC->tabs()->addTab(
954  self::TAB_ID_PERMISSIONS,
955  $DIC->language()->txt(self::TAB_ID_PERMISSIONS),
956  $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm')
957  );
958  }
959 
960  // if (defined('DEVMODE') && DEVMODE) {
961  // $DIC->tabs()->addTab(
962  // 'debug',
963  // 'DEBUG',
964  // $DIC->ctrl()->getLinkTarget($this, 'debug')
965  // );
966  // }
967  }
968 
969  // protected function debug(): void
970  // {
971  // global $DIC;
972  // /* @var \ILIAS\DI\Container $DIC */
973  //
974  // $DIC->tabs()->activateTab('debug');
975  //
976  // $filter = new ilCmiXapiStatementsReportFilter();
977  // $filter->setActivityId($this->object->getActivityId());
978  //
979  // $aggregateEndPointUrl = str_replace(
980  // 'data/xAPI',
981  // 'api/statements/aggregate',
982  // $this->object->getProvider()->getXapiLaunchUrl() // should be named endpoint not launch url
983  // );
984  //
985  // $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
986  // $this->object->getId(),
987  // $aggregateEndPointUrl,
988  // $filter
989  // );
990  //
991  // $basicAuth = ilCmiXapiLrsType::buildBasicAuth(
992  // $this->object->getProvider()->getXapiLaunchKey(),
993  // $this->object->getProvider()->getXapiLaunchSecret()
994  // );
995  //
996  // $request = new ilCmiXapiHighscoreReportRequest(
997  // $basicAuth,
998  // $linkBuilder
999  // );
1000  //
1001  // try {
1002  // $report = $request->queryReport($this->object->getId());
1003  //
1004  // $DIC->ui()->mainTemplate()->setContent(
1005  // $report->getResponseDebug()
1006  // );
1007  //
1008  // //ilUtil::sendSuccess('Object ID: '.$this->object->getId());
1009  // $DIC->ui()->mainTemplate()->setOnScreenMessage('info', $linkBuilder->getPipelineDebug());
1010  // $DIC->ui()->mainTemplate()->setOnScreenMessage('question', '<pre>' . print_r($report->getTableData(), true) . '</pre>');
1011  // } catch (Exception $e) {
1012  // $this->tpl->setOnScreenMessage('failure', $e->getMessage());
1013  // }
1014  // }
1015 
1016  protected function addLocatorItems(): void
1017  {
1018  global $DIC;
1019  /* @var \ILIAS\DI\Container $DIC */
1020 
1021  $locator = $DIC['ilLocator'];
1022  /* @var ilLocatorGUI $locator */
1023  $locator->addItem(
1024  $this->object->getTitle(),
1025  $this->ctrl->getLinkTarget($this, self::DEFAULT_CMD),
1026  "",
1027  $this->object->getRefId()
1028  );
1029  }
1030 
1031  protected function trackObjectReadEvent(): void
1032  {
1033  global $DIC;
1034  /* @var \ILIAS\DI\Container $DIC */
1035 
1037  $this->object->getType(),
1038  $this->object->getRefId(),
1039  $this->object->getId(),
1040  $DIC->user()->getId()
1041  );
1042 
1043  ilLPStatusWrapper::_updateStatus($this->object->getId(), $DIC->user()->getId());
1044  }
1045 
1046  protected function launch(): void
1047  {
1049  $obj = $this->object;
1050  $this->tabs_gui->activateTab(self::TAB_ID_CONTENT);
1051  $gui = new ilLTIConsumerContentGUI($obj);
1052  $this->ctrl->forwardCommand($gui);
1053  }
1054 
1055  protected function infoScreen(): void
1056  {
1057  global $DIC;
1058  /* @var \ILIAS\DI\Container $DIC */
1059 
1060  $DIC->tabs()->activateTab(self::TAB_ID_INFO);
1061 
1062  $DIC->ctrl()->setCmd("showSummary");
1063  $DIC->ctrl()->setCmdClass("ilinfoscreengui");
1064  $this->infoScreenForward();
1065  }
1066 
1067  protected function infoScreenForward(): void
1068  {
1069  global $DIC;
1070  /* @var \ILIAS\DI\Container $DIC */
1071  $ilErr = $DIC['ilErr'];
1072  /* @var ilErrorHandling $ilErr */
1073 
1074  if (!$this->checkPermissionBool("visible") && !$this->checkPermissionBool("read")) {
1075  $ilErr->raiseError($DIC->language()->txt("msg_no_perm_read"));
1076  }
1077 
1078  $this->handleAvailablityMessage();
1079 
1080  $info = new ilInfoScreenGUI($this);
1081 
1082  $info->enablePrivateNotes();
1083 
1084  if ($this->checkPermissionBool("read")) {
1085  $info->enableNews();
1086  }
1087 
1088  $info->enableNewsEditing(false);
1089 
1090  if ($this->checkPermissionBool("write")) {
1091  $news_set = new ilSetting("news");
1092  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1093 
1094  if ($enable_internal_rss) {
1095  //todo check
1096  $info->setBlockProperty("news", "settings", "true");
1097  $info->setBlockProperty("news", "public_notifications_option", "true");
1098  }
1099  }
1100 
1101  // standard meta data
1102  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
1103 
1104  if (DEVMODE) {
1105  // Development Info
1106  $info->addSection('DEVMODE Info');
1107  $info->addProperty('Local Object ID', (string) $this->object->getId());
1108  $info->addProperty('Current User ID', (string) $DIC->user()->getId());
1109  }
1110  if ($this->object->getProvider()->getHasOutcome() && ilLPObjSettings::_lookupDBMode($this->object->getId()) != 0) {
1111  $info->addSection($DIC->language()->txt("lti_info_learning_progress_section"));
1112  $info->addProperty(
1113  $DIC->language()->txt("mastery_score"),
1114  ($this->object->getMasteryScorePercent()) . ' %'
1115  );
1116  }
1117 
1118  // LTI Ressource Info about privacy
1119  $info->addSection($DIC->language()->txt("lti_info_privacy_section"));
1120 
1121  $info->addProperty(
1122  $DIC->language()->txt("lti_con_prov_url"),
1123  $this->object->getProvider()->getProviderUrl()
1124  );
1125 
1126  $info->addProperty(
1127  $DIC->language()->txt("conf_privacy_name"),
1128  $DIC->language()->txt('conf_privacy_name_' . ilObjCmiXapiGUI::getPrivacyNameString($this->object->getProvider()->getPrivacyName()))
1129  );
1130 
1131  $info->addProperty(
1132  $DIC->language()->txt("conf_privacy_ident"),
1133  $DIC->language()->txt('conf_privacy_ident_' . ilObjCmiXapiGUI::getPrivacyIdentString($this->object->getProvider()->getPrivacyIdent()))
1134  );
1135  if ($this->object->getProvider()->isExternalProvider()) {
1136  $info->addProperty(
1137  $DIC->language()->txt("lti_info_external_provider_label"),
1138  $DIC->language()->txt('lti_info_external_provider_info')
1139  );
1140  }
1141 
1142  if ($this->object->getProvider()->getUseXapi()) {
1143  $info->addProperty(
1144  $DIC->language()->txt("lti_con_prov_xapi_launch_url"),
1145  $this->object->getProvider()->getXapiLaunchUrl()
1146  );
1147  }
1148 
1149  // FINISHED INFO SCREEN, NOW FORWARD
1150  $this->ctrl->forwardCommand($info);
1151  }
1152 
1153  protected function handleAvailablityMessage(): void
1154  {
1155  global $DIC;
1156  /* @var \ILIAS\DI\Container $DIC */
1157  if ($this->object->getProvider()->getProviderUrl() == '') {
1158  $this->tpl->setOnScreenMessage('failure', $DIC->language()->txt('lti_provider_not_set_msg'));
1159  } elseif ($this->object->getProvider()->getAvailability() == ilLTIConsumeProvider::AVAILABILITY_NONE) {
1160  $this->tpl->setOnScreenMessage('failure', $DIC->language()->txt('lti_provider_not_avail_msg'));
1161  }
1162  }
1163 
1164  protected function getRequestValue(string $key): ?string
1165  {
1166  if ($this->request_wrapper->has($key)) {
1167  return $this->request_wrapper->retrieve($key, $this->refinery->kindlyTo()->string());
1168  }
1169  return null;
1170  }
1171 }
static get(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLTIConsumerAccess $ltiAccess
exit
Definition: login.php:28
Class ilInfoScreenGUI.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
ilErrorHandling $error
executeCommand()
execute command
fillCloneTemplate(?string $tpl_varname, string $type)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
New implementation of ilObjectGUI.
GUI class for the workflow of copying objects.
const ROOT_FOLDER_ID
Definition: constants.php:32
addGeneral()
Definition: class.ilMD.php:44
createNewObject(string $newType, string $title, string $description)
Class ChatMainBarProvider .
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance) ...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
initHeaderAction(?string $a_sub_type=null, ?int $a_sub_id=null)
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
static _gotoRepositoryNode(int $ref_id, string $cmd="")
contentSelection(string $providerId, string $newType, string $refId, ilLTIConsumeProvider $provider)
setParameterByClass(string $a_class, string $a_parameter, $a_value)
$refId
Definition: xapitoken.php:58
prepareOutput(bool $show_sub_objects=true)
if(empty($clientId)) $providerId
Definition: ltitoken.php:82
setTitle(string $title)
createObject()
create new object form
static buildContentSelectionParameters(ilLTIConsumeProvider $provider, int $refId, string $returnUrl, string $nonce)
putObjectInTree(ilObject $obj, int $parent_node_id=null)
Add object to tree at given position.
saveContentSelection(ilLTIConsumeProvider $provider, string $token)
static getIdent(int $userIdentMode, ilObjUser $user)
initShowToolConfig(string $a_new_type, int $a_provider_id)
$ilErr
Definition: raiseError.php:17
static getProviderIdFromClientId(string $clientId)
static getTypeByRefId(int $ref_id, bool $stop_on_error=true)
get object type by reference id
static _lookupObjId(int $ref_id)
static updateKeywords(ilMDGeneral $a_md_section, array $a_keywords)
global $DIC
Definition: feed.php:28
$provider
Definition: ltitoken.php:83
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static _lookupTitle(int $obj_id)
$keys
Definition: metadata.php:204
static getPrivacyIdentString(int $ident)
buildProviderSelectionForm(string $a_new_type)
$token
Definition: xapitoken.php:70
static getPrivacyNameString(int $ident)
initCustomCreateForm(string $a_new_type)
ServerRequestInterface $request
initCreationForms(string $a_new_type)
Validates if an active certificate is stored in the database and can be downloaded by the user...
const CLIENT_ID
Definition: constants.php:41
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
afterSave(\ilObject $newObject)
static array static decode(string $jwt, $keyOrKeyArray, stdClass &$headers=null)
Decodes a JWT string into a PHP object.
Definition: JWT.php:96
string $key
Consumer key/client ID value.
Definition: System.php:193
static has($a_var)
const const static parseKeySet(array $jwks, string $defaultAlg=null)
Parse a set of JWK keys.
Definition: JWK.php:55
static _goto(string $a_target)
static _lookupDBMode(int $a_obj_id)
$ltiMessageHint
Definition: ltiauth.php:51
initDynRegForm(string $a_new_type)
setTargetScript(string $a_target_script)
__construct(Container $dic, ilPlugin $plugin)
getGeneral()
Definition: class.ilMD.php:34
addItem(string $a_title, string $a_link, string $a_frame="", int $a_ref_id=0, ?string $type=null)
ilLocatorGUI $locator
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
addHeaderAction()
Add header action menu.
static clear(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class FlySystemFileAccessTest disabled disabled disabled.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
initCreateForm(string $a_new_type)
ilAccessHandler $access