Skip to content

Commit

Permalink
Merge pull request #527 from dpalou/MOBILE-1650
Browse files Browse the repository at this point in the history
MOBILE-1650 completion: Fix scorm and quiz completion check
  • Loading branch information
jleyva authored Jun 13, 2016
2 parents 8c0a714 + 20fac49 commit 95d28f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
6 changes: 3 additions & 3 deletions www/addons/mod/quiz/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down
26 changes: 10 additions & 16 deletions www/addons/mod/scorm/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -279,15 +283,15 @@ angular.module('mm.addons.mod_scorm')
}

// Refreshes data.
function refreshData(dontForceSync) {
function refreshData(dontForceSync, checkCompletion) {
var promises = [];
promises.push($mmaModScorm.invalidateScormData(courseid));
if (scorm) {
promises.push($mmaModScorm.invalidateAllScormData(scorm.id));
}

return $q.all(promises).finally(function() {
return fetchScormData(!dontForceSync);
return fetchScormData(!dontForceSync, checkCompletion);
});
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
Expand All @@ -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);
}
}
});

Expand Down

0 comments on commit 95d28f0

Please sign in to comment.