From f2bb7e9172541da6a17b05a3b809fe29d5ab227d Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Wed, 23 Nov 2016 09:31:54 +0100 Subject: [PATCH 1/5] Code formatting --- js/questionset.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 97ef90b..ed41f73 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -541,7 +541,6 @@ H5P.QuestionSet = function (options, contentId, contentData) { replaceQuestionsInDOM(questionInstances); }; - /** * Empty the DOM of all questions, attach new questions and update buttons * @@ -817,7 +816,6 @@ H5P.QuestionSet = function (options, contentId, contentData) { }); }; - /** * Initialize a question and attach it to the DOM * @@ -1009,7 +1007,6 @@ H5P.QuestionSet = function (options, contentId, contentData) { return score; }; - /** * @deprecated since version 1.9.2 * @returns {number} From 7a3e8d8292059980ca0e6372ff67828f695683d5 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Wed, 23 Nov 2016 10:19:32 +0100 Subject: [PATCH 2/5] Add function getXAPIData() to allow the creation of a report HFP-255 --- js/questionset.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/js/questionset.js b/js/questionset.js index ed41f73..32c6d63 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -1121,6 +1121,58 @@ H5P.QuestionSet = function (options, contentId, contentData) { poolOrder: poolOrder }; }; + + /** + * Generate xAPI object definition used in xAPI statements. + * @return {Object} + */ + var getxAPIDefinition = function () { + var definition = {}; + + definition.interactionType = 'compound'; + definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction'; + definition.description = { + 'en-US': 'Question Set' + }; + + return definition; + }; + + /** + * Add the question itself to the definition part of an xAPIEvent + */ + var addQuestionToXAPI = function(xAPIEvent) { + var definition = xAPIEvent.getVerifiedStatementValue(['object', 'definition']); + $.extend(definition, getxAPIDefinition()); + }; + + /** + * Get xAPI data from sub content types + * + * @param {Object} metaContentType + * @returns {array} + */ + var getXAPIDataFromChildren = function(metaContentType) { + return metaContentType.getQuestions().map(function(question) { + return question.getXAPIData(); + }); + } + + /** + * Get xAPI data. + * Contract used by report rendering engine. + * + * @see contract at {@link https://h5p.org/documentation/developers/contracts#guides-header-6} + */ + this.getXAPIData = function(){ + var xAPIEvent = this.createXAPIEventTemplate('answered'); + addQuestionToXAPI(xAPIEvent); + var childrenData = getXAPIDataFromChildren(this); + return { + statement: xAPIEvent.data.statement, + children: childrenData + } + }; }; H5P.QuestionSet.prototype = Object.create(H5P.EventDispatcher.prototype); From 29d122be50f3f3fea43d94fb15396189711ab6c8 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Wed, 23 Nov 2016 14:39:57 +0100 Subject: [PATCH 3/5] Update questionset.js --- js/questionset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/questionset.js b/js/questionset.js index 32c6d63..476cb59 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -1132,7 +1132,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { definition.interactionType = 'compound'; definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction'; definition.description = { - 'en-US': 'Question Set' + 'en-US': '' }; return definition; From 5b0736f0e8b2a3be0b5617c02228606c5939f803 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Thu, 24 Nov 2016 17:29:47 +0100 Subject: [PATCH 4/5] Added score to getXAPIData call HFP-255 --- js/questionset.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 476cb59..0fdd085 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -1132,7 +1132,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { definition.interactionType = 'compound'; definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction'; definition.description = { - 'en-US': '' + 'en-US': '' }; return definition; @@ -1150,13 +1150,13 @@ H5P.QuestionSet = function (options, contentId, contentData) { * Get xAPI data from sub content types * * @param {Object} metaContentType - * @returns {array} + * @returns {array} */ var getXAPIDataFromChildren = function(metaContentType) { return metaContentType.getQuestions().map(function(question) { return question.getXAPIData(); }); - } + }; /** * Get xAPI data. @@ -1166,11 +1166,16 @@ H5P.QuestionSet = function (options, contentId, contentData) { */ this.getXAPIData = function(){ var xAPIEvent = this.createXAPIEventTemplate('answered'); - addQuestionToXAPI(xAPIEvent); - var childrenData = getXAPIDataFromChildren(this); + addQuestionToXAPI(xAPIEvent); + xAPIEvent.setScoredResult(this.getScore(), + this.getMaxScore(), + this, + true, + this.getScore() === this.getMaxScore() + ); return { statement: xAPIEvent.data.statement, - children: childrenData + children: getXAPIDataFromChildren(this) } }; }; From 541bf90762c16f3e583fee881b397cb4bbc8c54c Mon Sep 17 00:00:00 2001 From: thomasmars Date: Fri, 25 Nov 2016 09:29:08 +0100 Subject: [PATCH 5/5] Increased patch version, prepared for release --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 7085667..098e93a 100644 --- a/library.json +++ b/library.json @@ -4,7 +4,7 @@ "contentType": "question", "majorVersion": 1, "minorVersion": 10, - "patchVersion": 1, + "patchVersion": 2, "embedTypes": [ "iframe" ],