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