Skip to content

Commit 45ac153

Browse files
committed
MOBILE-1710 links: Handle grade.php for quiz and scorm
1 parent ac5e333 commit 45ac153

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

www/addons/mod/quiz/services/handlers.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ angular.module('mm.addons.mod_quiz')
143143
self.linksHandler = function() {
144144

145145
var self = {},
146-
patterns = ['/mod/quiz/view.php', '/mod/quiz/review.php'];
146+
patterns = ['/mod/quiz/view.php', '/mod/quiz/review.php', '/mod/quiz/grade.php'];
147147

148148
/**
149149
* Whether or not the handler is enabled for a certain site.
@@ -245,7 +245,13 @@ angular.module('mm.addons.mod_quiz')
245245
}
246246
});
247247
}
248+
} else if (url.indexOf(patterns[2]) > -1) {
249+
// Quiz grade.
250+
// @todo Go to review user best attempt if it isn't current user.
251+
return $mmContentLinksHelper.treatModuleGradeUrl(siteIds, url, isEnabled, courseId);
248252
}
253+
254+
249255
return $q.when([]);
250256
};
251257

www/addons/mod/scorm/services/handlers.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ angular.module('mm.addons.mod_scorm')
172172
*/
173173
self.linksHandler = function() {
174174

175-
var self = {};
175+
var self = {},
176+
patterns = ['/mod/scorm/view.php', '/mod/scorm/grade.php'];
176177

177178
/**
178179
* Whether or not the handler is enabled for a certain site.
@@ -201,9 +202,15 @@ angular.module('mm.addons.mod_scorm')
201202
*/
202203
self.getActions = function(siteIds, url, courseId) {
203204
// Check it's a SCORM URL.
204-
if (typeof self.handles(url) != 'undefined') {
205+
if (url.indexOf(patterns[0]) > -1) {
206+
// SCORM index.
205207
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
208+
} else if (url.indexOf(patterns[1]) > -1) {
209+
// SCORM grade.
210+
// @todo Go to user attempts list if it isn't current user.
211+
return $mmContentLinksHelper.treatModuleGradeUrl(siteIds, url, isEnabled, courseId);
206212
}
213+
207214
return $q.when([]);
208215
};
209216

@@ -214,9 +221,11 @@ angular.module('mm.addons.mod_scorm')
214221
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
215222
*/
216223
self.handles = function(url) {
217-
var position = url.indexOf('/mod/scorm/view.php');
218-
if (position > -1) {
219-
return url.substr(0, position);
224+
for (var i = 0; i < patterns.length; i++) {
225+
var position = url.indexOf(patterns[i]);
226+
if (position > -1) {
227+
return url.substr(0, position);
228+
}
220229
}
221230
};
222231

www/core/components/contentlinks/services/helper.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,60 @@ angular.module('mm.core.contentlinks')
273273
});
274274
};
275275

276+
/**
277+
* Treats a module grade URL (grade.php).
278+
*
279+
* @module mm.core.contentlinks
280+
* @ngdoc method
281+
* @name $mmContentLinksHelper#treatModuleGradeUrl
282+
* @param {String[]} siteIds Site IDs the URL belongs to.
283+
* @param {String} url URL to treat.
284+
* @param {Function} isEnabled Function to check if the module is enabled. @see $mmContentLinksHelper#filterSupportedSites.
285+
* @param {Number} [courseId] Course ID related to the URL.
286+
* @param {Function} [gotoReview] Function to go to review page if user is not current user.
287+
* @return {Promise} Promise resolved with the list of actions.
288+
*/
289+
self.treatModuleGradeUrl = function(siteIds, url, isEnabled, courseId, gotoReview) {
290+
var params = $mmUtil.extractUrlParams(url);
291+
if (typeof params.id != 'undefined') {
292+
// If courseId is not set we check if it's set in the URL as a param.
293+
courseId = courseId || params.courseid || params.cid;
294+
295+
// Pass false because all sites should have the same siteurl.
296+
return self.filterSupportedSites(siteIds, isEnabled, false, courseId).then(function(ids) {
297+
if (!ids.length) {
298+
return [];
299+
} else {
300+
// Return actions.
301+
return [{
302+
message: 'mm.core.view',
303+
icon: 'ion-eye',
304+
sites: ids,
305+
action: function(siteId) {
306+
// Check if userid is the site's current user.
307+
var modal = $mmUtil.showModalLoading();
308+
$mmSitesManager.getSite(siteId).then(function(site) {
309+
if (!params.userid || params.userid == site.getUserId()) {
310+
// No user specified or current user. Navigate to module.
311+
$mmCourseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId);
312+
} else if (angular.isFunction(gotoReview)) {
313+
// gotoReview function is defined, use it.
314+
gotoReview(url, params, courseId, siteId);
315+
} else {
316+
// Not current user and no gotoReview function specified, open it in browser.
317+
$mmUtil.openInBrowser(url);
318+
}
319+
}).finally(function() {
320+
modal.dismiss();
321+
});
322+
}
323+
}];
324+
}
325+
});
326+
}
327+
return $q.when([]);
328+
};
329+
276330
/**
277331
* Treats a URL that belongs to a module's index page.
278332
*

0 commit comments

Comments
 (0)