From 2f60924b09014724bc84ff7bede6679ff9b4a1fc Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 28 Jun 2022 17:40:55 +0200 Subject: [PATCH] wip #5319 @1.5 --- app/Jobs/ElearningMediaDownload.php | 2 +- app/Jobs/ElearningPackageDownload.php | 4 ++-- app/Jobs/QuizDownload.php | 2 +- app/Models/Quiz.php | 26 ---------------------- resources/elearningpackage/js/app.js | 3 ++- resources/quiz/js/app.js | 32 +++++++++++++++------------ resources/scorm/scorm.js | 24 +++++++++++--------- 7 files changed, 37 insertions(+), 56 deletions(-) diff --git a/app/Jobs/ElearningMediaDownload.php b/app/Jobs/ElearningMediaDownload.php index b6c08a796..7459a699b 100644 --- a/app/Jobs/ElearningMediaDownload.php +++ b/app/Jobs/ElearningMediaDownload.php @@ -32,7 +32,7 @@ class ElearningMediaDownload extends DownloadBase try { if ($this->action === 'scormcloud') { - $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->entry->id); + $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->entry->id, true); $body .= "

"; $body .= __('Le media peut être testé sur SCORM Cloud : :url', ['url' => $scormURL]); } diff --git a/app/Jobs/ElearningPackageDownload.php b/app/Jobs/ElearningPackageDownload.php index d5de9a2d8..23b5fcaf0 100644 --- a/app/Jobs/ElearningPackageDownload.php +++ b/app/Jobs/ElearningPackageDownload.php @@ -15,7 +15,7 @@ class ElearningPackageDownload extends DownloadBase { try { $compilepath = $this->entry->getFinalPath(); - $this->entry->compile($compilepath,$this->user); + $this->entry->compile($compilepath, $this->user); $fname = $this->_fname(); $dest = Files::mkdir(storage_path('app/public/elearningpackage/download/')) . $fname; @@ -32,7 +32,7 @@ class ElearningPackageDownload extends DownloadBase try { if ($this->action === 'scormcloud') { - $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->entry->id); + $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->entry->id, true); $body .= "

"; $body .= __('Le package peut être testé sur SCORM Cloud : :url', ['url' => $scormURL]); } diff --git a/app/Jobs/QuizDownload.php b/app/Jobs/QuizDownload.php index 6b149dd0d..f9cd1b039 100644 --- a/app/Jobs/QuizDownload.php +++ b/app/Jobs/QuizDownload.php @@ -32,7 +32,7 @@ class QuizDownload extends DownloadBase try { if ($this->action === 'scormcloud') { - $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->entry->id); + $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->entry->id, true); $body .= "

