From e74fb6009ac980f4bb8f768865784cba33e22e7a Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Thu, 30 Aug 2018 12:35:46 +0200 Subject: [PATCH 1/2] Use title from metadata object when creating xAPI stmt --- js/h5p-x-api-event.js | 6 +++--- js/h5p.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/js/h5p-x-api-event.js b/js/h5p-x-api-event.js index c1d6c66..4cec937 100644 --- a/js/h5p-x-api-event.js +++ b/js/h5p-x-api-event.js @@ -133,9 +133,10 @@ H5P.XAPIEvent.prototype.setObject = function (instance) { } } else { - if (H5PIntegration && H5PIntegration.contents && H5PIntegration.contents['cid-' + instance.contentId].title) { + var content = H5P.getContentForInstance(instance.contentId); + if (content && content.metadata && content.metadata.title) { this.data.statement.object.definition.name = { - "en-US": H5P.createTitle(H5PIntegration.contents['cid-' + instance.contentId].title) + "en-US": H5P.createTitle(content.metadata.title) }; } } @@ -150,7 +151,6 @@ H5P.XAPIEvent.prototype.setObject = function (instance) { */ H5P.XAPIEvent.prototype.setContext = function (instance) { if (instance.parent && (instance.parent.contentId || instance.parent.subContentId)) { - var parentId = instance.parent.subContentId === undefined ? instance.parent.contentId : instance.parent.subContentId; this.data.statement.context = { "contextActivities": { "parent": [ diff --git a/js/h5p.js b/js/h5p.js index 38f6022..4330ade 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -2140,6 +2140,20 @@ H5P.createTitle = function (rawTitle, maxLength) { contentUserDataAjax(contentId, dataId, subContentId, undefined, null); }; + /** + * Function for getting content for a certain ID + * + * @param {number} contentId + * @return {Object} + */ + H5P.getContentForInstance = function (contentId) { + var key = 'cid-' + contentId; + var exists = H5PIntegration && H5PIntegration.contents && + H5PIntegration.contents[key]; + + return exists ? H5PIntegration.contents[key] : undefined; + }; + /** * Prepares the content parameters for storing in the clipboard. * From 775b45ab6c5733e7d52c5cf352b60bebe4913297 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Fri, 31 Aug 2018 09:32:23 +0200 Subject: [PATCH 2/2] HFP-2094 Add metadata property to validation of library.json --- h5p.classes.php | 1 + 1 file changed, 1 insertion(+) diff --git a/h5p.classes.php b/h5p.classes.php index 6f48f53..024235c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -680,6 +680,7 @@ class H5PValidator { 'author' => '/^.{1,255}$/', 'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr|MIT|GPL1|GPL2|GPL3|MPL|MPL2)$/', 'description' => '/^.{1,}$/', + 'metadata' => '/^(0|1)$/', 'dynamicDependencies' => array( 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/',