]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5471 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Oct 2022 08:25:14 +0000 (10:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Oct 2022 08:25:14 +0000 (10:25 +0200)
app/Models/Quiz.php
resources/quiz/js/app.js

index 298635906a039ec56d09aeac0cd79cdd1422f3ed..a1551bc4824c20fd72b9eeb099d8b5a414ae2864 100644 (file)
@@ -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');
index a48f0c9e3862541dce116924446617132fa4fb12..377fe20eff277a242543bdccb01fd5a0ef6ba71b 100644 (file)
@@ -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);