"; $body .= __('Le package peut être testé sur SCORM Cloud : :url', ['url' => $scormURL]); } diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index dbc03bcbd..9c4206326 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -242,32 +242,6 @@ class Quiz extends ToolboxModel */ public function compile($dest, $forceScorm = false, $user = null) { - /* - - $defaultModuleContent = ['content_title' => '', 'complete_when_opened' => false, 'mandatory' => true, - 'quiz_id' => '', 'fb_id' => '', 'audio_id' => '', 'pdf_id' => '', 'video_id' => '']; - - - - $modules = []; - - foreach ($this->contents as $id => $content) { - $m = $this->_compileModule($id, array_merge($defaultModuleContent, $content), $vdir, $user); - if ($m !== false) { - $modules[] = $m; - } - } - - $data = ['title' => $this->title, 'description' => $this->description, 'modules' => $modules]; - - $vdir->file_put_contents('data.js', 'const DATA=' . json_encode($data) . ';'); - $vdir->file_put_contents('imsmanifest.xml', new Manifest($this->title, Version::SCORM_2004, $organization, 'PACKAGE_' . $this->id)); - $vdir->copyDirectory(resource_path('elearningpackage/dist/css'), 'css'); - $vdir->copyDirectory(resource_path('elearningpackage/dist/js'), 'js'); - $vdir->copyDirectory(resource_path('elearningpackage/dist/fonts'), 'fonts'); - $vdir->copy(resource_path('elearningpackage/index.html'), 'index.html'); - $vdir->sync(true);*/ - $wdir = resource_path('quiz'); $vdir = new VirtualDirectory($dest); diff --git a/resources/elearningpackage/js/app.js b/resources/elearningpackage/js/app.js index 6272b99b2..ec990fc5a 100644 --- a/resources/elearningpackage/js/app.js +++ b/resources/elearningpackage/js/app.js @@ -27,7 +27,7 @@ function initPackage() { return; } - var res=initScorm(); + var res = initScorm(); initState(); setContents(); initEvents(); @@ -72,6 +72,7 @@ function initState() { } }); } + function initEvents() { $(document).on('click', '[data-id]:not([data-lock="locked"])', function () { openSubSCO($(this).data('id')); diff --git a/resources/quiz/js/app.js b/resources/quiz/js/app.js index 76c12af5e..e52db5cf1 100644 --- a/resources/quiz/js/app.js +++ b/resources/quiz/js/app.js @@ -300,9 +300,8 @@ require('../../scorm/scorm'); if ($(next).is("#resultsscreen")) { updateScore(); - console.log(showReview, checkScore()) var show = showReview === 'always' || (showReview === 'passed' && checkScore()); - console.log(showReview, checkScore(), show, score); + if (!show) { $('#correction').hide(); } else { @@ -316,8 +315,7 @@ require('../../scorm/scorm'); resize(); gsap.fromTo($(next), {left: w + 50, opacity: 0}, {duration: 0.5, left: 0, opacity: 1}); gsap.fromTo($(prev), {left: 0, opacity: 1}, { - duration: 0.5, - left: -w - 50, opacity: 0, onComplete: function () { + duration: 0.5, left: -w - 50, opacity: 0, onComplete: function () { $(prev).hide(); endTransition(); } @@ -332,20 +330,29 @@ require('../../scorm/scorm'); function completed() { updateScore(); + var passed = checkScore(); + if (logAttempts) { + logAttempt(passed); + } + if (DATA.scorm) { - setSCORMScore(score, $("section.question").length, 0); - setScormValue('cmi.core.lesson_status', 'completed'); + setScormValue('status', 'completed'); + setScormValue('success_status', passed ? 'passed' : 'failed'); + setSCORMScore(getNormalizedScore(true), 100, 0, getNormalizedScore()); setSCORMLocation({q: 1}); } + } - var passed = checkScore(); - if (logAttempts) { - logAttempt(passed); + function getNormalizedScore(pct) { + var s = score / countQuestions; + if (pct === undefined || pct === false) { + return s; } + return Math.round(100 * s); } function logAttempt(passed) { - var score = Math.round(100 * (score / countQuestions)); + var score = getNormalizedScore(true); if (isNaN(score)) { score = 0; } @@ -353,16 +360,13 @@ require('../../scorm/scorm'); score: score, passed: passed, questions: logQuestions, }; - console.log(logdata); - - $.ajax('https://toolbox.fluidbook.com/quiz/' + DATA.id + '/log', { method: 'POST', data: logdata, crossDomain: true, }); } function checkScore() { - var normalizedScore = score / countQuestions; + var normalizedScore = getNormalizedScore(false); $('#results > h2').hide(); var passed; $('#restart').hide(); diff --git a/resources/scorm/scorm.js b/resources/scorm/scorm.js index 31f8c73ef..0d69b83d4 100644 --- a/resources/scorm/scorm.js +++ b/resources/scorm/scorm.js @@ -34,8 +34,7 @@ window._CMI2004 = { 'exit': 'cmi.exit', }; -window.initScorm=function() -{ +window.initScorm = function () { if (SCORM_INITED) { return; } @@ -97,17 +96,20 @@ window.initScormEvents = function () { }; window.setSCORMLocation = function (location) { - return setScormValue('cmi.location', JSON.stringify(location)); + return setScormValue('location', JSON.stringify(location)); }; -window.setSCORMScore = function (score, max, min) { +window.setSCORMScore = function (score, max, min, scaled) { if (min === undefined) { min = 0; } - setScormValue('cmi.core.score.raw', score); - setScormValue('cmi.core.score.min', min); - setScormValue('cmi.core.score.max', max); + if (scaled !== undefined) { + setScormValue('cmi.score.scaled', scaled); + } + setScormValue('cmi.score.raw', score); + setScormValue('cmi.score.min', min); + setScormValue('cmi.score.max', max); }; window.getScormValue = function (elementName) { if (!SCORM_OK) { @@ -117,10 +119,10 @@ window.getScormValue = function (elementName) { if (cmi == '') { return null; } - return result = SCORM.get(cmi); + return SCORM.get(cmi); }; -window.setScormValue=function(elementName, value) { +window.setScormValue = function (elementName, value) { if (!SCORM_OK) { return; } @@ -133,7 +135,7 @@ window.setScormValue=function(elementName, value) { }; -window.scormMarkAsComplete=function() { +window.scormMarkAsComplete = function () { if (!SCORM_OK) { return; } @@ -141,7 +143,7 @@ window.scormMarkAsComplete=function() { }; -window.finishScorm=function() { +window.finishScorm = function () { if (!SCORM_OK) { return; } -- 2.39.5