]> _ Git - fluidbook-toolbox.git/commitdiff
done #3948 @2.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Oct 2020 17:26:14 +0000 (19:26 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Oct 2020 17:26:14 +0000 (19:26 +0200)
app/Models/Quiz.php
resources/quiz/js/main.js

index 8e67d3f12ba1d4f5434537323836e0cc191c60c7..571a2164601b9819425dcdd2a1d99756da2f62a3 100644 (file)
@@ -224,7 +224,7 @@ class Quiz extends CubistMagicAbstractModel
         $xml->addChild('logattempts', $data->get('logattempts', false) ? '1' : '0');
         $xt = $xml->addChild('translations');
         /** @var QuizTranslation $translation */
-        $tid = $data->get('translation',1) ?? 1;
+        $tid = $data->get('translation', 1) ?? 1;
         if ($tid === 'en') {
             $tid = 1;
         }
@@ -256,6 +256,7 @@ class Quiz extends CubistMagicAbstractModel
             }
             $xq->addAttribute('count', $question['count_for_score'] ? '1' : '0');
             $xq->addAttribute('type', $question['type']);
+            $xq->addAttribute('min_score', $question['min_score']);
             $xq->addChild('label', $question['question']);
             if ($question['type'] === 'multiple') {
                 $xas = $xq->addChild('answers');
index b09ae217b4b79fae6e5d5b2a154571a1393e1440..f1960d4a21d8716236fa2e0e630b88b542bb616a 100644 (file)
                 var type = $(this).attr('type');
                 var multiple = $(this).attr('multiple') == '1';
                 var multipleclass = multiple ? ' multiple' : '';
-                var question = '<section class="question' + multipleclass + '" data-count="' + $(this).attr('count') + '" data-q="' + qn + '" data-type="' + type + '">';
+                var question = '<section class="question' + multipleclass + '" data-count="' + $(this).attr('count') + '" data-q="' + qn + '" data-min-score="' + $(this).attr('min_score') + '" data-type="' + type + '">';
                 question += '<div class="label"><h3>' + sprintf(getTranslation('question'), qn) + '</h3> ' + $(this).find('label').text() + '</div>';
                 question += '<div class="answers">';
                 question += '</div>';
                 };
 
                 if ($(this).data('type') === 'multiple') {
+                    var min_score = parseInt($(this).data('min-score'));
+                    if (min_score === 0) {
+                        min_score = $(this).find('.answer[data-correct="1"]').length;
+                    }
+                    var this_score = 0;
                     $(this).find('.answer').each(function () {
-                        var correct = $(this).attr('data-correct') == '1';
-                        var active = $(this).hasClass('active');
-                        if (correct !== active) {
-                            ok = false;
-                        }
-                        if (active) {
+                        if ($(this).hasClass('active')) {
+                            var correct = $(this).attr('data-correct') == '1';
+                            this_score += correct ? 1 : -1;
                             a.push($(this).data('a'))
                         }
                     });
+                    console.log(this_score, min_score);
+                    ok = this_score >= min_score;
                     answers.push(a);
                     log.anwser = a;
                 } else {