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