H5P Guides

Question type contract

The contract to be followed if a content type should be compatible with Question set, Course presentation, and Interactive video. The examples are taken from H5P.Blanks.

The following sections list the required contracts that a library must implement.

Functions 

getAnswerGiven()

Checks if answers for this task has been given, and the program can proceed to calculate scores. Should return false if the user can not proceed yet.

Return value

Returns {Boolean} true if answers have been given, else false.

  Blanks.prototype.getAnswerGiven = function () {
    return this.answered || this.blankIsCorrect;
  };

getScore()

Calculates the user's score for this task, f.ex. correct answers subtracted by wrong answers.

Return value

Returns {Number}  User's score for this task.

  Blanks.prototype.getScore = function () {
    return = this.points;
  };

getMaxScore()

Calculates the maximum amount of points achievable for this task.

Return value

Returns {Number} Max score achievable for this task.

  Blanks.prototype.getMaxScore = function () {
    return this.calculateMaxScore();
  };

showSolutions()

Displays the solution(s) for this task, should also hide all buttons.

Return value

none

  Blanks.prototype.showSolutions = function () {
    this.showAllSolutions();
    //Hide solution button:
    this._$solutionButton.hide();
    this._$retryButton.hide();

    //Disable dragging during "solution" mode
    this.disableDraggables();
  };

resetTask()

Resets the task to its initial state, should also show buttons that were hidden by the showSolutions() function.

Return value

none

  Blanks.prototype.resetTask = function () {
    this.points = 0;
    this.rawPoints = 0;

    //Enables Draggables
    this.enableDraggables();

    //Reset position and feedback.
    this.draggables.forEach(function (draggable) {
      draggable.resetPosition();
    });

    //Show solution button
    this.$solutionButton.show();
    this.$retryButton.hide();

    // Reset score message
    this.showScore();

  };

getXAPIData()

Retrieves the xAPI data necessary for generating result reports.

Return value

An object with the following fields:

  • statement: Should contain the xAPI statement that is usually sent on 'answered. Refer to the xAPI spec.
  • children: Optional field with an array of all children's xAPI event. This is implemented by calling getXAPIData() on all children of the content type.

The following properties of the statement structure is essential for the functions where this contract is used: 

  • object.definition.interactionType: Type of the interaction. Choose from xAPI spec.
  • object.definition.description: Question text and any additional information to generate the report.
  • object.definition.correctResponsesPattern: A pattern for determining the correct answers of the interaction. See spec.
  • object.definition: Additional definition properties required for the specific interaction type.
  • result.response: User answers for interaction. See spec.
  • result.score.min: Minimum possible score for task
  • result.score.raw: Raw user score
  • result.score.max: Maximum possible score for task
  • result.score.scaled: Score in percentage.

Variables

params.behaviour.enableSolutionsButton {Boolean}

A boolean class parameter that determines if a "show solution" button will be shown in your content type.

Description

The parent content type must be able to override whether a solution button should be displayed. Implementing a class parameter called "enableSolutionsButton" and letting this value determine if the solution button will be displayed, will allow the parent content type to override this value.

Type

Boolean

    // Set this.params.behaviour.enableSolutionsButton to true or false through semantics.
    if (this.params.behaviour.enableSolutionsButton === true) {
      this.addSolutionsButton();
    }

params.behaviour.enableRetry {Boolean}

A boolean class parameter that determines if a "retry" button will be shown in your content type.

Description

The parent content type must be able to override whether a solution button should be displayed. Implementing a class parameter called "enableRetry" and letting this value determine if the solution button will be displayed, will allow the parent content type to override this value.

Type

Boolean

    // Set this.params.behaviour.enablRetry to true or false through semantics.
    if (this.params.behaviour.enableRetry === true) {
      this.addRetryButton();
    }