From 11bc5fa2a2befba4b01d01815df52eded26993c9 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 20 Jun 2017 13:17:49 +0200 Subject: [PATCH] Add duration, completion and success to xAPI completed event --- memory-game.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/memory-game.js b/memory-game.js index 4ace9de..9a0e2da 100644 --- a/memory-game.js +++ b/memory-game.js @@ -60,10 +60,6 @@ H5P.MemoryGame = (function (EventDispatcher, $) { var isFinished = (removed === cards.length); var desc = card.getDescription(); - if (isFinished) { - self.triggerXAPIScored(1, 1, 'completed'); - } - if (desc !== undefined) { // Pause timer and show desciption. timer.pause(); @@ -95,6 +91,13 @@ H5P.MemoryGame = (function (EventDispatcher, $) { var finished = function () { timer.stop(); $feedback.addClass('h5p-show'); + + // Create and trigger xAPI event 'completed' + var completedEvent = self.createXAPIEventTemplate('completed'); + completedEvent.setScoredResult(1, 1, self, true, true); + completedEvent.data.statement.result.duration = 'PT' + (Math.round(timer.getTime() / 10) / 100) + 'S'; + self.trigger(completedEvent); + if (parameters.behaviour && parameters.behaviour.allowRetry) { // Create retry button var retryButton = createButton('reset', parameters.l10n.tryAgain || 'Try again?', function () {