From 5d89e9976050c9a739105a6373e8d22de525441a Mon Sep 17 00:00:00 2001 From: Sander A Date: Mon, 27 Aug 2018 15:53:50 +0300 Subject: [PATCH] Override H5P.Blanks xapi statement build fixes #83 --- ov_h5p_overrides/h5p-blanks-xapi-override.js | 49 ++++++++++++++++++++ ov_h5p_overrides/ov_h5p_overrides.module | 7 +++ 2 files changed, 56 insertions(+) create mode 100644 ov_h5p_overrides/h5p-blanks-xapi-override.js diff --git a/ov_h5p_overrides/h5p-blanks-xapi-override.js b/ov_h5p_overrides/h5p-blanks-xapi-override.js new file mode 100644 index 0000000..f3a8fd7 --- /dev/null +++ b/ov_h5p_overrides/h5p-blanks-xapi-override.js @@ -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; +}; \ No newline at end of file diff --git a/ov_h5p_overrides/ov_h5p_overrides.module b/ov_h5p_overrides/ov_h5p_overrides.module index acc849f..c3fddc0 100644 --- a/ov_h5p_overrides/ov_h5p_overrides.module +++ b/ov_h5p_overrides/ov_h5p_overrides.module @@ -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' => '' + ); + } } }