From: Vincent Vanwaelscappel Date: Thu, 1 Apr 2021 17:23:30 +0000 (+0200) Subject: wait #4388 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=d34ff0e2704daa2020676a1ab8a98aff0e81d5cd;p=fluidbook-toolbox.git wait #4388 @3 --- diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index fa17ca03b..eba871bbe 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -256,9 +256,15 @@ class Quiz extends CubistMagicAbstractModel } } - file_put_contents($dest . '/data.js', 'var DATA=' . json_encode($this->getData()) . ';'); + $data = $this->getData(); + + $json = json_encode($data, JSON_THROW_ON_ERROR); + + file_put_contents($dest . '/data.js', 'var DATA=' . $json . ';'); if ($this->getAttribute('scorm')) { + $scorm_js = ' +'; $title = htmlspecialchars($this->getAttribute('title')); file_put_contents($dest . '/imsmanifest.xml', ' @@ -280,7 +286,13 @@ class Quiz extends CubistMagicAbstractModel '); + } else { + $scorm_js = ''; + unlink($dest . '/js/scorm.js'); + unlink($dest . '/js/libs/scorm/apiwrapper.js'); } + + file_put_contents($dest . '/index.html', str_replace('$SCORM_JS', $scorm_js, file_get_contents($dest . '/index.html'))); } public function getData() @@ -288,6 +300,11 @@ class Quiz extends CubistMagicAbstractModel $data = $this->getPageData(); $d = $data->getRawData(); + $unset = ['banner', 'logo']; + foreach ($unset as $item) { + unset($d[$item]); + } + // Create data.js $d['translations'] = []; $tid = $data->get('translation', 1) ?? 1; diff --git a/resources/quiz/index.html b/resources/quiz/index.html index 00815481f..2cd105b35 100644 --- a/resources/quiz/index.html +++ b/resources/quiz/index.html @@ -26,8 +26,7 @@ - - +$SCORM_JS diff --git a/resources/quiz/js/main.js b/resources/quiz/js/main.js index 446e94a72..227e2f7f0 100644 --- a/resources/quiz/js/main.js +++ b/resources/quiz/js/main.js @@ -96,7 +96,7 @@ countQuestions++; } var multipleClass = question.multiple ? ' multiple' : ''; - var questionHtml = '
'; + var questionHtml = '
'; questionHtml += '

' + sprintf(getTranslation('question'), qn) + '

' + question.question + '
'; questionHtml += '
'; if (question.multiple) { @@ -109,8 +109,8 @@ var questionCorrection = question.explaination; if (questionCorrection === '') { var c = []; - $.each(question.answers,function (kk, answer) { - if (answer.correct==1) { + $.each(question.answers, function (kk, answer) { + if (answer.correct == 1) { c.push(answer.answer); } }); @@ -132,7 +132,7 @@ $.each(question.answers, function (aa, answer) { var a = $('
' + answer.answer + '
'); // Set correct tag - var correct = answer.correct==1 ? 1 : 0; + var correct = answer.correct == 1 ? 1 : 0; correctCount += correct; $(a).find('.answer').attr('data-correct', correct); $(holder).append($(a)); @@ -185,7 +185,12 @@ $(document).on('quizinit', function (event, state) { init(state); }); - initScormEvents(); + if (DATA.scorm) { + initScormEvents(); + } else { + SCORM = false; + $(document).trigger('quizinit', {q: 1}); + } resizeContainer(); resize(); } @@ -300,9 +305,11 @@ function completed() { updateScore(); - setSCORMScore(score, $("section.question").length, 0); - setScormValue('cmi.core.lesson_status', 'completed'); - setSCORMLocation({q: 1}); + if (DATA.scorm) { + setSCORMScore(score, $("section.question").length, 0); + setScormValue('cmi.core.lesson_status', 'completed'); + setSCORMLocation({q: 1}); + } var passed = checkScore(); if (logAttempts) {