Skip to content

Commit

Permalink
Override H5P.Blanks xapi statement build
Browse files Browse the repository at this point in the history
fixes #83
  • Loading branch information
Sander A committed Aug 27, 2018
1 parent 3abba68 commit 5d89e99
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ov_h5p_overrides/h5p-blanks-xapi-override.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
H5P.Blanks.prototype.getxAPIDefinition = function () {
var definition = {};
definition.description = {
'en-US': this.params.text
};
definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction';
definition.interactionType = 'fill-in';
// XXX START
//definition.correctResponsesPattern = ['{case_matters=' + this.params.behaviour.caseSensitive + '}'];
// XXX END
var firstCorrectResponse = true;
// xAPI forces us to create solution patterns for all possible solution combinations
for (var i = 0; i < this.params.questions.length; i++) {
var question = this.handleBlanks(this.params.questions[i], function(solution) {
// XXX START
// This code could hang the browser in case there are many questions and each one has multiple correct answers
/*
// Store new patterns for each extra alternative answer
var newPatterns = [];
for (var j = 0; j < definition.correctResponsesPattern.length; j++) {
if (!firstCorrectResponse) {
definition.correctResponsesPattern[j] += '[,]';
}
var prefix = definition.correctResponsesPattern[j];
for (var k = 0; k < solution.solutions.length; k++) {
if (k === 0) {
// This is the first possible answr, just add it to the pattern
definition.correctResponsesPattern[j] += solution.solutions[k];
}
else {
// This is an alternative possible answer, we need to create a new permutation
newPatterns.push(prefix + solution.solutions[k]);
}
}
}
// Add any new permutations to the list of response patterns
definition.correctResponsesPattern = definition.correctResponsesPattern.concat(newPatterns);
firstCorrectResponse = false;
*/
// XXX END

// We replace the solutions in the question with a "blank"
return '__________';
});
definition.description['en-US'] += question;
}
return definition;
};
7 changes: 7 additions & 0 deletions ov_h5p_overrides/ov_h5p_overrides.module
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ function ov_h5p_overrides_h5p_scripts_alter(&$scripts, $libraries, $mode) {
'path' => drupal_get_path('module', 'ov_h5p_overrides') . '/math_jax_hacks.js',
'version' => ''
);

if(isset($libraries['H5P.Blanks']) && $libraries['H5P.Blanks']['majorVersion'] == "1" && $libraries['H5P.Blanks']['minorVersion'] == "10"){
$scripts[] = (object) array(
'path' => drupal_get_path('module', 'ov_h5p_overrides') . '/h5p-blanks-xapi-override.js',
'version' => ''
);
}
}
}

Expand Down

0 comments on commit 5d89e99

Please sign in to comment.