From 20fac49a3ca5aefcf301d9bbcdccbdb51a2686e6 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 13 Jun 2016 13:21:48 +0200 Subject: [PATCH] MOBILE-1650 completion: Fix scorm and quiz completion check --- www/addons/mod/quiz/controllers/index.js | 6 +++--- www/addons/mod/scorm/controllers/index.js | 26 +++++++++-------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/www/addons/mod/quiz/controllers/index.js b/www/addons/mod/quiz/controllers/index.js index 81da76485a9..c0fc1c426a4 100644 --- a/www/addons/mod/quiz/controllers/index.js +++ b/www/addons/mod/quiz/controllers/index.js @@ -339,6 +339,9 @@ angular.module('mm.addons.mod_quiz') // Go to review an attempt that has just been finished. function goToAutoReview() { + // If we go to auto review it means an attempt was finished. Check completion status. + $mmCourse.checkModuleCompletion(courseId, module.completionstatus); + // Verify that user can see the review. var attemptId = autoReview.attemptId; if (quizAccessInfo.canreviewmyattempts) { @@ -349,9 +352,6 @@ angular.module('mm.addons.mod_quiz') }); } - // If we go to auto review it means an attempt was finished. Check completion status. - $mmCourse.checkModuleCompletion(courseId, module.completionstatus); - return $q.when(); } diff --git a/www/addons/mod/scorm/controllers/index.js b/www/addons/mod/scorm/controllers/index.js index 0745da8d25d..e98b14ec31c 100644 --- a/www/addons/mod/scorm/controllers/index.js +++ b/www/addons/mod/scorm/controllers/index.js @@ -48,7 +48,7 @@ angular.module('mm.addons.mod_scorm') $scope.modebrowse = $mmaModScorm.MODEBROWSE; // Convenience function to get SCORM data. - function fetchScormData(refresh) { + function fetchScormData(refresh, checkCompletion) { return $mmaModScorm.getScorm(courseid, module.id, module.url).then(function(scormData) { scorm = scormData; @@ -76,6 +76,10 @@ angular.module('mm.addons.mod_scorm') $scope.syncTime = syncTime; }); + if (checkCompletion) { + $mmCourse.checkModuleCompletion(courseid, module.completionstatus); + } + // Get the number of attempts and check if SCORM is incomplete. return $mmaModScorm.getAttemptCount(scorm.id).then(function(attemptsData) { attempts = attemptsData; @@ -279,7 +283,7 @@ angular.module('mm.addons.mod_scorm') } // Refreshes data. - function refreshData(dontForceSync) { + function refreshData(dontForceSync, checkCompletion) { var promises = []; promises.push($mmaModScorm.invalidateScormData(courseid)); if (scorm) { @@ -287,7 +291,7 @@ angular.module('mm.addons.mod_scorm') } return $q.all(promises).finally(function() { - return fetchScormData(!dontForceSync); + return fetchScormData(!dontForceSync, checkCompletion); }); } @@ -339,11 +343,6 @@ angular.module('mm.addons.mod_scorm') if (message) { $mmUtil.showErrorModal(message); } - - if (data.attemptFinished) { - // An attempt was finished, check completion status. - $mmCourse.checkModuleCompletion(courseid, module.completionstatus); - } } }).catch(function(err) { if (showErrors) { @@ -416,7 +415,7 @@ angular.module('mm.addons.mod_scorm') // Refresh the data. $scope.scormLoaded = false; scrollView.scrollTop(); - refreshData(true).finally(function() { + refreshData(true, true).finally(function() { $scope.scormLoaded = true; }); }).finally(function() { @@ -441,7 +440,7 @@ angular.module('mm.addons.mod_scorm') scrollView.scrollTop(); // Add a delay to make sure the player has started the last writing calls so we can detect conflicts. $timeout(function() { - refreshData().finally(function() { + refreshData(false, true).finally(function() { $scope.scormLoaded = true; }); }, 500); @@ -453,14 +452,9 @@ angular.module('mm.addons.mod_scorm') if (data && data.siteid == $mmSite.getId() && data.scormid == scorm.id) { $scope.scormLoaded = false; scrollView.scrollTop(); - fetchScormData().finally(function() { + fetchScormData(false, true).finally(function() { $scope.scormLoaded = true; }); - - if (data.attemptFinished) { - // An attempt was finished, check completion status. - $mmCourse.checkModuleCompletion(courseid, module.completionstatus); - } } });