From 1d449cc89ac88f5620b7d7f6246c48e0fe2eb161 Mon Sep 17 00:00:00 2001 From: Brian Quinn Date: Wed, 16 Aug 2017 14:44:24 +0100 Subject: [PATCH 1/2] Resolves #1710, adds getInteractionObject() function This is required in preparation for xAPI support. --- js/adapt-contrib-matching.js | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/js/adapt-contrib-matching.js b/js/adapt-contrib-matching.js index c142899..e6ac5b3 100644 --- a/js/adapt-contrib-matching.js +++ b/js/adapt-contrib-matching.js @@ -278,6 +278,53 @@ define([ this.$('select').eq(i).val(value).trigger('change'); }, + /** + * Used by tracking extensions to return an object containing the component's specific interactions. + */ + getInteractionObject: function() { + var interactions = { + correctResponsesPattern: null, + source: null, + target: null + }; + + interactions.correctResponsesPattern = [ + this.model.get('_items').map(function(item, questionIndex) { + questionIndex = questionIndex + 1; + + return [ + questionIndex, + item._options.filter(function(item) { + return item._isCorrect; + }).map(function(item) { + return questionIndex + '_' + (item._index + 1).toString() + }) + ].join('[.]'); + + }).join('[,]') + ]; + + interactions.source = _.flatten(this.model.get('_items').map(function(item) { + return { + id: (item._index + 1).toString(), + description: item.text + } + })); + + interactions.target = _.flatten(this.model.get('_items').map(function(item, index) { + // Offset by 1, as these values are not zero-indexed. + index = index + 1; + return item._options.map(function(option) { + return { + id: index + '_' + (option._index + 1), + description: option.text + } + }); + })); + + return interactions; + }, + /** * Used by adapt-contrib-spoor to get the user's answers in the format required by the cmi.interactions.n.student_response data field * Returns the user's answers as a string in the format "1.1#2.3#3.2" assuming user selected option 1 in drop-down 1, option 3 in drop-down 2 From e76a579fe25c6af61d4d95508434909e4a32aebc Mon Sep 17 00:00:00 2001 From: Brian Quinn Date: Thu, 17 Aug 2017 09:28:11 +0100 Subject: [PATCH 2/2] Added some comments to getInteractionObject() --- js/adapt-contrib-matching.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/js/adapt-contrib-matching.js b/js/adapt-contrib-matching.js index e6ac5b3..7a77846 100644 --- a/js/adapt-contrib-matching.js +++ b/js/adapt-contrib-matching.js @@ -288,15 +288,21 @@ define([ target: null }; + // This contains an array with a single string value, matching the source 'id' with the correct + // matching target 'id' value. An example is as follows: + // [ "1[.]1_2[,]2[.]2_3" ] interactions.correctResponsesPattern = [ this.model.get('_items').map(function(item, questionIndex) { + // Offset the item index and use it as a group identifier. questionIndex = questionIndex + 1; return [ questionIndex, item._options.filter(function(item) { + // Get the correct item(s). return item._isCorrect; }).map(function(item) { + // Prefix the option's index and offset by 1. return questionIndex + '_' + (item._index + 1).toString() }) ].join('[.]'); @@ -304,13 +310,21 @@ define([ }).join('[,]') ]; + // The 'source' property contains an array of all the stems/questions, e.g. + // [{id: "1", description: "First question"}, {id: "2", description: "Second question"}] interactions.source = _.flatten(this.model.get('_items').map(function(item) { return { + // Offset by 1. id: (item._index + 1).toString(), description: item.text } })); + // The 'target' property contains an array of all the option responses, with the 'id' + // prefixed to indicate the grouping, e.g. + // [ {id: "1_1": description: "First option, group 1"}, + // {id: "1_2": description: "Second option, group 1"} + // {id: "2_1": description: "First option, group 2"} ] interactions.target = _.flatten(this.model.get('_items').map(function(item, index) { // Offset by 1, as these values are not zero-indexed. index = index + 1;