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
8 changes: 7 additions & 1 deletion www/addons/mod/quiz/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ angular.module('mm.addons.mod_quiz')
self.linksHandler = function() {

var self = {},
patterns = ['/mod/quiz/view.php', '/mod/quiz/review.php'];
patterns = ['/mod/quiz/view.php', '/mod/quiz/review.php', '/mod/quiz/grade.php'];

/**
* Whether or not the handler is enabled for a certain site.
Expand Down Expand Up @@ -245,7 +245,13 @@ angular.module('mm.addons.mod_quiz')
}
});
}
} else if (url.indexOf(patterns[2]) > -1) {
// Quiz grade.
// @todo Go to review user best attempt if it isn't current user.
return $mmContentLinksHelper.treatModuleGradeUrl(siteIds, url, isEnabled, courseId);
}


return $q.when([]);
};

Expand Down
19 changes: 14 additions & 5 deletions www/addons/mod/scorm/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ angular.module('mm.addons.mod_scorm')
*/
self.linksHandler = function() {

var self = {};
var self = {},
patterns = ['/mod/scorm/view.php', '/mod/scorm/grade.php'];

/**
* Whether or not the handler is enabled for a certain site.
Expand Down Expand Up @@ -201,9 +202,15 @@ angular.module('mm.addons.mod_scorm')
*/
self.getActions = function(siteIds, url, courseId) {
// Check it's a SCORM URL.
if (typeof self.handles(url) != 'undefined') {
if (url.indexOf(patterns[0]) > -1) {
// SCORM index.
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
} else if (url.indexOf(patterns[1]) > -1) {
// SCORM grade.
// @todo Go to user attempts list if it isn't current user.
return $mmContentLinksHelper.treatModuleGradeUrl(siteIds, url, isEnabled, courseId);
}

return $q.when([]);
};

Expand All @@ -214,9 +221,11 @@ angular.module('mm.addons.mod_scorm')
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
*/
self.handles = function(url) {
var position = url.indexOf('/mod/scorm/view.php');
if (position > -1) {
return url.substr(0, position);
for (var i = 0; i < patterns.length; i++) {
var position = url.indexOf(patterns[i]);
if (position > -1) {
return url.substr(0, position);
}
}
};

Expand Down
54 changes: 54 additions & 0 deletions www/core/components/contentlinks/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,60 @@ angular.module('mm.core.contentlinks')
});
};

/**
* Treats a module grade URL (grade.php).
*
* @module mm.core.contentlinks
* @ngdoc method
* @name $mmContentLinksHelper#treatModuleGradeUrl
* @param {String[]} siteIds Site IDs the URL belongs to.
* @param {String} url URL to treat.
* @param {Function} isEnabled Function to check if the module is enabled. @see $mmContentLinksHelper#filterSupportedSites.
* @param {Number} [courseId] Course ID related to the URL.
* @param {Function} [gotoReview] Function to go to review page if user is not current user.
* @return {Promise} Promise resolved with the list of actions.
*/
self.treatModuleGradeUrl = function(siteIds, url, isEnabled, courseId, gotoReview) {
var params = $mmUtil.extractUrlParams(url);
if (typeof params.id != 'undefined') {
// If courseId is not set we check if it's set in the URL as a param.
courseId = courseId || params.courseid || params.cid;

// Pass false because all sites should have the same siteurl.
return self.filterSupportedSites(siteIds, isEnabled, false, courseId).then(function(ids) {
if (!ids.length) {
return [];
} else {
// Return actions.
return [{
message: 'mm.core.view',
icon: 'ion-eye',
sites: ids,
action: function(siteId) {
// Check if userid is the site's current user.
var modal = $mmUtil.showModalLoading();
$mmSitesManager.getSite(siteId).then(function(site) {
if (!params.userid || params.userid == site.getUserId()) {
// No user specified or current user. Navigate to module.
$mmCourseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId);
} else if (angular.isFunction(gotoReview)) {
// gotoReview function is defined, use it.
gotoReview(url, params, courseId, siteId);
} else {
// Not current user and no gotoReview function specified, open it in browser.
$mmUtil.openInBrowser(url);
}
}).finally(function() {
modal.dismiss();
});
}
}];
}
});
}
return $q.when([]);
};

/**
* Treats a URL that belongs to a module's index page.
*
Expand Down