ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjCmiXapiGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
41 {
42  public const TAB_ID_INFO = 'tab_info';
43  public const TAB_ID_SETTINGS = 'tab_settings';
44  public const TAB_ID_STATEMENTS = 'tab_statements';
45  public const TAB_ID_SCORING = 'tab_scoring';
46  public const TAB_ID_LEARNING_PROGRESS = 'learning_progress';
47  public const TAB_ID_METADATA = 'tab_metadata';
48  public const TAB_ID_EXPORT = 'tab_export';
49  public const TAB_ID_PERMISSIONS = 'perm_settings';
50 
51  public const CMD_INFO_SCREEN = 'infoScreen';
52  public const CMD_FETCH_XAPI_STATEMENTS = 'fetchXapiStatements';
53 
54  public const DEFAULT_CMD = self::CMD_INFO_SCREEN;
55 
56  public const NEW_OBJ_TITLE = "";
57 
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  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
63 
64  if ($this->object instanceof ilObjCmiXapi) {
65  $this->cmixAccess = ilCmiXapiAccess::getInstance($this->object);
66  }
67 
68  $this->lng->loadLanguageModule("cmix");
69  }
70 
71  public function getType(): string
72  {
73  return 'cmix';
74  }
75 
79  protected function initCreateForm(string $a_new_type): \ilPropertyFormGUI
80  {
81  $form = new ilPropertyFormGUI();
82  $form->setTarget("_top");
83  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
84  $form->setTitle($this->lng->txt($a_new_type . "_new"));
85 
86  $form = $this->initDidacticTemplate($form);
87 
88  $title = new ilHiddenInputGUI('title');
89  $title->setValue(self::NEW_OBJ_TITLE);
90  $form->addItem($title);
91 
92  $type = new ilRadioGroupInputGUI('Type', 'content_type');
93  $type->setRequired(true);
94 
95  $typeLearningModule = new ilRadioOption($this->lng->txt('cmix_add_cmi5_lm'), ilObjCmiXapi::CONT_TYPE_CMI5);
96  $typeLearningModule->setInfo($this->lng->txt('cmix_add_cmi5_lm_info'));
97  $type->addOption($typeLearningModule);
98 
99  $typeGenericModule = new ilRadioOption(
100  $this->lng->txt('cmix_add_xapi_standard_object'),
102  );
103  $typeGenericModule->setInfo($this->lng->txt('cmix_add_xapi_standard_object_info'));
104  $type->addOption($typeGenericModule);
105 
106  $form->addItem($type);
107 
108  $item = new ilRadioGroupInputGUI($this->lng->txt('cmix_add_lrs_type'), 'lrs_type_id');
109  $item->setRequired(true);
111  foreach ($types as $type) {
112  $option = new ilRadioOption((string) $type['title'], (string) $type['type_id'], (string) $type['description']);
113  $item->addOption($option);
114  }
115  #$item->setValue($this->object->typedef->getTypeId());
116  $form->addItem($item);
117 
118  $source = new ilRadioGroupInputGUI($this->lng->txt('cmix_add_source'), 'source_type');
119  $source->setRequired(true);
120 
121  $srcRemoteContent = new ilRadioOption($this->lng->txt('cmix_add_source_url'), 'resource');
122  $srcRemoteContent->setInfo($this->lng->txt('cmix_add_source_url_info'));
123  $source->addOption($srcRemoteContent);
124 
125  $srcUploadContent = new ilRadioOption($this->lng->txt('cmix_add_source_local_dir'), 'upload');
126  $srcUploadContent->setInfo($this->lng->txt('cmix_add_source_local_dir_info'));
127  $source->addOption($srcUploadContent);
128 
129  $srcUpload = new ilFileInputGUI($this->lng->txt("select_file"), "uploadfile");
130  $srcUpload->setAllowDeletion(false);
131  $srcUpload->setSuffixes(['zip', 'xml']);
132  $srcUpload->setRequired(true);
133  $srcUploadContent->addSubItem($srcUpload);
134 
136  $srcServerContent = new ilRadioOption($this->lng->txt('cmix_add_source_upload_dir'), 'server');
137  $srcServerContent->setInfo($this->lng->txt('cmix_add_source_upload_dir_info'));
138  $source->addOption($srcServerContent);
139 
140  $options = ['' => $this->lng->txt('cmix_add_source_upload_select')];
141 
142  foreach (ilUploadFiles::_getUploadFiles() as $file) {
143  $options[$file] = $file;
144  }
145 
146  $srcSelect = new ilSelectInputGUI($this->lng->txt("select_file"), "serverfile");
147  $srcSelect->setOptions($options);
148  $srcServerContent->addSubItem($srcSelect);
149  }
150 
151  $srcExternalApp = new ilRadioOption($this->lng->txt('cmix_add_source_external_app'), 'external');
152  $srcExternalApp->setInfo($this->lng->txt('cmix_add_source_external_app_info'));
153  $source->addOption($srcExternalApp);
154 
155  $form->addItem($source);
156 
157  $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
158  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
159 
160  return $form;
161  }
162 
163  protected function afterSave(ilObject $newObject): void
164  {
165  /* @var ilObjCmiXapi $newObject */
166  $form = $this->initCreateForm($newObject->getType());
167 
168  if ($form->checkInput()) {
169  $newObject->setContentType($form->getInput('content_type'));
170 
171  $newObject->setLrsTypeId((int) $form->getInput('lrs_type_id'));
172  $newObject->initLrsType();
173 
174  $newObject->setPrivacyIdent($newObject->getLrsType()->getPrivacyIdent());
175  $newObject->setPrivacyName($newObject->getLrsType()->getPrivacyName());
176 
177  switch ($form->getInput('source_type')) {
178  case 'resource': // remote resource
179 
180  $newObject->setTitle($form->getInput('title'));
181  $newObject->setSourceType(ilObjCmiXapi::SRC_TYPE_REMOTE);
182  break;
183 
184  case 'upload': // upload from local client
185 
186  try {
187  $uploadImporter = new ilCmiXapiContentUploadImporter($newObject);
188  $uploadImporter->importFormUpload((array) $form->getInput('uploadfile'));
189 
190  $newObject->setSourceType(ilObjCmiXapi::SRC_TYPE_LOCAL);
192  $form->getItemByPostVar('uploadfile')->setAlert($e->getMessage());
193  $this->tpl->setOnScreenMessage('failure', 'something went wrong!', true);
194  $this->ctrl->redirectByClass(self::class, 'create');
195  }
196 
197  break;
198 
199  case 'server': // from upload directory
200 
202  throw new ilCmiXapiException('access denied!');
203  }
204 
205  $serverFile = $form->getInput('serverfile');
206 
207  if (!ilUploadFiles::_checkUploadFile($serverFile)) {
208  throw new ilCmiXapiException($this->lng->txt('upload_error_file_not_found'));
209  }
210 
211  $uploadImporter = new ilCmiXapiContentUploadImporter($newObject);
212 
213  $uploadImporter->importServerFile(implode(DIRECTORY_SEPARATOR, [
215  $serverFile
216  ]));
217 
218  $newObject->setSourceType(ilObjCmiXapi::SRC_TYPE_LOCAL);
219 
220  break;
221 
222  case 'external':
223 
224  $newObject->setSourceType(ilObjCmiXapi::SRC_TYPE_EXTERNAL);
225  $newObject->setBypassProxyEnabled(true);
226  break;
227  }
228 
229  $newObject->save();
230 
231  $this->initMetadata($newObject);
232 
233  $this->ctrl->redirectByClass(ilCmiXapiSettingsGUI::class);
234  }
235 
236  throw new ilCmiXapiException('invalid creation form submit!');
237  }
238 
239  public function initMetadata(ilObjCmiXapi $object): void
240  {
241  $metadata = new ilMD($object->getId(), $object->getId(), $object->getType());
242 
243  $generalMetadata = $metadata->getGeneral();
244 
245  if (!$generalMetadata) {
246  $generalMetadata = $metadata->addGeneral();
247  }
248 
249  $generalMetadata->setTitle($object->getTitle());
250  $generalMetadata->save();
251 
252  $id = $generalMetadata->addIdentifier();
253  $id->setCatalog('ILIAS');
254  $id->setEntry('il__' . $object->getType() . '_' . $object->getId());
255  $id->save();
256  }
257 
258  protected function initHeaderAction(?string $sub_type = null, ?int $sub_id = null): ?ilObjectListGUI
259  {
260  $return = parent::initHeaderAction($sub_type, $sub_id);
261 
262  if ($this->creation_mode) {
263  return $return;
264  }
265 
266  $validator = new ilCertificateDownloadValidator();
267  if ($validator->isCertificateDownloadable((int) $this->user->getId(), $this->object->getId())) {
268  $certLink = $this->ctrl->getLinkTargetByClass(
269  [ilObjCmiXapiGUI::class, ilCmiXapiSettingsGUI::class],
271  );
272 
273  $this->lng->loadLanguageModule('certificate');
274 
275  $return->addCustomCommand($certLink, 'download_certificate');
276 
277  $return->addHeaderIcon(
278  'cert_icon',
279  ilUtil::getImagePath('standard/icon_cert.svg'),
280  $this->lng->txt('download_certificate'),
281  null,
282  null,
283  $certLink
284  );
285  }
286 
287  return $return;
288  }
289 
290  public static function _goto(string $a_target): void
291  {
292  global $DIC;
293  $main_tpl = $DIC->ui()->mainTemplate();
294  /* @var \ILIAS\DI\Container $DIC */
295  $err = $DIC['ilErr'];
296  /* @var ilErrorHandling $err */
297  $ctrl = $DIC->ctrl();
298  $request = $DIC->http()->request();
299  $access = $DIC->access();
300  $lng = $DIC->language();
301 
302  $targetParameters = explode('_', $a_target);
303  $id = (int) $targetParameters[0];
304 
305  if ($id <= 0) {
306  $err->raiseError($lng->txt('msg_no_perm_read'), $err->FATAL);
307  }
308 
309  if ($access->checkAccess('read', '', $id)) {
310  $ctrl->setTargetScript('ilias.php');
311  $ctrl->setParameterByClass(ilObjCmiXapiGUI::class, 'ref_id', $id);
312  $ctrl->redirectByClass([ilRepositoryGUI::class, ilObjCmiXapiGUI::class]);
313  } elseif ($access->checkAccess('visible', '', $id)) {
314  ilObjectGUI::_gotoRepositoryNode($id, 'infoScreen');
315  } elseif ($access->checkAccess('read', '', ROOT_FOLDER_ID)) {
316  $main_tpl->setOnScreenMessage('info', sprintf(
317  $lng->txt('msg_no_perm_read_item'),
319  ), true);
320 
322  }
323 
324  $err->raiseError($lng->txt("msg_no_perm_read_lm"), $err->FATAL);
325  }
326 
327  public function executeCommand(): void
328  {
329  global $DIC;
330  /* @var \ILIAS\DI\Container $DIC */
331 
332  // TODO: access checks (!)
333 
334  if (!$this->creation_mode) {
335  $link = ilLink::_getLink($this->object->getRefId(), $this->object->getType());
336  $navigationHistory = $DIC['ilNavigationHistory'];
337  /* @var ilNavigationHistory $navigationHistory */
338  $navigationHistory->addItem($this->object->getRefId(), $link, $this->object->getType());
339  $this->trackObjectReadEvent();
340  }
341 
342  $this->prepareOutput();
343  $this->addHeaderAction();
344 
346  $obj = $this->object;
347 
348  switch ($DIC->ctrl()->getNextClass()) {
349  case strtolower(ilObjectCopyGUI::class):
350 
351  $gui = new ilObjectCopyGUI($this);
352  $gui->setType($this->getType());
353  $DIC->ctrl()->forwardCommand($gui);
354 
355  break;
356 
357  case strtolower(ilCommonActionDispatcherGUI::class):
358 
360  $this->ctrl->forwardCommand($gui);
361 
362  break;
363 
364  case strtolower(ilLearningProgressGUI::class):
365 
366  $DIC->tabs()->activateTab(self::TAB_ID_LEARNING_PROGRESS);
367 
368  $gui = new ilLearningProgressGUI(
370  $this->object->getRefId()
371  );
372 
373  $DIC->ctrl()->forwardCommand($gui);
374 
375  break;
376 
377  case strtolower(ilObjectMetaDataGUI::class):
378 
379  $DIC->tabs()->activateTab(self::TAB_ID_METADATA);
380 
381  $gui = new ilObjectMetaDataGUI($this->object);
382  $DIC->ctrl()->forwardCommand($gui);
383  break;
384 
385  case strtolower(ilPermissionGUI::class):
386 
387  $DIC->tabs()->activateTab(self::TAB_ID_PERMISSIONS);
388 
389  $gui = new ilPermissionGUI($this);
390  $DIC->ctrl()->forwardCommand($gui);
391 
392  break;
393 
394  case strtolower(ilCmiXapiSettingsGUI::class):
395 
396  $DIC->tabs()->activateTab(self::TAB_ID_SETTINGS);
397 
398  $gui = new ilCmiXapiSettingsGUI($obj);
399  $DIC->ctrl()->forwardCommand($gui);
400 
401  break;
402 
403  case strtolower(ilCmiXapiStatementsGUI::class):
404 
405  $DIC->tabs()->activateTab(self::TAB_ID_STATEMENTS);
406 
407  $gui = new ilCmiXapiStatementsGUI($obj);
408  $DIC->ctrl()->forwardCommand($gui);
409 
410  break;
411 
412  case strtolower(ilCmiXapiScoringGUI::class):
413 
414  $DIC->tabs()->activateTab(self::TAB_ID_SCORING);
415 
416  $gui = new ilCmiXapiScoringGUI($obj);
417  $DIC->ctrl()->forwardCommand($gui);
418 
419  break;
420 
421  case strtolower(ilCmiXapiExportGUI::class):
422 
423  $DIC->tabs()->activateTab(self::TAB_ID_EXPORT);
424 
425  $gui = new ilCmiXapiExportGUI($this);
426  $DIC->ctrl()->forwardCommand($gui);
427 
428  break;
429 
430  case strtolower(ilCmiXapiRegistrationGUI::class):
431 
432  $DIC->tabs()->activateTab(self::TAB_ID_INFO);
433 
434  $gui = new ilCmiXapiRegistrationGUI($obj);
435  $DIC->ctrl()->forwardCommand($gui);
436 
437  break;
438 
439  case strtolower(ilCmiXapiLaunchGUI::class):
440 
441  $gui = new ilCmiXapiLaunchGUI($obj);
442  $DIC->ctrl()->forwardCommand($gui);
443 
444  break;
445 
446  default:
447 
448  if($DIC->ctrl()->getCmd() == "settings") {
449  $DIC->tabs()->activateTab(self::TAB_ID_SETTINGS);
450  $DIC->ctrl()->setCmd('show');
451  $gui = new ilCmiXapiSettingsGUI($obj);
452  $DIC->ctrl()->forwardCommand($gui);
453  } else {
454  $command = $DIC->ctrl()->getCmd(self::DEFAULT_CMD);
455  $this->{$command}();
456  }
457  }
458  }
459 
460  protected function setTabs(): void
461  {
462  global $DIC;
463  /* @var \ILIAS\DI\Container $DIC */
464 
465  $DIC->tabs()->addTab(
466  self::TAB_ID_INFO,
467  $DIC->language()->txt(self::TAB_ID_INFO),
468  $DIC->ctrl()->getLinkTargetByClass(self::class)
469  );
470 
471  if ($this->cmixAccess->hasWriteAccess()) {
472  $DIC->tabs()->addTab(
473  self::TAB_ID_SETTINGS,
474  $DIC->language()->txt(self::TAB_ID_SETTINGS),
475  $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiSettingsGUI::class)
476  );
477  }
478 
479  if ($this->cmixAccess->hasStatementsAccess()) {
480  $DIC->tabs()->addTab(
481  self::TAB_ID_STATEMENTS,
482  $DIC->language()->txt(self::TAB_ID_STATEMENTS),
483  $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiStatementsGUI::class)
484  );
485  }
486 
487  if ($this->cmixAccess->hasHighscoreAccess()) {
488  $DIC->tabs()->addTab(
489  self::TAB_ID_SCORING,
490  $DIC->language()->txt(self::TAB_ID_SCORING),
491  $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiScoringGUI::class)
492  );
493  }
494 
495  if ($this->cmixAccess->hasLearningProgressAccess()) {
496  $DIC->tabs()->addTab(
497  self::TAB_ID_LEARNING_PROGRESS,
498  $DIC->language()->txt(self::TAB_ID_LEARNING_PROGRESS),
499  $DIC->ctrl()->getLinkTargetByClass(ilLearningProgressGUI::class)
500  );
501  }
502 
503  if ($this->cmixAccess->hasWriteAccess()) {
504  $gui = new ilObjectMetaDataGUI($this->object);
505  $link = $gui->getTab();
506 
507  if (strlen($link)) {
508  $DIC->tabs()->addTab(
509  self::TAB_ID_METADATA,
510  $DIC->language()->txt('meta_data'),
511  $link
512  );
513  }
514  }
515 
516  if ($this->cmixAccess->hasWriteAccess()) {
517  $DIC->tabs()->addTab(
518  self::TAB_ID_EXPORT,
519  $DIC->language()->txt(self::TAB_ID_EXPORT),
520  $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiExportGUI::class)
521  );
522  }
523 
524  if ($this->cmixAccess->hasEditPermissionsAccess()) {
525  $DIC->tabs()->addTab(
526  self::TAB_ID_PERMISSIONS,
527  $DIC->language()->txt(self::TAB_ID_PERMISSIONS),
528  $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm')
529  );
530  }
531 
532  if (defined('DEVMODE') && DEVMODE) {
533  $DIC->tabs()->addTab(
534  'debug',
535  'DEBUG',
536  $DIC->ctrl()->getLinkTarget($this, 'debug')
537  );
538  }
539  }
540 
541  protected function debug(): void
542  {
543  global $DIC;
544  /* @var \ILIAS\DI\Container $DIC */
545 
546  $DIC->tabs()->activateTab('debug');
547 
548  $filter = new ilCmiXapiStatementsReportFilter();
549  $filter->setActivityId($this->object->getActivityId());
550 
551  $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
552  $this->object->getId(),
553  $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
554  $filter
555  );
556 
558  $this->object->getLrsType()->getBasicAuth(),
559  $linkBuilder
560  );
561 
562  try {
563  $report = $request->queryReport($this->object->getId());
564 
565  $DIC->ui()->mainTemplate()->setContent(
566  $report->getResponseDebug()
567  );
568  //ilUtil::sendSuccess('Object ID: '.$this->object->getId());
569  $this->tpl->setOnScreenMessage('info', $linkBuilder->getPipelineDebug());
570  $this->tpl->setOnScreenMessage('question', '<pre>' . print_r($report->getTableData(), true) . '</pre>');
571  } catch (Exception $e) {
572  $this->tpl->setOnScreenMessage('failure', $e->getMessage());
573  }
574  }
575 
576  protected function addLocatorItems(): void
577  {
578  global $DIC;
579  /* @var \ILIAS\DI\Container $DIC */
580 
581  $locator = $DIC['ilLocator'];
582  /* @var ilLocatorGUI $locator */
583  $locator->addItem(
584  $this->object->getTitle(),
585  $this->ctrl->getLinkTarget($this, self::DEFAULT_CMD),
586  "",
587  $DIC->http()->wrapper()->query()->retrieve("ref_id", $DIC->refinery()->kindlyTo()->int())
588  );
589  }
590 
591  protected function trackObjectReadEvent(): void
592  {
593  global $DIC;
594  /* @var \ILIAS\DI\Container $DIC */
595 
597  $this->object->getType(),
598  $this->object->getRefId(),
599  $this->object->getId(),
600  $DIC->user()->getId()
601  );
602  }
603 
604  public function infoScreen(): void
605  {
606  global $DIC;
607  /* @var \ILIAS\DI\Container $DIC */
608 
609  $DIC->tabs()->activateTab(self::TAB_ID_INFO);
610 
611  $DIC->ctrl()->setCmd("showSummary");
612  $DIC->ctrl()->setCmdClass("ilinfoscreengui");
613  $this->infoScreenForward();
614  }
615 
616  public function infoScreenForward(): void
617  {
618  global $DIC;
619  /* @var \ILIAS\DI\Container $DIC */
620  $ilErr = $DIC['ilErr'];
621  /* @var ilErrorHandling $ilErr */
622 
623  if (!$this->checkPermissionBool("visible") && !$this->checkPermissionBool("read")) {
624  $ilErr->raiseError($DIC->language()->txt("msg_no_perm_read"), $ilErr->MESSAGE);
625  }
626 
627  $this->handleAvailablityMessage();
628  $this->initInfoScreenToolbar();
629 
630  $info = new ilInfoScreenGUI($this);
631 
632  $info->enablePrivateNotes();
633 
634  if ($this->checkPermissionBool("read")) {
635  $info->enableNews();
636  }
637 
638  $info->enableNewsEditing(false);
639 
640  if ($this->checkPermissionBool("write")) {
641  $news_set = new ilSetting("news");
642  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
643 
644  if ($enable_internal_rss) {
645  $info->setBlockProperty("news", "settings", (string) true);
646  $info->setBlockProperty("news", "public_notifications_option", (string) true);
647  }
648  }
649 
650  if (DEVMODE) {
651  // Development Info
652  $info->addSection('DEVMODE Info');
653  $info->addProperty('Local Object ID', (string) $this->object->getId());
654  $info->addProperty('Current User ID', (string) $DIC->user()->getId());
655  }
656 
657  // standard meta data
658  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
659 
660  // Info about privacy
661  if ($this->object->isSourceTypeExternal()) {
662  $info->addSection($DIC->language()->txt("cmix_info_privacy_section"));
663  } else {
664  $info->addSection($DIC->language()->txt("cmix_info_privacy_section_launch"));
665  }
666 
667  $info->addProperty($DIC->language()->txt('cmix_lrs_type'), $this->object->getLrsType()->getTitle());
668 
669  if ($this->object->isSourceTypeExternal()) {
670  $cmixUser = new ilCmiXapiUser(
671  $this->object->getId(),
672  $DIC->user()->getId(),
673  $this->object->getPrivacyIdent()
674  );
675  if ($cmixUser->getUsrIdent()) {
676  $info->addProperty(
677  $DIC->language()->txt("conf_user_registered_mail"),
678  $cmixUser->getUsrIdent()
679  );
680  }
681  } else {
682  $info->addProperty(
683  $DIC->language()->txt("conf_privacy_name"),
684  $DIC->language()->txt('conf_privacy_name_' . self::getPrivacyNameString($this->object->getPrivacyName()))
685  );
686 
687  $info->addProperty(
688  $DIC->language()->txt("conf_privacy_ident"),
689  $DIC->language()->txt('conf_privacy_ident_' . self::getPrivacyIdentString($this->object->getPrivacyIdent()))
690  );
691  }
692 
693  if ($this->object->getLrsType()->getExternalLrs()) {
694  $info->addProperty(
695  $DIC->language()->txt("cmix_info_external_lrs_label"),
696  $DIC->language()->txt('cmix_info_external_lrs_info')
697  );
698  }
699 
700  if (strlen($this->object->getLrsType()->getPrivacyCommentDefault())) {
701  $info->addProperty(
702  $DIC->language()->txt("cmix_indication_to_user"),
703  nl2br($this->object->getLrsType()->getPrivacyCommentDefault())
704  );
705  }
706 
707  // FINISHED INFO SCREEN, NOW FORWARD
708 
709  $this->ctrl->forwardCommand($info);
710  }
711 
712  protected function initInfoScreenToolbar(): void
713  {
714  global $DIC;
715  /* @var \ILIAS\DI\Container $DIC */
716 
717  if (!$this->object->getOfflineStatus() && $this->object->getLrsType()->isAvailable() && $this->checkPermissionBool("read")) {
718  // TODO : check if this is the correct query
719  // p.e. switched to another privacyIdent before: user exists but not with the new privacyIdent
720  // re_check for isSourceTypeExternal
721  //$cmixUserExists = ilCmiXapiUser::exists($this->object->getId(), $DIC->user()->getId());
722 
723  if ($this->object->isSourceTypeExternal()) {
724  $extCmiUserExists = ilCmiXapiUser::exists($this->object->getId(), $DIC->user()->getId());
725  // $registerButton = ilLinkButton::getInstance();
726  //
727  // if ($extCmiUserExists) {
728  // $registerButton->setCaption('change_registration');
729  // } else {
730  // $registerButton->setPrimary(true);
731  // $registerButton->setCaption('create_registration');
732  // }
733  //
734  // $registerButton->setUrl($DIC->ctrl()->getLinkTargetByClass(
735  // ilCmiXapiRegistrationGUI::class
736  // ));
737  //
738  // $DIC->toolbar()->addButtonInstance($registerButton);
739 
740  if ($extCmiUserExists) {
741  $label = $this->lng->txt('change_registration');
742  } else {
743  // $registerButton->setPrimary(true);
744  $label = $this->lng->txt('create_registration');
745  }
746  $button = $DIC->ui()->factory()->button()->primary(
747  $label,
748  $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiRegistrationGUI::class)
749  );
750  $DIC->toolbar()->addComponent($button);
751  } else {
752  $launchButton = ilLinkButton::getInstance();
753  $launchButton->setPrimary(true);
754  $launchButton->setCaption('launch');
755 
756  if ($this->object->getLaunchMethod() == ilObjCmiXapi::LAUNCH_METHOD_NEW_WIN) {
757  $launchButton->setTarget('_blank');
758  }
759 
760  $launchButton->setUrl($DIC->ctrl()->getLinkTargetByClass(
761  ilCmiXapiLaunchGUI::class
762  ));
763 
764  $DIC->toolbar()->addButtonInstance($launchButton);
765 
766  //todo
767  // if ($this->object->getLaunchMethod() == ilObjCmiXapi::LAUNCH_METHOD_NEW_WIN) {
768  // setTarget('_blank');
769  // }
770  // $button = $DIC->ui()->factory()->button()->primary(
771  // $this->lng->txt('launch'),
772  // $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiLaunchGUI::class)
773  // );
774  // $DIC->toolbar()->addComponent($button);
775  }
776 
782  $cmiUserExists = ilCmiXapiUser::exists(
783  $this->object->getId(),
784  $DIC->user()->getId(),
785  $this->object->getPrivacyIdent()
786  );
787 
788  if ($cmiUserExists) {
789  $cmixUser = new ilCmiXapiUser(
790  $this->object->getId(),
791  $DIC->user()->getId(),
792  $this->object->getPrivacyIdent()
793  );
794 
795  if ($this->isFetchXapiStatementsRequired($cmixUser)) {
796  $button = $DIC->ui()->factory()->button()->primary(
797  $this->lng->txt('fetch_xapi_statements'),
798  $DIC->ctrl()->getLinkTarget(
799  $this,
800  self::CMD_FETCH_XAPI_STATEMENTS
801  )
802  );
803  $DIC->toolbar()->addComponent($button);
804  $this->sendLastFetchInfo($cmixUser);
805  }
806  }
807  }
808  }
809 
810  protected function handleAvailablityMessage(): void
811  {
812  global $DIC;
813  /* @var \ILIAS\DI\Container $DIC */
814 
815  if ($this->object->getLrsType()->getAvailability() == ilCmiXapiLrsType::AVAILABILITY_NONE) {
816  $this->tpl->setOnScreenMessage('failure', $DIC->language()->txt('cmix_lrstype_not_avail_msg'));
817  }
818  }
819 
820  protected function isFetchXapiStatementsRequired(ilCmiXapiUser $cmixUser): bool
821  {
822  global $DIC;
823  if ($this->object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
824  return false;
825  }
826 
827  if ($this->object->isBypassProxyEnabled()) {
828  return true;
829  }
830 
831  if (!$cmixUser->hasProxySuccess()) {
832  return true;
833  }
834 
835  return false;
836  }
837 
838  protected function sendLastFetchInfo(ilCmiXapiUser $cmixUser): void
839  {
840  global $DIC;
841  /* @var \ILIAS\DI\Container $DIC */
842 
843  if (!$cmixUser->getFetchUntil()->get(IL_CAL_UNIX)) {
844  $info = $DIC->language()->txt('xapi_statements_not_fetched_yet');
845  } else {
846  $info = $DIC->language()->txt('xapi_statements_last_fetch_date') . ' ' . ilDatePresentation::formatDate(
847  $cmixUser->getFetchUntil()
848  );
849  }
850 
851  $this->tpl->setOnScreenMessage('info', $info);
852  }
853 
854  protected function fetchXapiStatements(): void
855  {
856  global $DIC;
857  /* @var \ILIAS\DI\Container $DIC */
858  $logger = ilLoggerFactory::getLogger($this->object->getType());
859 
860  if ($this->object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
861  throw new ilCmiXapiException('access denied!');
862  }
863 
864  $cmixUser = new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getPrivacyIdent());
865 
866  $fetchedUntil = $cmixUser->getFetchUntil();
867  $now = new ilCmiXapiDateTime(time(), IL_CAL_UNIX);
868 
869  $report = $this->getXapiStatementsReport($fetchedUntil, $now);
870 
871  if ($report->hasStatements()) {
872  $evaluation = new ilXapiStatementEvaluation($logger, $this->object);
873  $evaluation->evaluateReport($report);
874 
875  //$logger->debug('update lp for object (' . $this->object->getId() . ')');
876  //ilLPStatusWrapper::_updateStatus($this->object->getId(), $DIC->user()->getId());
877  }
878 
879  $cmixUser->setFetchUntil($now);
880  $cmixUser->save();
881 
882  $this->tpl->setOnScreenMessage('success', $DIC->language()->txt('xapi_statements_fetched_successfully'), true);
883  $DIC->ctrl()->redirect($this, self::CMD_INFO_SCREEN);
884  }
885 
886  protected function getXapiStatementsReport(
887  ilCmiXapiDateTime $since,
888  ilCmiXapiDateTime $until
890  $filter = $this->buildReportFilter($since, $until);
891 
892  $linkBuilder = new ilCmiXapiStatementsReportLinkBuilder(
893  $this->object->getId(),
894  $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
895  $filter
896  );
897 
899  $this->object->getLrsType()->getBasicAuth(),
900  $linkBuilder
901  );
902 
903  return $request->queryReport($this->object->getId());
904  }
905 
906  protected function buildReportFilter(
907  ilCmiXapiDateTime $since,
908  ilCmiXapiDateTime $until
910  global $DIC;
911  /* @var \ILIAS\DI\Container $DIC */
912 
913  $filter = new ilCmiXapiStatementsReportFilter();
914 
915  $filter->setActor(new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId()));
916  $filter->setActivityId($this->object->getActivityId());
917 
918  $filter->setStartDate($since);
919  $filter->setEndDate($until);
920 
921  $start = $filter->getStartDate()->get(IL_CAL_DATETIME);
922  $end = $filter->getEndDate()->get(IL_CAL_DATETIME);
923  ilLoggerFactory::getLogger($this->object->getType())->debug("use filter from ($start) until ($end)");
924 
925  return $filter;
926  }
927 
928  public static function getPrivacyIdentString(int $ident): string
929  {
930  switch ($ident) {
931  case 0:
932  return "il_uuid_user_id";
933  case 1:
934  return "il_uuid_ext_account";
935  case 2:
936  return "il_uuid_login";
937  case 3:
938  return "real_email";
939  case 4:
940  return "il_uuid_random";
941  case 5:
942  return "il_uuid_sha256";
943  case 6:
944  return "il_uuid_sha256url";
945  }
946  return '';
947  }
948 
949  public static function getPrivacyNameString(int $ident): string
950  {
951  switch ($ident) {
952  case 0:
953  return "none";
954  case 1:
955  return "firstname";
956  case 2:
957  return "lastname";
958  case 3:
959  return "fullname";
960  }
961  return '';
962  }
963 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static exists(int $objId, int $usrId, int $privacyIdent=999)
static getInstance(ilObjCmiXapi $object)
Class ilInfoScreenGUI.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
const IL_CAL_DATETIME
executeCommand()
execute command
static getLogger(string $a_component_id)
Get component logger.
This class represents a selection list property in a property form.
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
afterSave(ilObject $newObject)
static _goto(string $a_target)
addGeneral()
Definition: class.ilMD.php:44
initHeaderAction(?string $sub_type=null, ?int $sub_id=null)
This class represents a file property in a property form.
setInfo(string $a_info)
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)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _gotoRepositoryNode(int $ref_id, string $cmd="")
setParameterByClass(string $a_class, string $a_parameter, $a_value)
prepareOutput(bool $show_sub_objects=true)
static _getUploadDirectory()
setTitle(string $title)
setOptions(array $a_options)
const IL_CAL_UNIX
$ilErr
Definition: raiseError.php:17
initMetadata(ilObjCmiXapi $object)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
buildReportFilter(ilCmiXapiDateTime $since, ilCmiXapiDateTime $until)
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static _lookupTitle(int $obj_id)
getXapiStatementsReport(ilCmiXapiDateTime $since, ilCmiXapiDateTime $until)
static getPrivacyIdentString(int $ident)
static getPrivacyNameString(int $ident)
ServerRequestInterface $request
initDidacticTemplate(ilPropertyFormGUI $form)
Validates if an active certificate is stored in the database and can be downloaded by the user...
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)
ilCmiXapiAccess $cmixAccess
isFetchXapiStatementsRequired(ilCmiXapiUser $cmixUser)
initCreateForm(string $a_new_type)
setRequired(bool $a_required)
setAllowDeletion(bool $a_val)
setTargetScript(string $a_target_script)
getGeneral()
Definition: class.ilMD.php:34
addItem(string $a_title, string $a_link, string $a_frame="", int $a_ref_id=0, ?string $type=null)
static _checkUploadFile(string $a_file)
ilLocatorGUI $locator
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
sendLastFetchInfo(ilCmiXapiUser $cmixUser)
static getTypesData(bool $a_extended=false, ?int $a_availability=null)
Get basic data array of all types (without field definitions)
addHeaderAction()
Add header action menu.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
ilAccessHandler $access