From: Vincent Vanwaelscappel Date: Thu, 20 Oct 2022 08:25:14 +0000 (+0200) Subject: wip #5471 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=edc1e257746daf9cbfa823ec095b258af6db0b8d;p=fluidbook-toolbox.git wip #5471 @1 --- diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index 298635906..a1551bc48 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -303,7 +303,6 @@ class Quiz extends ToolboxModel } } - if ($forceScorm || $this->getAttribute('scorm')) { $scormVersion = $this->getAttribute('scorm_version') ?: '1.2'; $manifest = new Manifest($this->getAttribute('title'), $scormVersion, $this->getAttribute('client') ?: backpack_user()->getCompanyNameAttribute(), $this->getAttribute('project') ?: 'Quiz'); diff --git a/resources/quiz/js/app.js b/resources/quiz/js/app.js index a48f0c9e3..377fe20ef 100644 --- a/resources/quiz/js/app.js +++ b/resources/quiz/js/app.js @@ -9,7 +9,8 @@ require('../../scorm/scorm'); var data; var score; var questionStatus = {}; - var showReview, threshold, instantReview, logAttempts, displayScore, countQuestions, passedAction, failedAction, + var testMode, quizMode, showReview, threshold, instantReview, logAttempts, displayScore, countQuestions, + passedAction, failedAction, logQuestions; function initApp() { @@ -103,6 +104,8 @@ require('../../scorm/scorm'); instantReview = DATA.instantReview; logAttempts = DATA.logattempts; displayScore = DATA.display_score; + testMode = DATA.type === 'test'; + quizMode = DATA.type === 'quiz'; threshold = DATA.threshold; if (threshold > 1) { @@ -272,7 +275,11 @@ require('../../scorm/scorm'); $(answer).addClass('active'); $('section:visible').find('.answer:not(.active)').addClass('inactive'); updateScore(); - displayBadge($(answer).attr('data-correct') == 1); + if (testMode) { + displayBadge(true); + } else { + displayBadge($(answer).attr('data-correct') == 1); + } resizeContainer(); } else { $(answer).toggleClass('active'); @@ -418,6 +425,62 @@ require('../../scorm/scorm'); } function updateScore() { + if (testMode) { + return updateTestScore(); + } + if (quizMode) { + return updateQuizScore(); + } + } + + function updateTestScore() { + score = 0; + var answers = []; + var qn = 1; + logQuestions = []; + + + $('.question').each(function () { + var q = $(this); + var a = []; + var log = {}; + + var qScore = null; + if ($(this).data('type') === 'multiple') { + $(this).find('.answer.active').each(function () { + a.push($(this).data('a')) + qScore = DATA.questions[q.data('q') - 1].answers[$(this).data('a')].score; + }); + + answers.push(a); + log.answer = a; + } else { + log.answer = $(this).find('input,textarea,select').val(); + } + + questionStatus[qn] = qScore; + + if (qScore !== null) { + score += qScore; + } + log.score = qScore; + + logQuestions[qn] = log; + qn++; + }); + + + var state = { + q: $(".answer.active").last().closest('.question').data('q') + 1, a: answers + }; + + if (SCORM) { + setSCORMLocation(state); + } + $("#correctanswers").text(score); + } + + function updateQuizScore() { score = 0; var answers = []; var qn = 1; @@ -485,6 +548,8 @@ require('../../scorm/scorm'); } $("#correctanswers").text(score); } + + }); })(typeof window === 'undefined' ? this : window);