ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjCmiXapiGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
29{
30 const TAB_ID_INFO = 'tab_info';
31 const TAB_ID_SETTINGS = 'tab_settings';
32 const TAB_ID_STATEMENTS = 'tab_statements';
33 const TAB_ID_SCORING = 'tab_scoring';
34 const TAB_ID_LEARNING_PROGRESS = 'learning_progress';
35 const TAB_ID_METADATA = 'tab_metadata';
36 const TAB_ID_EXPORT = 'tab_export';
37 const TAB_ID_PERMISSIONS = 'perm_settings';
38
39 const CMD_INFO_SCREEN = 'infoScreen';
40 const CMD_FETCH_XAPI_STATEMENTS = 'fetchXapiStatements';
41
43
44 const NEW_OBJ_TITLE = "";
45
49 public $object;
50
55
56 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
57 {
58 global $DIC; /* @var \ILIAS\DI\Container $DIC */
59
60 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
61
62 if ($this->object instanceof ilObjCmiXapi) {
63 $this->cmixAccess = ilCmiXapiAccess::getInstance($this->object);
64 }
65
66 $DIC->language()->loadLanguageModule("cmix");
67 }
68
69 public function getType()
70 {
71 return 'cmix';
72 }
73
74 protected function initCreateForm($a_new_type)
75 {
76 global $DIC; /* @var \ILIAS\DI\Container $DIC */
77
78 $ilHelp = $DIC->help();
79 $ilHelp->setScreenIdComponent("cmix");
80 $ilHelp->setScreenId("create_object");
81
82 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
83 $form = new ilPropertyFormGUI();
84 $form->setTarget("_top");
85 $form->setFormAction($this->ctrl->getFormAction($this, "save"));
86 $form->setTitle($this->lng->txt($a_new_type . "_new"));
87
88 $form = $this->initDidacticTemplate($form);
89
90 $title = new ilHiddenInputGUI('title', 'title');
91 $title->setValue(self::NEW_OBJ_TITLE);
92 $form->addItem($title);
93
94 $type = new ilRadioGroupInputGUI('Type', 'content_type');
95 $type->setRequired(true);
96
97 $typeLearningModule = new ilRadioOption($this->lng->txt('cmix_add_cmi5_lm'), ilObjCmiXapi::CONT_TYPE_CMI5);
98 $typeLearningModule->setInfo($this->lng->txt('cmix_add_cmi5_lm_info'));
99 $type->addOption($typeLearningModule);
100
101 $typeGenericModule = new ilRadioOption($this->lng->txt('cmix_add_xapi_standard_object'), ilObjCmiXapi::CONT_TYPE_GENERIC);
102 $typeGenericModule->setInfo($this->lng->txt('cmix_add_xapi_standard_object_info'));
103 $type->addOption($typeGenericModule);
104
105 $form->addItem($type);
106
107 $item = new ilRadioGroupInputGUI($this->lng->txt('cmix_add_lrs_type'), 'lrs_type_id');
108 $item->setRequired(true);
110 foreach ($types as $type) {
111 $option = new ilRadioOption($type['title'], $type['type_id'], $type['description']);
112 $item->addOption($option);
113 }
114 #$item->setValue($this->object->typedef->getTypeId());
115 $form->addItem($item);
116
117 $source = new ilRadioGroupInputGUI($this->lng->txt('cmix_add_source'), 'source_type');
118 $source->setRequired(true);
119
120 $srcRemoteContent = new ilRadioOption($this->lng->txt('cmix_add_source_url'), 'resource');
121 $srcRemoteContent->setInfo($this->lng->txt('cmix_add_source_url_info'));
122 $source->addOption($srcRemoteContent);
123
124 $srcUploadContent = new ilRadioOption($this->lng->txt('cmix_add_source_local_dir'), 'upload');
125 $srcUploadContent->setInfo($this->lng->txt('cmix_add_source_local_dir_info'));
126 $source->addOption($srcUploadContent);
127
128 $srcUpload = new ilFileInputGUI($this->lng->txt("select_file"), "uploadfile");
129 $srcUpload->setAllowDeletion(false);
130 $srcUpload->setSuffixes(['zip', 'xml']);
131 $srcUpload->setRequired(true);
132 $srcUploadContent->addSubItem($srcUpload);
133
135 $srcServerContent = new ilRadioOption($this->lng->txt('cmix_add_source_upload_dir'), 'server');
136 $srcServerContent->setInfo($this->lng->txt('cmix_add_source_upload_dir_info'));
137 $source->addOption($srcServerContent);
138
139 $options = ['' => $this->lng->txt('cmix_add_source_upload_select')];
140
141 foreach (ilUploadFiles::_getUploadFiles() as $file) {
142 $options[$file] = $file;
143 }
144
145 $srcSelect = new ilSelectInputGUI($this->lng->txt("select_file"), "serverfile");
146 $srcSelect->setOptions($options);
147 $srcServerContent->addSubItem($srcSelect);
148 }
149
150 $srcExternalApp = new ilRadioOption($this->lng->txt('cmix_add_source_external_app'), 'external');
151 $srcExternalApp->setInfo($this->lng->txt('cmix_add_source_external_app_info'));
152 $source->addOption($srcExternalApp);
153
154 $form->addItem($source);
155
156 $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
157 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
158
159 return $form;
160 }
161
162 protected function afterSave(ilObject $newObject)
163 {
164 global $DIC; /* @var \ILIAS\DI\Container $DIC */
165
166 /* @var ilObjCmiXapi $newObject */
167 $form = $this->initCreateForm($newObject->getType());
168
169 if ($form->checkInput()) {
170 $newObject->setContentType($form->getInput('content_type'));
171
172 $newObject->setLrsTypeId($form->getInput('lrs_type_id'));
173 $newObject->initLrsType();
174
175 $newObject->setPrivacyIdent($newObject->getLrsType()->getPrivacyIdent());
176 $newObject->setPrivacyName($newObject->getLrsType()->getPrivacyName());
177
178 switch ($form->getInput('source_type')) {
179 case 'resource': // remote resource
180
181 $newObject->setTitle($form->getInput('title'));
182 $newObject->setSourceType(ilObjCmiXapi::SRC_TYPE_REMOTE);
183 break;
184
185 case 'upload': // upload from local client
186
187 try {
188 $uploadImporter = new ilCmiXapiContentUploadImporter($newObject);
189 $uploadImporter->importFormUpload($form->getItemByPostVar('uploadfile'));
190
191 $newObject->setSourceType(ilObjCmiXapi::SRC_TYPE_LOCAL);
193 $form->getItemByPostVar('uploadfile')->setAlert($e->getMessage());
194 ilUtil::sendFailure('something went wrong!', true);
195 $DIC->ctrl()->redirectByClass(self::class, 'create');
196 }
197
198 break;
199
200 case 'server': // from upload directory
201
203 throw new ilCmiXapiException('access denied!');
204 }
205
206 $serverFile = $form->getInput('serverfile');
207
208 if (!ilUploadFiles::_checkUploadFile($serverFile)) {
209 throw new ilCmiXapiException($DIC->language()->txt('upload_error_file_not_found'));
210 }
211
212 $uploadImporter = new ilCmiXapiContentUploadImporter($newObject);
213
214 $uploadImporter->importServerFile(implode(DIRECTORY_SEPARATOR, [
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 $DIC->ctrl()->redirectByClass(ilCmiXapiSettingsGUI::class);
234 }
235
236 throw new ilCmiXapiException('invalid creation form submit!');
237 }
238
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($a_sub_type = null, $a_sub_id = null)
259 {
260 global $DIC; /* @var \ILIAS\DI\Container $DIC */
261
262 $return = parent::initHeaderAction($a_sub_type, $a_sub_id);
263
264 if ($this->creation_mode) {
265 return $return;
266 }
267
268 $validator = new ilCertificateDownloadValidator();
269 if ($validator->isCertificateDownloadable((int) $DIC->user()->getId(), (int) $this->object->getId())) {
270 $certLink = $DIC->ctrl()->getLinkTargetByClass(
271 [ilObjCmiXapiGUI::class, ilCmiXapiSettingsGUI::class],
273 );
274
275 $DIC->language()->loadLanguageModule('certificate');
276
277 $return->addCustomCommand($certLink, 'download_certificate');
278
279 $return->addHeaderIcon(
280 'cert_icon',
281 ilUtil::getImagePath('icon_cert.svg'),
282 $DIC->language()->txt('download_certificate'),
283 null,
284 null,
285 $certLink
286 );
287 }
288
289 return $return;
290 }
291
292 public static function _goto($a_target)
293 {
294 global $DIC; /* @var \ILIAS\DI\Container $DIC */
295 $err = $DIC['ilErr']; /* @var ilErrorHandling $err */
296 $ctrl = $DIC->ctrl();
297 $request = $DIC->http()->request();
298 $access = $DIC->access();
299 $lng = $DIC->language();
300
301 $targetParameters = explode('_', $a_target);
302 $id = (int) $targetParameters[0];
303
304 if ($id <= 0) {
305 $err->raiseError($lng->txt('msg_no_perm_read'), $err->FATAL);
306 }
307
308 if ($access->checkAccess('read', '', $id)) {
309 $ctrl->setTargetScript('ilias.php');
310 $ctrl->initBaseClass(ilRepositoryGUI::class);
311 $ctrl->setParameterByClass(ilObjCmiXapiGUI::class, 'ref_id', $id);
312 if (isset($request->getQueryParams()['gotolp'])) {
313 $ctrl->setParameterByClass(ilObjCmiXapiGUI::class, 'gotolp', 1);
314 }
315 $ctrl->redirectByClass([ilRepositoryGUI::class, ilObjCmiXapiGUI::class]);
316 } elseif ($access->checkAccess('visible', '', $id)) {
317 ilObjectGUI::_gotoRepositoryNode($id, 'infoScreen');
318 } elseif ($access->checkAccess('read', '', ROOT_FOLDER_ID)) {
320 sprintf(
321 $DIC->language()->txt('msg_no_perm_read_item'),
323 ),
324 true
325 );
326
328 }
329
330 $err->raiseError($DIC->language()->txt("msg_no_perm_read_lm"), $err->FATAL);
331 }
332
333 public function executeCommand()
334 {
335 global $DIC; /* @var \ILIAS\DI\Container $DIC */
336
337 // TODO: access checks (!)
338
339 if (!$this->creation_mode) {
340 $link = ilLink::_getLink($this->object->getRefId(), $this->object->getType());
341 $navigationHistory = $DIC['ilNavigationHistory']; /* @var ilNavigationHistory $navigationHistory */
342 $navigationHistory->addItem($this->object->getRefId(), $link, $this->object->getType());
343 $this->trackObjectReadEvent();
344 }
345
346 $this->prepareOutput();
347 $this->addHeaderAction();
348
349
350 switch ($DIC->ctrl()->getNextClass()) {
351 case strtolower(ilObjectCopyGUI::class):
352
353 $gui = new ilObjectCopyGUI($this);
354 $gui->setType($this->getType());
355 $DIC->ctrl()->forwardCommand($gui);
356
357 break;
358
359 case strtolower(ilCommonActionDispatcherGUI::class):
360
362 $this->ctrl->forwardCommand($gui);
363
364 break;
365
366 case strtolower(ilLearningProgressGUI::class):
367
368 $DIC->tabs()->activateTab(self::TAB_ID_LEARNING_PROGRESS);
369
370 $gui = new ilLearningProgressGUI(
372 $this->object->getRefId()
373 );
374
375 $DIC->ctrl()->forwardCommand($gui);
376
377 break;
378
379 case strtolower(ilObjectMetaDataGUI::class):
380
381 $DIC->tabs()->activateTab(self::TAB_ID_METADATA);
382
383 $gui = new ilObjectMetaDataGUI($this->object);
384 $DIC->ctrl()->forwardCommand($gui);
385 break;
386
387 case strtolower(ilPermissionGUI::class):
388
389 $DIC->tabs()->activateTab(self::TAB_ID_PERMISSIONS);
390
391 $gui = new ilPermissionGUI($this);
392 $DIC->ctrl()->forwardCommand($gui);
393
394 break;
395
396 case strtolower(ilCmiXapiSettingsGUI::class):
397
398 $DIC->tabs()->activateTab(self::TAB_ID_SETTINGS);
399
400 $gui = new ilCmiXapiSettingsGUI($this->object);
401 $DIC->ctrl()->forwardCommand($gui);
402
403 break;
404
405 case strtolower(ilCmiXapiStatementsGUI::class):
406
407 $DIC->tabs()->activateTab(self::TAB_ID_STATEMENTS);
408
409 $gui = new ilCmiXapiStatementsGUI($this->object);
410 $DIC->ctrl()->forwardCommand($gui);
411
412 break;
413
414 case strtolower(ilCmiXapiScoringGUI::class):
415
416 $DIC->tabs()->activateTab(self::TAB_ID_SCORING);
417
418 $gui = new ilCmiXapiScoringGUI($this->object);
419 $DIC->ctrl()->forwardCommand($gui);
420
421 break;
422
423 case strtolower(ilCmiXapiExportGUI::class):
424
425 $DIC->tabs()->activateTab(self::TAB_ID_EXPORT);
426
427 $gui = new ilCmiXapiExportGUI($this);
428 $DIC->ctrl()->forwardCommand($gui);
429
430 break;
431
432 case strtolower(ilCmiXapiRegistrationGUI::class):
433
434 $DIC->tabs()->activateTab(self::TAB_ID_INFO);
435
436 $gui = new ilCmiXapiRegistrationGUI($this->object);
437 $DIC->ctrl()->forwardCommand($gui);
438
439 break;
440
441 case strtolower(ilCmiXapiLaunchGUI::class):
442
443 $gui = new ilCmiXapiLaunchGUI($this->object);
444 $DIC->ctrl()->forwardCommand($gui);
445
446 break;
447
448 default:
449
450 $command = $DIC->ctrl()->getCmd(self::DEFAULT_CMD);
451 $this->{$command}();
452 }
453 }
454
455 protected function setTabs()
456 {
457 global $DIC; /* @var \ILIAS\DI\Container $DIC */
458
459 $DIC->help()->setScreenIdComponent("cmix");
460
461 $DIC->tabs()->addTab(
462 self::TAB_ID_INFO,
463 $DIC->language()->txt(self::TAB_ID_INFO),
464 $DIC->ctrl()->getLinkTargetByClass(self::class)
465 );
466
467 if ($this->cmixAccess->hasWriteAccess()) {
468 $DIC->tabs()->addTab(
469 self::TAB_ID_SETTINGS,
470 $DIC->language()->txt(self::TAB_ID_SETTINGS),
471 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiSettingsGUI::class)
472 );
473 }
474
475 if ($this->cmixAccess->hasStatementsAccess()) {
476 $DIC->tabs()->addTab(
477 self::TAB_ID_STATEMENTS,
478 $DIC->language()->txt(self::TAB_ID_STATEMENTS),
479 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiStatementsGUI::class)
480 );
481 }
482
483 if ($this->cmixAccess->hasHighscoreAccess()) {
484 $DIC->tabs()->addTab(
485 self::TAB_ID_SCORING,
486 $DIC->language()->txt(self::TAB_ID_SCORING),
487 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiScoringGUI::class)
488 );
489 }
490
491 if ($this->cmixAccess->hasLearningProgressAccess()) {
492 $DIC->tabs()->addTab(
493 self::TAB_ID_LEARNING_PROGRESS,
494 $DIC->language()->txt(self::TAB_ID_LEARNING_PROGRESS),
495 $DIC->ctrl()->getLinkTargetByClass(ilLearningProgressGUI::class)
496 );
497 }
498
499 if ($this->cmixAccess->hasWriteAccess()) {
500 $gui = new ilObjectMetaDataGUI($this->object);
501 $link = $gui->getTab();
502
503 if (strlen($link)) {
504 $DIC->tabs()->addTab(
505 self::TAB_ID_METADATA,
506 $DIC->language()->txt('meta_data'),
507 $link
508 );
509 }
510 }
511
512 if ($this->cmixAccess->hasWriteAccess()) {
513 $DIC->tabs()->addTab(
514 self::TAB_ID_EXPORT,
515 $DIC->language()->txt(self::TAB_ID_EXPORT),
516 $DIC->ctrl()->getLinkTargetByClass(ilCmiXapiExportGUI::class)
517 );
518 }
519
520 if ($this->cmixAccess->hasEditPermissionsAccess()) {
521 $DIC->tabs()->addTab(
522 self::TAB_ID_PERMISSIONS,
523 $DIC->language()->txt(self::TAB_ID_PERMISSIONS),
524 $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm')
525 );
526 }
527
528 if (defined('DEVMODE') && DEVMODE) {
529 $DIC->tabs()->addTab(
530 'debug',
531 'DEBUG',
532 $DIC->ctrl()->getLinkTarget($this, 'debug')
533 );
534 }
535 }
536
537 protected function debug()
538 {
539 global $DIC; /* @var \ILIAS\DI\Container $DIC */
540
541 $DIC->tabs()->activateTab('debug');
542
543 $filter = new ilCmiXapiStatementsReportFilter();
544 $filter->setActivityId($this->object->getActivityId());
545
546 $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
547 $this->object,
548 $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
549 $filter
550 );
551
553 $this->object->getLrsType()->getBasicAuth(),
554 $linkBuilder
555 );
556
557 try {
558 $report = $request->queryReport($this->object);
559
560 $DIC->ui()->mainTemplate()->setContent(
561 $report->getResponseDebug()
562 );
563 } catch (Exception $e) {
564 ilUtil::sendFailure($e->getMessage());
565 }
566 //ilUtil::sendSuccess('Object ID: '.$this->object->getId());
567 ilUtil::sendInfo($linkBuilder->getPipelineDebug());
568 ilUtil::sendQuestion('<pre>' . print_r($report->getTableData(), 1) . '</pre>');
569 }
570
571 public function addLocatorItems()
572 {
573 global $DIC; /* @var \ILIAS\DI\Container $DIC */
574
575 $locator = $DIC['ilLocator']; /* @var ilLocatorGUI $locator */
576 $locator->addItem(
577 $this->object->getTitle(),
578 $this->ctrl->getLinkTarget($this, self::DEFAULT_CMD),
579 "",
580 $_GET["ref_id"]
581 );
582 }
583
584 protected function trackObjectReadEvent()
585 {
586 global $DIC; /* @var \ILIAS\DI\Container $DIC */
587
589 $this->object->getType(),
590 $this->object->getRefId(),
591 $this->object->getId(),
592 $DIC->user()->getId()
593 );
594 }
595
596 public function infoScreen()
597 {
598 global $DIC; /* @var \ILIAS\DI\Container $DIC */
599
600 $DIC->tabs()->activateTab(self::TAB_ID_INFO);
601
602 $DIC->ctrl()->setCmd("showSummary");
603 $DIC->ctrl()->setCmdClass("ilinfoscreengui");
604 $this->infoScreenForward();
605 }
606
607 public function infoScreenForward()
608 {
609 global $DIC; /* @var \ILIAS\DI\Container $DIC */
610 $ilErr = $DIC['ilErr']; /* @var ilErrorHandling $ilErr */
611
612 if (!$this->checkPermissionBool("visible") && !$this->checkPermissionBool("read")) {
613 $ilErr->raiseError($DIC->language()->txt("msg_no_perm_read"));
614 }
615
617 $this->initInfoScreenToolbar();
618
619 $info = new ilInfoScreenGUI($this);
620
621 $info->enablePrivateNotes();
622
623 if ($this->checkPermissionBool("read")) {
624 $info->enableNews();
625 }
626
627 $info->enableNewsEditing(false);
628
629 if ($this->checkPermissionBool("write")) {
630 $news_set = new ilSetting("news");
631 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
632
633 if ($enable_internal_rss) {
634 $info->setBlockProperty("news", "settings", true);
635 $info->setBlockProperty("news", "public_notifications_option", true);
636 }
637 }
638
639 if (DEVMODE) {
640 // Development Info
641 $info->addSection('DEVMODE Info');
642 $info->addProperty('Local Object ID', $this->object->getId());
643 $info->addProperty('Current User ID', $DIC->user()->getId());
644 }
645
646 // standard meta data
647 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
648
649 // Info about privacy
650 if ($this->object->isSourceTypeExternal()) {
651 $info->addSection($DIC->language()->txt("cmix_info_privacy_section"));
652 } else {
653 $info->addSection($DIC->language()->txt("cmix_info_privacy_section_launch"));
654 }
655
656 $info->addProperty($DIC->language()->txt('cmix_lrs_type'), $this->object->getLrsType()->getTitle());
657
658 if ($this->object->isSourceTypeExternal()) {
659 $cmixUser = new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getPrivacyIdent());
660 if ($cmixUser->getUsrIdent()) {
661 $info->addProperty(
662 $DIC->language()->txt("conf_user_registered_mail"),
663 $cmixUser->getUsrIdent()
664 );
665 }
666 } else {
667 $info->addProperty(
668 $DIC->language()->txt("conf_privacy_name"),
669 $DIC->language()->txt('conf_privacy_name_' . self::getPrivacyNameString($this->object->getPrivacyName()))
670 );
671
672 $info->addProperty(
673 $DIC->language()->txt("conf_privacy_ident"),
674 $DIC->language()->txt('conf_privacy_ident_' . self::getPrivacyIdentString($this->object->getPrivacyIdent()))
675 );
676 }
677
678 if ($this->object->getLrsType()->getExternalLrs()) {
679 $info->addProperty(
680 $DIC->language()->txt("cmix_info_external_lrs_label"),
681 $DIC->language()->txt('cmix_info_external_lrs_info')
682 );
683 }
684
685 if (strlen($this->object->getLrsType()->getPrivacyCommentDefault())) {
686 $info->addProperty(
687 $DIC->language()->txt("cmix_indication_to_user"),
688 nl2br($this->object->getLrsType()->getPrivacyCommentDefault())
689 );
690 }
691
692 // FINISHED INFO SCREEN, NOW FORWARD
693
694 $this->ctrl->forwardCommand($info);
695 }
696
697 protected function initInfoScreenToolbar()
698 {
699 global $DIC; /* @var \ILIAS\DI\Container $DIC */
700
701 if (!$this->object->getOfflineStatus() && $this->object->getLrsType()->isAvailable()) {
702 // TODO : check if this is the correct query
703 // p.e. switched to another privacyIdent before: user exists but not with the new privacyIdent
704 // re_check for isSourceTypeExternal
705 //$cmixUserExists = ilCmiXapiUser::exists($this->object->getId(), $DIC->user()->getId());
706
707 if ($this->object->isSourceTypeExternal()) {
708 $extCmiUserExists = ilCmiXapiUser::exists($this->object->getId(), $DIC->user()->getId());
709 $registerButton = ilLinkButton::getInstance();
710
711 if ($extCmiUserExists) {
712 $registerButton->setCaption('change_registration');
713 } else {
714 $registerButton->setPrimary(true);
715 $registerButton->setCaption('create_registration');
716 }
717
718 $registerButton->setUrl($DIC->ctrl()->getLinkTargetByClass(
719 ilCmiXapiRegistrationGUI::class
720 ));
721
722 $DIC->toolbar()->addButtonInstance($registerButton);
723 } else {
724 $launchButton = ilLinkButton::getInstance();
725 $launchButton->setPrimary(true);
726 $launchButton->setCaption('launch');
727
728 if ($this->object->getLaunchMethod() == ilObjCmiXapi::LAUNCH_METHOD_NEW_WIN) {
729 $launchButton->setTarget('_blank');
730 }
731
732 $launchButton->setUrl($DIC->ctrl()->getLinkTargetByClass(
733 ilCmiXapiLaunchGUI::class
734 ));
735
736 $DIC->toolbar()->addButtonInstance($launchButton);
737 }
738
744 $cmiUserExists = ilCmiXapiUser::exists($this->object->getId(), $DIC->user()->getId(), $this->object->getPrivacyIdent());
745
746 if ($cmiUserExists) {
747 $cmixUser = new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getPrivacyIdent());
748
749 if ($this->isFetchXapiStatementsRequired($cmixUser)) {
750 $fetchButton = ilLinkButton::getInstance();
751 $fetchButton->setCaption('fetch_xapi_statements');
752
753 $fetchButton->setUrl($DIC->ctrl()->getLinkTarget(
754 $this,
755 self::CMD_FETCH_XAPI_STATEMENTS
756 ));
757
758 $DIC->toolbar()->addButtonInstance($fetchButton);
759
760 $this->sendLastFetchInfo($cmixUser);
761 }
762 }
763 }
764 }
765
766 protected function handleAvailablityMessage()
767 {
768 global $DIC; /* @var \ILIAS\DI\Container $DIC */
769
770 if ($this->object->getLrsType()->getAvailability() == ilCmiXapiLrsType::AVAILABILITY_NONE) {
771 ilUtil::sendFailure($DIC->language()->txt('cmix_lrstype_not_avail_msg'));
772 }
773 }
774
775 protected function isFetchXapiStatementsRequired(ilCmiXapiUser $cmixUser)
776 {
777 global $DIC;
778 if ($this->object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
779 return false;
780 }
781
782 if ($this->object->isBypassProxyEnabled()) {
783 return true;
784 }
785
786 if (!$cmixUser->hasProxySuccess()) {
787 return true;
788 }
789
790 return false;
791 }
792
793 protected function sendLastFetchInfo(ilCmiXapiUser $cmixUser)
794 {
795 global $DIC; /* @var \ILIAS\DI\Container $DIC */
796
797 if (!$cmixUser->getFetchUntil()->get(IL_CAL_UNIX)) {
798 $info = $DIC->language()->txt('xapi_statements_not_fetched_yet');
799 } else {
800 $info = $DIC->language()->txt('xapi_statements_last_fetch_date') . ' ' . ilDatePresentation::formatDate(
801 $cmixUser->getFetchUntil()
802 );
803 }
804
805 ilUtil::sendInfo($info);
806 }
807
808 protected function fetchXapiStatements()
809 {
810 global $DIC; /* @var \ILIAS\DI\Container $DIC */
811 $logger = ilLoggerFactory::getLogger($this->object->getType());
812
813 if ($this->object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
814 throw new ilCmiXapiException('access denied!');
815 }
816
817 $cmixUser = new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getPrivacyIdent());
818
819 $fetchedUntil = $cmixUser->getFetchUntil();
820 $now = new ilCmiXapiDateTime(time(), IL_CAL_UNIX);
821
822 $report = $this->getXapiStatementsReport($fetchedUntil, $now);
823
824 if ($report->hasStatements()) {
825 $evaluation = new ilXapiStatementEvaluation($logger, $this->object);
826 $evaluation->evaluateReport($report);
827
828 //$logger->debug('update lp for object (' . $this->object->getId() . ')');
829 //ilLPStatusWrapper::_updateStatus($this->object->getId(), $DIC->user()->getId());
830 }
831
832 $cmixUser->setFetchUntil($now);
833 $cmixUser->save();
834
835 ilUtil::sendSuccess($DIC->language()->txt('xapi_statements_fetched_successfully'), true);
836 $DIC->ctrl()->redirect($this, self::CMD_INFO_SCREEN);
837 }
838
840 {
841 $filter = $this->buildReportFilter($since, $until);
842
843 $linkBuilder = new ilCmiXapiStatementsReportLinkBuilder(
844 $this->object,
845 $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
846 $filter
847 );
848
850 $this->object->getLrsType()->getBasicAuth(),
851 $linkBuilder
852 );
853
854 return $request->queryReport($this->object);
855 }
856
857 protected function buildReportFilter(ilCmiXapiDateTime $since, ilCmiXapiDateTime $until)
858 {
859 global $DIC; /* @var \ILIAS\DI\Container $DIC */
860
861 $filter = new ilCmiXapiStatementsReportFilter();
862
863 $filter->setActor(new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId()));
864 $filter->setActivityId($this->object->getActivityId());
865
866 $filter->setStartDate($since);
867 $filter->setEndDate($until);
868
869 $start = $filter->getStartDate()->get(IL_CAL_DATETIME);
870 $end = $filter->getEndDate()->get(IL_CAL_DATETIME);
871 ilLoggerFactory::getLogger($this->object->getType())->debug("use filter from ($start) until ($end)");
872
873 return $filter;
874 }
875
876 public static function getPrivacyIdentString(int $ident)
877 {
878 switch ($ident) {
879 case 0:
880 return "il_uuid_user_id";
881 case 1:
882 return "il_uuid_ext_account";
883 case 2:
884 return "il_uuid_login";
885 case 3:
886 return "real_email";
887 case 4:
888 return "il_uuid_random";
889 case 5:
890 return "il_uuid_sha256";
891 case 6:
892 return "il_uuid_sha256url";
893 }
894 return '';
895 }
896
897 public static function getPrivacyNameString(int $ident)
898 {
899 switch ($ident) {
900 case 0:
901 return "none";
902 case 1:
903 return "firstname";
904 case 2:
905 return "lastname";
906 case 3:
907 return "fullname";
908 }
909 return '';
910 }
911}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
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( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
static getInstance(ilObjCmiXapi $object)
static getTypesData($a_extended=false, $a_availability=null)
Get basic data array of all types (without field definitions)
static exists($objId, $usrId, $privacyIdent=999)
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
This class represents a file property in a property form.
This class represents a hidden form property in a property form.
Class ilInfoScreenGUI.
Class ilObjUserTrackingGUI.
static getInstance()
Factory.
static getLogger($a_component_id)
Get component logger.
sendLastFetchInfo(ilCmiXapiUser $cmixUser)
isFetchXapiStatementsRequired(ilCmiXapiUser $cmixUser)
initCreateForm($a_new_type)
Init object creation form.
setTabs()
create tabs (repository/workspace switch)
static getPrivacyNameString(int $ident)
addLocatorItems()
Functions to be overwritten.
executeCommand()
execute command
afterSave(ilObject $newObject)
Post (successful) object creation hook.
getType()
Functions that must be overwritten.
initHeaderAction($a_sub_type=null, $a_sub_id=null)
Add header action menu.
static getPrivacyIdentString(int $ident)
getXapiStatementsReport(ilCmiXapiDateTime $since, ilCmiXapiDateTime $until)
initMetadata(ilObjCmiXapi $object)
static _goto($a_target)
buildReportFilter(ilCmiXapiDateTime $since, ilCmiXapiDateTime $until)
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Constructor.
New implementation of ilObjectGUI.
prepareOutput($a_show_subobjects=true)
prepare output
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_node_id=null)
Check permission.
GUI class for the workflow of copying objects.
static _gotoRepositoryNode($a_ref_id, $a_cmd="frameset")
Goto repository root.
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
initDidacticTemplate(ilPropertyFormGUI $form)
Show didactic template types.
addHeaderAction()
Add header action menu.
Class ilObjectMetaDataGUI.
Class ilObject Basic functions for all objects.
getType()
get object type @access public
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
setTitle($a_title)
set object title
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 class represents an option in a radio group.
This class represents a selection list property in a property form.
ILIAS Setting Class.
static _getUploadFiles()
Get a list of readable files in the upload directory.
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
static _getUploadDirectory()
Get the directory with uploaded files.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
$source
Definition: metadata.php:76
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type