this.logQuestions = [];
// Le score global du quiz
this.score = 0;
+ this.maxScore = 0;
this.questionStatus = [];
this.answers = [];
this.lastAnsweredQuestion = -1;
},
+ /**
+ *
+ * @param questionIndex integer
+ * @param answers array
+ * @returns {{ok, status: []}}
+ */
setAnswer: function (questionIndex, answers) {
this.lastAnsweredQuestion = questionIndex;
this.answers[questionIndex] = answers;
this.updateScore();
- return {ok: this.questionStatus[questionIndex].ok, status: this.questionStatus};
+ return {
+ ok: this.questionStatus[questionIndex].ok,
+ score: this.score,
+ maxScore: this.maxScore,
+ status: this.questionStatus
+ };
},
checkQuestion: function (questionIndex) {
- let question = this.quiz.questions[questionIndex];
+ let question = this.quiz.data.questions[questionIndex];
let a = [];
let ok = true;
- let count = $(this).attr('data-count') == '1';
+ let count = question.count_for_score;
let log = {
'count': count,
};
let answersStatus = [];
let userAnswers = this.answers[questionIndex];
+ let min_score = 0;
+ let this_score = 0;
if (userAnswers === undefined || userAnswers === null) {
ok = null;
} else {
let $this = this;
if (question.type === 'multiple') {
// Le score de la question
- let min_score = this.getMinScore(question);
- let this_score = 0;
- for (const answerIndex in question.answers) {
+ min_score = this.getMinScore(question);
+ this_score = 0;
+ for (let answerIndex in question.answers) {
+ answerIndex = parseInt(answerIndex);
const answer = question.answers[answerIndex];
let checkedByUser = userAnswers.indexOf(answerIndex) >= 0;
if (answer.correct === 1) {
this_score += answer.score;
answersStatus[answerIndex] = 'ok';
} else {
- // C'est une bonne réponse mais elle n'a pas été cochée par l'utilisateur
+ // C'est une bonne réponse, mais elle n'a pas été cochée par l'utilisateur
answersStatus[answerIndex] = 'missed';
}
} else {
}
}
}
-
ok = this_score >= min_score;
log.answer = a;
} else {
log.answer = $(this).find('input,textarea,select').val();
}
-
- if (!count) {
- ok = null;
- }
}
- this.questionStatus[questionIndex] = {'status': ok, 'answers': answersStatus};
+ this.questionStatus[questionIndex] = {
+ ok: ok,
+ answers: answersStatus,
+ // dbg_min_score: min_score,
+ // dbg_this_score: this_score
+ };
- if (ok && count) {
- this.score++;
- log.score = 1;
+ if (count) {
+ this.maxScore++;
+ if (ok) {
+ this.score++;
+ log.score = 1;
+ } else {
+ log.score = 0;
+ }
} else {
log.score = 0;
}
if (min_score === 0) {
min_score = 0;
for (const answerIndex in question.answers) {
- let answer = question.answers[answerIndex];
- if (answer.correct) {
+ const answer = question.answers[answerIndex];
+ if (answer.correct === 1) {
min_score += answer.score;
}
}
},
updateScore: function () {
+ this.maxScore = 0;
this.score = 0;
this.logQuestions = [];
- for (const qn in this.quiz.questions) {
+ for (const qn in this.quiz.data.questions) {
this.checkQuestion(qn);
}