Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
This files describes API changes in the Moodle Mobile app,
information provided here is intended especially for developers.

=== 3.1.0 ===

* A new param "single" is passed to the prefetch functions of handlers registered in $mmCoursePrefetchDelegateProvider. Please notice that the download of sections will always send false/undefined, if you use this function somewhere else to download a single module then you should pass single=true.

=== 3.0 ===

* The function $mmaModBook#getChapterContent now requires to receive the result of $mmaModBook#getContentsMap instead of module.contents.
Expand Down
8 changes: 5 additions & 3 deletions www/addons/mod_book/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ angular.module('mm.addons.mod_book')
* @module mm.addons.mod_book
* @ngdoc method
* @name $mmaModBookPrefetchHandler#prefetch
* @param {Object} module The module object returned by WS.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
* @param {Object} module The module object returned by WS.
* @param {Number} courseId Course ID the module belongs to.
* @param {Boolean} single True if we're downloading a single module, false if we're downloading a whole section.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
*/
self.prefetch = function(module) {
self.prefetch = function(module, courseId, single) {
return $mmaModBook.prefetchContent(module);
};

Expand Down
8 changes: 5 additions & 3 deletions www/addons/mod_folder/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ angular.module('mm.addons.mod_folder')
* @module mm.addons.mod_folder
* @ngdoc method
* @name $mmaModFolderPrefetchHandler#prefetch
* @param {Object} module The module object returned by WS.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
* @param {Object} module The module object returned by WS.
* @param {Number} courseId Course ID the module belongs to.
* @param {Boolean} single True if we're downloading a single module, false if we're downloading a whole section.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
*/
self.prefetch = function(module) {
self.prefetch = function(module, courseId, single) {
return $mmaModFolder.prefetchContent(module);
};

Expand Down
8 changes: 5 additions & 3 deletions www/addons/mod_imscp/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ angular.module('mm.addons.mod_imscp')
* @module mm.addons.mod_imscp
* @ngdoc method
* @name $mmaModImscpPrefetchHandler#prefetch
* @param {Object} module The module object returned by WS.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
* @param {Object} module The module object returned by WS.
* @param {Number} courseId Course ID the module belongs to.
* @param {Boolean} single True if we're downloading a single module, false if we're downloading a whole section.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
*/
self.prefetch = function(module) {
self.prefetch = function(module, courseId, single) {
return $mmaModImscp.prefetchContent(module);
};

Expand Down
8 changes: 5 additions & 3 deletions www/addons/mod_page/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ angular.module('mm.addons.mod_page')
* @module mm.addons.mod_page
* @ngdoc method
* @name $mmaModPagePrefetchHandler#prefetch
* @param {Object} module The module object returned by WS.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
* @param {Object} module The module object returned by WS.
* @param {Number} courseId Course ID the module belongs to.
* @param {Boolean} single True if we're downloading a single module, false if we're downloading a whole section.
* @return {Promise} Promise resolved when all files have been downloaded. Data returned is not reliable.
*/
self.prefetch = function(module) {
self.prefetch = function(module, courseId, single) {
return $mmaModPage.prefetchContent(module);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
return false;
};

Expand Down
5 changes: 4 additions & 1 deletion www/addons/mod_quiz/accessrules/ipaddress/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
return false;
};

Expand Down
5 changes: 4 additions & 1 deletion www/addons/mod_quiz/accessrules/numattempts/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
return false;
};

Expand Down
17 changes: 12 additions & 5 deletions www/addons/mod_quiz/accessrules/offlineattempts/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
if (prefetch) {
return false;
}

if (!attempt) {
return true;
}
Expand All @@ -52,14 +59,14 @@ angular.module('mm.addons.mod_quiz')
/**
* Get fixed preflight data (data that doesn't require user interaction).
*
* @module mm.addons.mod_quiz
* @ngdoc method
* @name $mmaModQuizAccessRulesDelegate#getFixedPreflightData
* @param {Object} quiz Quiz.
* @param {Object} attempt Attempt.
* @param {Object} preflightData Object where to store the preflight data.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Void}
*/
self.getFixedPreflightData = function(attempt, preflightData) {
self.getFixedPreflightData = function(quiz, attempt, preflightData, prefetch, siteId) {
preflightData.confirmdatasaved = 1;
};

Expand Down
5 changes: 4 additions & 1 deletion www/addons/mod_quiz/accessrules/openclosedate/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
return false;
};

Expand Down
140 changes: 135 additions & 5 deletions www/addons/mod_quiz/accessrules/password/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
// limitations under the License.

angular.module('mm.addons.mod_quiz')
.constant('mmaModQuizAccessPasswordStore', 'mod_quiz_access_password')

.config(function($mmSitesFactoryProvider, mmaModQuizAccessPasswordStore) {
var stores = [
{
name: mmaModQuizAccessPasswordStore,
keyPath: 'id',
indexes: []
}
];
$mmSitesFactoryProvider.registerStores(stores);
})

/**
* Handler for password quiz access rule.
Expand All @@ -21,7 +33,7 @@ angular.module('mm.addons.mod_quiz')
* @ngdoc service
* @name $mmaQuizAccessPasswordHandler
*/
.factory('$mmaQuizAccessPasswordHandler', function() {
.factory('$mmaQuizAccessPasswordHandler', function($mmSitesManager, $mmSite, $q, mmaModQuizAccessPasswordStore) {

var self = {};

Expand All @@ -34,6 +46,80 @@ angular.module('mm.addons.mod_quiz')
delete data.quizpassword;
};

/**
* Get a password stored in DB.
*
* @param {Number} quizId Quiz ID.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved with password on success, rejected otherwise.
*/
function getPasswordEntry(quizId, siteId) {
siteId = siteId || $mmSite.getId();

return $mmSitesManager.getSite(siteId).then(function(site) {
return site.getDb().get(mmaModQuizAccessPasswordStore, quizId);
});
}

/**
* Remove a password from DB.
*
* @param {Number} quizId Quiz ID.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved on success, rejected otherwise.
*/
function removePassword(quizId, siteId) {
siteId = siteId || $mmSite.getId();

return $mmSitesManager.getSite(siteId).then(function(site) {
return site.getDb().remove(mmaModQuizAccessPasswordStore, quizId);
});
}

/**
* Store a password in DB.
*
* @param {Number} quizId Quiz ID.
* @param {String} password Password.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved on success, rejected otherwise.
*/
function storePassword(quizId, password, siteId) {
siteId = siteId || $mmSite.getId();

return $mmSitesManager.getSite(siteId).then(function(site) {
var entry = {
id: quizId,
password: password,
timemodified: new Date().getTime()
};

return site.getDb().insert(mmaModQuizAccessPasswordStore, entry);
});
}

/**
* Get fixed preflight data (data that doesn't require user interaction).
*
* @param {Object} quiz Quiz.
* @param {Object} attempt Attempt.
* @param {Object} preflightData Object where to store the preflight data.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved when preflight data has been added.
*/
self.getFixedPreflightData = function(quiz, attempt, preflightData, prefetch, siteId) {
if (quiz && quiz.id && typeof preflightData.quizpassword == 'undefined') {
return getPasswordEntry(quiz.id, siteId).then(function(entry) {
preflightData.quizpassword = entry.password;
}).catch(function() {
// Don't reject.
});
}

return $q.when();
};

/**
* Whether or not the rule is enabled for the site.
*
Expand All @@ -46,12 +132,20 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @return {Boolean} True if preflight check required.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved with a boolean: true if preflight check required, false otherwise.
*/
self.isPreflightCheckRequired = function(attempt) {
// If the password rule is active in a quiz we always require to input the password.
return true;
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
// Check if we have a password stored.
return getPasswordEntry(quiz.id, siteId).then(function() {
return false;
}).catch(function() {
// Not stored.
return true;
});
};

/**
Expand All @@ -63,6 +157,42 @@ angular.module('mm.addons.mod_quiz')
return 'mma-quiz-access-password-preflight';
};

/**
* The preflight check has passed. This is a chance to record that fact in some way.
*
* @param {Object} quiz Quiz.
* @param {Object} attempt Attempt.
* @param {Object} preflightData Object where to store the preflight data.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved when done.
*/
self.notifyPreflightCheckPassed = function(quiz, attempt, preflightData, prefetch, siteId) {
if (quiz && quiz.id && typeof preflightData.quizpassword != 'undefined') {
return storePassword(quiz.id, preflightData.quizpassword, siteId);
}

return $q.when();
};

/**
* The preflight check has failed.
*
* @param {Object} quiz Quiz.
* @param {Object} attempt Attempt.
* @param {Object} preflightData Object where to store the preflight data.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved when done.
*/
self.notifyPreflightCheckFailed = function(quiz, attempt, preflightData, prefetch, siteId) {
if (quiz && quiz.id) {
return removePassword(quiz.id, siteId);
}

return $q.when();
};

return self;
})

Expand Down
5 changes: 4 additions & 1 deletion www/addons/mod_quiz/accessrules/safebrowser/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
return false;
};

Expand Down
5 changes: 4 additions & 1 deletion www/addons/mod_quiz/accessrules/securewindow/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
return false;
};

Expand Down
6 changes: 5 additions & 1 deletion www/addons/mod_quiz/accessrules/timelimit/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ angular.module('mm.addons.mod_quiz')
/**
* Check if a preflight check is required.
*
* @param {Object} quiz Quiz.
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
* @param {Boolean} prefetch True if prefetching, false if attempting the quiz.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Boolean} True if preflight check required.
*/
self.isPreflightCheckRequired = function(attempt) {
self.isPreflightCheckRequired = function(quiz, attempt, prefetch, siteId) {
// Warning only required if the attempt is not already started.
// prefetch should always be false since offline isn't compatible with timed quizzes.
return !attempt;
};

Expand Down
Loading