From 1cd0fef71ed884f81bc4e35c16347cf4b6fb8fa2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 25 Sep 2023 17:44:04 +0200 Subject: [PATCH] wip #6186 @0.75 --- js/quiz.score.js | 25 ++++++++++++++++++++++--- js/quiz.scorm.js | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/js/quiz.score.js b/js/quiz.score.js index dec9675..7025a19 100644 --- a/js/quiz.score.js +++ b/js/quiz.score.js @@ -103,13 +103,12 @@ QuizScore.prototype = { } this.questionStatus[questionIndex] = { - ok: ok, answers: answersStatus, // dbg_min_score: min_score, - // dbg_this_score: this_score + ok: ok, answers: answersStatus, }; if (count) { this.maxScore++; - if (ok == 'ok') { + if (ok === 'ok') { this.score++; log.score = 1; } else { @@ -121,6 +120,19 @@ QuizScore.prototype = { this.logQuestions[questionIndex] = log; }, + getNormalizedScore: function (pct) { + var s = this.score / this.getQuestionsCount(); + if (pct === undefined || pct === false) { + return s; + } + return Math.round(100 * s); + }, + + isPassed: function () { + let threshold = parseInt(this.quiz.data.threshold); + return isNaN(threshold) || this.getNormalizedScore(true) > threshold; + }, + getMinScore: function (question) { // Le score minimal est le score que l'utilisateur doit atteindre sur une question pour que sa réponse soit considérée let min_score = parseInt(question.min_score); @@ -146,6 +158,13 @@ QuizScore.prototype = { } this.quiz.scorm.saveState(this.getCurrentState()); + if (this.lastAnsweredQuestion === this.getQuestionsCount()) { + this.quiz.scorm.completed() + } + }, + + getQuestionsCount: function () { + return this.quiz.data.questions.length - 1 }, getCurrentState: function () { diff --git a/js/quiz.scorm.js b/js/quiz.scorm.js index df3f6a5..bad02ad 100644 --- a/js/quiz.scorm.js +++ b/js/quiz.scorm.js @@ -36,7 +36,7 @@ QuizScorm.prototype = { completed: function (passed) { cubeSCORM.scormMarkAsComplete(); - cubeSCORM.setScormValue('success_status', this.quiz.score.passed ? 'passed' : 'failed'); + cubeSCORM.setScormValue('success_status', this.quiz.score.isPassed() ? 'passed' : 'failed'); cubeSCORM.setSCORMScore(this.quiz.score.getNormalizedScore(true), 100, 0, this.quiz.score.getNormalizedScore()); this.saveState(this.defaultState) }, -- 2.39.5