Skip to content

Commit

Permalink
JI-3263 Add support of report when content is used as child content
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravi Majithia committed Mar 1, 2022
1 parent 51a212e commit 7368e45
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion image-hotspot-question.js
Expand Up @@ -96,6 +96,11 @@ H5P.ImageHotspotQuestion = (function ($, Question) {
this.previousState = contentData.previousState;
}

// Start activity timer
if (this.isRoot()) {
this.setActivityStarted();
}

// Register resize listener with h5p
this.on('resize', this.resize);
}
Expand Down Expand Up @@ -286,7 +291,7 @@ H5P.ImageHotspotQuestion = (function ($, Question) {
this.hotspotFeedback.$element.addClass('fade-in');

// Trigger xAPI completed event
this.triggerXAPIScored(this.getScore(), this.getMaxScore(), 'answered');
this.triggerAnswered();
};

/**
Expand Down Expand Up @@ -329,6 +334,10 @@ H5P.ImageHotspotQuestion = (function ($, Question) {
return this.score;
};

ImageHotspotQuestion.prototype.getTitle = function () {
return H5P.createTitle((this.contentData.metadata && this.contentData.metadata.title) ? this.contentData.metadata.title : 'Fill In');
};

/**
* Gets the max score for this question.
* Used in contracts.
Expand All @@ -338,6 +347,58 @@ H5P.ImageHotspotQuestion = (function ($, Question) {
return this.maxScore;
};

/**
* Trigger xAPI answered event
*/
ImageHotspotQuestion.prototype.triggerAnswered = function () {
var self = this;
var xAPIEvent = self.createXAPIEventTemplate('answered');
self.addQuestionToXAPI(xAPIEvent);
self.trigger(xAPIEvent);
};

/**
* Get xAPI data.
* Contract used by report rendering engine.
*
* @see contract at {@link https://h5p.org/documentation/developers/contracts#guides-header-6}
*/
ImageHotspotQuestion.prototype.getXAPIData = function () {
var self = this;
var xAPIEvent = self.createXAPIEventTemplate('answered');
xAPIEvent.setScoredResult(self.getScore(), self.getMaxScore(), self, true, true);

This comment has been minimized.

Copy link
@otacke

otacke Jun 7, 2022

Contributor

@ravimajithia Should the success argument (the last one here) always be true, or should it rather be set to self.getScore() === self.getMaxScore()?

self.addQuestionToXAPI(xAPIEvent);
return {
statement: xAPIEvent.data.statement
};
};

/**
* Add the question itselt to the definition part of an xAPIEvent
*/
ImageHotspotQuestion.prototype.addQuestionToXAPI = function (xAPIEvent) {
var definition = xAPIEvent.getVerifiedStatementValue(['object', 'definition']);
$.extend(true, definition, this.getxAPIDefinition());
};

/**
* Generate xAPI object definition used in xAPI statements.
* @return {Object}
*/
ImageHotspotQuestion.prototype.getxAPIDefinition = function () {
// Individual report not supported
if (this.isRoot()) {
return;
}
var definition = {};
definition.description = {
'en-US': this.getTitle()
};
definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction';
definition.interactionType = 'general';
return definition;
};

/**
* Display the first found solution for this question.
* Used in contracts
Expand Down Expand Up @@ -371,6 +432,11 @@ H5P.ImageHotspotQuestion = (function ($, Question) {

// Clear feedback
this.removeFeedback();

// Reset timer
if (this.isRoot()) {
this.setActivityStarted(true);
}
};

/**
Expand Down

0 comments on commit 7368e45

Please sign in to comment.