ILIAS  release_8 Revision v8.24
class.ilObjCmiXapiGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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
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('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)) {
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
359 $gui = ilCommonActionDispatcherGUI::getInstanceFromAjaxCall();
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 $command = $DIC->ctrl()->getCmd(self::DEFAULT_CMD);
449 $this->{$command}();
450 }
451 }
452
453 protected function launch(): void
454 {
455 global $DIC;
456 /* @var \ILIAS\DI\Container $DIC */
458 $obj = $this->object;
459
460 if ($obj->isSourceTypeExternal() || $obj->isBypassProxyEnabled()) {
461 $this->infoScreen();
462 } else {
463 $gui = new ilCmiXapiLaunchGUI($obj, $DIC->repositoryTree()->getParentId($this->getRefId()));
464 $DIC->ctrl()->forwardCommand($gui);
465 }
466 }
467
468
469 protected function setTabs(): void
470 {
471 global $DIC;
472 /* @var \ILIAS\DI\Container $DIC */
473
474 $DIC->tabs()->addTab(
475 self::TAB_ID_INFO,
476 $DIC->language()->txt(self::TAB_ID_INFO),
477 $DIC->ctrl()->getLinkTargetByClass(self::class)
478 );
479
480 if ($this->cmixAccess->hasWriteAccess()) {
481 $DIC->tabs()->addTab(
482 self::TAB_ID_SETTINGS,
483 $DIC->language()->txt(self::TAB_ID_SETTINGS),
484 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiSettingsGUI::class)
485 );
486 }
487
488 if ($this->cmixAccess->hasStatementsAccess()) {
489 $DIC->tabs()->addTab(
490 self::TAB_ID_STATEMENTS,
491 $DIC->language()->txt(self::TAB_ID_STATEMENTS),
492 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiStatementsGUI::class)
493 );
494 }
495
496 if ($this->cmixAccess->hasHighscoreAccess()) {
497 $DIC->tabs()->addTab(
498 self::TAB_ID_SCORING,
499 $DIC->language()->txt(self::TAB_ID_SCORING),
500 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiScoringGUI::class)
501 );
502 }
503
504 if ($this->cmixAccess->hasLearningProgressAccess()) {
505 $DIC->tabs()->addTab(
506 self::TAB_ID_LEARNING_PROGRESS,
507 $DIC->language()->txt(self::TAB_ID_LEARNING_PROGRESS),
508 $DIC->ctrl()->getLinkTargetByClass(ilLearningProgressGUI::class)
509 );
510 }
511
512 if ($this->cmixAccess->hasWriteAccess()) {
513 $gui = new ilObjectMetaDataGUI($this->object);
514 $link = $gui->getTab();
515
516 if (strlen($link)) {
517 $DIC->tabs()->addTab(
518 self::TAB_ID_METADATA,
519 $DIC->language()->txt('meta_data'),
520 $link
521 );
522 }
523 }
524
525 if ($this->cmixAccess->hasWriteAccess()) {
526 $DIC->tabs()->addTab(
527 self::TAB_ID_EXPORT,
528 $DIC->language()->txt(self::TAB_ID_EXPORT),
529 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiExportGUI::class)
530 );
531 }
532
533 if ($this->cmixAccess->hasEditPermissionsAccess()) {
534 $DIC->tabs()->addTab(
535 self::TAB_ID_PERMISSIONS,
536 $DIC->language()->txt(self::TAB_ID_PERMISSIONS),
537 $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm')
538 );
539 }
540
541 if (defined('DEVMODE') && DEVMODE) {
542 $DIC->tabs()->addTab(
543 'debug',
544 'DEBUG',
545 $DIC->ctrl()->getLinkTarget($this, 'debug')
546 );
547 }
548 }
549
550 protected function debug(): void
551 {
552 global $DIC;
553 /* @var \ILIAS\DI\Container $DIC */
554
555 $DIC->tabs()->activateTab('debug');
556
557 $filter = new ilCmiXapiStatementsReportFilter();
558 $filter->setActivityId($this->object->getActivityId());
559
560 $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
561 $this->object->getId(),
562 $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
563 $filter
564 );
565
567 $this->object->getLrsType()->getBasicAuth(),
568 $linkBuilder
569 );
570
571 try {
572 $report = $request->queryReport($this->object->getId());
573
574 $DIC->ui()->mainTemplate()->setContent(
575 $report->getResponseDebug()
576 );
577 //ilUtil::sendSuccess('Object ID: '.$this->object->getId());
578 $this->tpl->setOnScreenMessage('info', $linkBuilder->getPipelineDebug());
579 $this->tpl->setOnScreenMessage('question', '<pre>' . print_r($report->getTableData(), true) . '</pre>');
580 } catch (Exception $e) {
581 $this->tpl->setOnScreenMessage('failure', $e->getMessage());
582 }
583 }
584
585 protected function addLocatorItems(): void
586 {
587 global $DIC;
588 /* @var \ILIAS\DI\Container $DIC */
589
590 $locator = $DIC['ilLocator'];
591 /* @var ilLocatorGUI $locator */
593 $this->object->getTitle(),
594 $this->ctrl->getLinkTarget($this, self::DEFAULT_CMD),
595 "",
596 $DIC->http()->wrapper()->query()->retrieve("ref_id", $DIC->refinery()->kindlyTo()->int())
597 );
598 }
599
600 protected function trackObjectReadEvent(): void
601 {
602 global $DIC;
603 /* @var \ILIAS\DI\Container $DIC */
604
606 $this->object->getType(),
607 $this->object->getRefId(),
608 $this->object->getId(),
609 $DIC->user()->getId()
610 );
611 }
612
613 public function infoScreen(): void
614 {
615 global $DIC;
616 /* @var \ILIAS\DI\Container $DIC */
617
618 $DIC->tabs()->activateTab(self::TAB_ID_INFO);
619
620 $DIC->ctrl()->setCmd("showSummary");
621 $DIC->ctrl()->setCmdClass("ilinfoscreengui");
622 $this->infoScreenForward();
623 }
624
625 public function infoScreenForward(): void
626 {
627 global $DIC;
628 /* @var \ILIAS\DI\Container $DIC */
629 $ilErr = $DIC['ilErr'];
630 /* @var ilErrorHandling $ilErr */
631
632 if (!$this->checkPermissionBool("visible") && !$this->checkPermissionBool("read")) {
633 $ilErr->raiseError($DIC->language()->txt("msg_no_perm_read"));
634 }
635
637 $this->initInfoScreenToolbar();
638
639 $info = new ilInfoScreenGUI($this);
640
641 $info->enablePrivateNotes();
642
643 if ($this->checkPermissionBool("read")) {
644 $info->enableNews();
645 }
646
647 $info->enableNewsEditing(false);
648
649 if ($this->checkPermissionBool("write")) {
650 $news_set = new ilSetting("news");
651 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
652
653 if ($enable_internal_rss) {
654 $info->setBlockProperty("news", "settings", (string) true);
655 $info->setBlockProperty("news", "public_notifications_option", (string) true);
656 }
657 }
658
659 if (DEVMODE) {
660 // Development Info
661 $info->addSection('DEVMODE Info');
662 $info->addProperty('Local Object ID', (string) $this->object->getId());
663 $info->addProperty('Current User ID', (string) $DIC->user()->getId());
664 }
665
666 // standard meta data
667 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
668
669 // Info about privacy
670 if ($this->object->isSourceTypeExternal()) {
671 $info->addSection($DIC->language()->txt("cmix_info_privacy_section"));
672 } else {
673 $info->addSection($DIC->language()->txt("cmix_info_privacy_section_launch"));
674 }
675
676 $info->addProperty($DIC->language()->txt('cmix_lrs_type'), $this->object->getLrsType()->getTitle());
677
678 if ($this->object->isSourceTypeExternal()) {
679 $cmixUser = new ilCmiXapiUser(
680 $this->object->getId(),
681 $DIC->user()->getId(),
682 $this->object->getPrivacyIdent()
683 );
684 if ($cmixUser->getUsrIdent()) {
685 $info->addProperty(
686 $DIC->language()->txt("conf_user_registered_mail"),
687 $cmixUser->getUsrIdent()
688 );
689 }
690 } else {
691 $info->addProperty(
692 $DIC->language()->txt("conf_privacy_name"),
693 $DIC->language()->txt('conf_privacy_name_' . self::getPrivacyNameString($this->object->getPrivacyName()))
694 );
695
696 $info->addProperty(
697 $DIC->language()->txt("conf_privacy_ident"),
698 $DIC->language()->txt('conf_privacy_ident_' . self::getPrivacyIdentString($this->object->getPrivacyIdent()))
699 );
700 }
701
702 if ($this->object->getLrsType()->getExternalLrs()) {
703 $info->addProperty(
704 $DIC->language()->txt("cmix_info_external_lrs_label"),
705 $DIC->language()->txt('cmix_info_external_lrs_info')
706 );
707 }
708
709 if (strlen($this->object->getLrsType()->getPrivacyCommentDefault())) {
710 $info->addProperty(
711 $DIC->language()->txt("cmix_indication_to_user"),
712 nl2br($this->object->getLrsType()->getPrivacyCommentDefault())
713 );
714 }
715
716 // FINISHED INFO SCREEN, NOW FORWARD
717
718 $this->ctrl->forwardCommand($info);
719 }
720
721 protected function initInfoScreenToolbar(): void
722 {
723 global $DIC;
724 /* @var \ILIAS\DI\Container $DIC */
725
726 if (!$this->object->getOfflineStatus() && $this->object->getLrsType()->isAvailable()) {
727 // TODO : check if this is the correct query
728 // p.e. switched to another privacyIdent before: user exists but not with the new privacyIdent
729 // re_check for isSourceTypeExternal
730 //$cmixUserExists = ilCmiXapiUser::exists($this->object->getId(), $DIC->user()->getId());
731
732 if ($this->object->isSourceTypeExternal()) {
733 $extCmiUserExists = ilCmiXapiUser::exists($this->object->getId(), $DIC->user()->getId());
734 $registerButton = ilLinkButton::getInstance();
735
736 if ($extCmiUserExists) {
737 $registerButton->setCaption('change_registration');
738 } else {
739 $registerButton->setPrimary(true);
740 $registerButton->setCaption('create_registration');
741 }
742
743 $registerButton->setUrl($DIC->ctrl()->getLinkTargetByClass(
744 ilCmiXapiRegistrationGUI::class
745 ));
746
747 $DIC->toolbar()->addButtonInstance($registerButton);
748 } else {
749 $launchButton = ilLinkButton::getInstance();
750 $launchButton->setPrimary(true);
751 $launchButton->setCaption('launch');
752
753 if ($this->object->getLaunchMethod() == ilObjCmiXapi::LAUNCH_METHOD_NEW_WIN) {
754 $launchButton->setTarget('_blank');
755 }
756
757 $launchButton->setUrl($DIC->ctrl()->getLinkTargetByClass(
758 ilCmiXapiLaunchGUI::class
759 ));
760
761 $DIC->toolbar()->addButtonInstance($launchButton);
762 }
763
769 $cmiUserExists = ilCmiXapiUser::exists(
770 $this->object->getId(),
771 $DIC->user()->getId(),
772 $this->object->getPrivacyIdent()
773 );
774
775 if ($cmiUserExists) {
776 $cmixUser = new ilCmiXapiUser(
777 $this->object->getId(),
778 $DIC->user()->getId(),
779 $this->object->getPrivacyIdent()
780 );
781
782 if ($this->isFetchXapiStatementsRequired($cmixUser)) {
783 $fetchButton = ilLinkButton::getInstance();
784 $fetchButton->setCaption('fetch_xapi_statements');
785
786 $fetchButton->setUrl($DIC->ctrl()->getLinkTarget(
787 $this,
788 self::CMD_FETCH_XAPI_STATEMENTS
789 ));
790
791 $DIC->toolbar()->addButtonInstance($fetchButton);
792
793 $this->sendLastFetchInfo($cmixUser);
794 }
795 }
796 }
797 }
798
799 protected function handleAvailablityMessage(): void
800 {
801 global $DIC;
802 /* @var \ILIAS\DI\Container $DIC */
803
804 if ($this->object->getLrsType()->getAvailability() == ilCmiXapiLrsType::AVAILABILITY_NONE) {
805 $this->tpl->setOnScreenMessage('failure', $DIC->language()->txt('cmix_lrstype_not_avail_msg'));
806 }
807 }
808
809 protected function isFetchXapiStatementsRequired(ilCmiXapiUser $cmixUser): bool
810 {
811 global $DIC;
812 if ($this->object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
813 return false;
814 }
815
816 if ($this->object->isBypassProxyEnabled()) {
817 return true;
818 }
819
820 if (!$cmixUser->hasProxySuccess()) {
821 return true;
822 }
823
824 return false;
825 }
826
827 protected function sendLastFetchInfo(ilCmiXapiUser $cmixUser): void
828 {
829 global $DIC;
830 /* @var \ILIAS\DI\Container $DIC */
831
832 if (!$cmixUser->getFetchUntil()->get(IL_CAL_UNIX)) {
833 $info = $DIC->language()->txt('xapi_statements_not_fetched_yet');
834 } else {
835 $info = $DIC->language()->txt('xapi_statements_last_fetch_date') . ' ' . ilDatePresentation::formatDate(
836 $cmixUser->getFetchUntil()
837 );
838 }
839
840 $this->tpl->setOnScreenMessage('info', $info);
841 }
842
843 protected function fetchXapiStatements(): void
844 {
845 global $DIC;
846 /* @var \ILIAS\DI\Container $DIC */
847 $logger = ilLoggerFactory::getLogger($this->object->getType());
848
849 if ($this->object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
850 throw new ilCmiXapiException('access denied!');
851 }
852
853 $cmixUser = new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getPrivacyIdent());
854
855 $fetchedUntil = $cmixUser->getFetchUntil();
856 $now = new ilCmiXapiDateTime(time(), IL_CAL_UNIX);
857
858 $report = $this->getXapiStatementsReport($fetchedUntil, $now);
859
860 if ($report->hasStatements()) {
861 $evaluation = new ilXapiStatementEvaluation($logger, $this->object);
862 $evaluation->evaluateReport($report);
863
864 //$logger->debug('update lp for object (' . $this->object->getId() . ')');
865 //ilLPStatusWrapper::_updateStatus($this->object->getId(), $DIC->user()->getId());
866 }
867
868 $cmixUser->setFetchUntil($now);
869 $cmixUser->save();
870
871 $this->tpl->setOnScreenMessage('success', $DIC->language()->txt('xapi_statements_fetched_successfully'), true);
872 $DIC->ctrl()->redirect($this, self::CMD_INFO_SCREEN);
873 }
874
875 protected function getXapiStatementsReport(
876 ilCmiXapiDateTime $since,
877 ilCmiXapiDateTime $until
879 $filter = $this->buildReportFilter($since, $until);
880
881 $linkBuilder = new ilCmiXapiStatementsReportLinkBuilder(
882 $this->object->getId(),
883 $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
884 $filter
885 );
886
888 $this->object->getLrsType()->getBasicAuth(),
889 $linkBuilder
890 );
891
892 return $request->queryReport($this->object->getId());
893 }
894
895 protected function buildReportFilter(
896 ilCmiXapiDateTime $since,
897 ilCmiXapiDateTime $until
899 global $DIC;
900 /* @var \ILIAS\DI\Container $DIC */
901
902 $filter = new ilCmiXapiStatementsReportFilter();
903
904 $filter->setActor(new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId()));
905 $filter->setActivityId($this->object->getActivityId());
906
907 $filter->setStartDate($since);
908 $filter->setEndDate($until);
909
910 $start = $filter->getStartDate()->get(IL_CAL_DATETIME);
911 $end = $filter->getEndDate()->get(IL_CAL_DATETIME);
912 ilLoggerFactory::getLogger($this->object->getType())->debug("use filter from ($start) until ($end)");
913
914 return $filter;
915 }
916
917 public static function getPrivacyIdentString(int $ident): string
918 {
919 switch ($ident) {
920 case 0:
921 return "il_uuid_user_id";
922 case 1:
923 return "il_uuid_ext_account";
924 case 2:
925 return "il_uuid_login";
926 case 3:
927 return "real_email";
928 case 4:
929 return "il_uuid_random";
930 case 5:
931 return "il_uuid_sha256";
932 case 6:
933 return "il_uuid_sha256url";
934 }
935 return '';
936 }
937
938 public static function getPrivacyNameString(int $ident): string
939 {
940 switch ($ident) {
941 case 0:
942 return "none";
943 case 1:
944 return "firstname";
945 case 2:
946 return "lastname";
947 case 3:
948 return "fullname";
949 }
950 return '';
951 }
952}
const IL_CAL_UNIX
const IL_CAL_DATETIME
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)
static getInstance(ilObjCmiXapi $object)
static getTypesData(bool $a_extended=false, ?int $a_availability=null)
Get basic data array of all types (without field definitions)
static exists(int $objId, int $usrId, int $privacyIdent=999)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setTargetScript(string $a_target_script)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
This class represents a file property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilInfoScreenGUI.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addItem(string $a_title, string $a_link, string $a_frame="", int $a_ref_id=0, ?string $type=null)
static getLogger(string $a_component_id)
Get component logger.
sendLastFetchInfo(ilCmiXapiUser $cmixUser)
isFetchXapiStatementsRequired(ilCmiXapiUser $cmixUser)
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
setTabs()
create tabs (repository/workspace switch)
static getPrivacyNameString(int $ident)
addLocatorItems()
Functions to be overwritten.
afterSave(ilObject $newObject)
Post (successful) object creation hook.
static _goto(string $a_target)
ilCmiXapiAccess $cmixAccess
initCreateForm(string $a_new_type)
getType()
Functions that must be overwritten.
initHeaderAction(?string $sub_type=null, ?int $sub_id=null)
Add header action menu.
static getPrivacyIdentString(int $ident)
getXapiStatementsReport(ilCmiXapiDateTime $since, ilCmiXapiDateTime $until)
initMetadata(ilObjCmiXapi $object)
buildReportFilter(ilCmiXapiDateTime $since, ilCmiXapiDateTime $until)
New implementation of ilObjectGUI.
executeCommand()
execute command
ilAccessHandler $access
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
ilLocatorGUI $locator
prepareOutput(bool $show_sub_objects=true)
GUI class for the workflow of copying objects.
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
initDidacticTemplate(ilPropertyFormGUI $form)
addHeaderAction()
Add header action menu.
static _gotoRepositoryNode(int $ref_id, string $cmd="")
ServerRequestInterface $request
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...
setTitle(string $title)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _checkUploadFile(string $a_file)
static _getUploadDirectory()
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
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)
$source
Definition: metadata.php:93
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ilErr
Definition: raiseError.php:17