Skip to content

Commit a7e4302

Browse files
committed
MOBILE-1357 courses: Add view.php to courses link handler
1 parent 8c920a7 commit a7e4302

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

www/core/components/courses/services/handlers.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ angular.module('mm.core.courses')
2121
* @ngdoc service
2222
* @name $mmCoursesHandlers
2323
*/
24-
.factory('$mmCoursesHandlers', function($mmSite, $state, $mmCourses, $q, $mmUtil, $translate, $timeout, mmCoursesEnrolInvalidKey) {
24+
.factory('$mmCoursesHandlers', function($mmSite, $state, $mmCourses, $q, $mmUtil, $translate, $timeout, $mmContentLinksHelper,
25+
mmCoursesEnrolInvalidKey) {
2526

2627
var self = {};
2728

@@ -167,22 +168,24 @@ angular.module('mm.core.courses')
167168
* @return {Object[]} List of actions. See {@link $mmContentLinksDelegate#registerLinkHandler}.
168169
*/
169170
self.getActions = function(url, courseId) {
170-
// Check if URL belongs to the current site.
171-
if ($mmSite.containsUrl(url)) {
172-
// Check if it's a course enrol URL.
173-
if (url.indexOf('enrol/index.php') > -1 || url.indexOf('course/enrol.php') > -1) {
174-
var matches = url.match(/\.php\?id=(\d*)/); // Get course ID.
175-
if (matches && typeof matches[1] != 'undefined') {
176-
courseId = matches[1];
177-
// Return actions.
178-
return [{
179-
message: 'mm.core.view',
180-
icon: 'ion-eye',
181-
action: function() {
182-
actionEnrol(courseId, url);
171+
// Check if it's a course URL.
172+
if (url.indexOf('enrol/index.php') > -1 || url.indexOf('course/enrol.php') > -1 ||
173+
url.indexOf('course/view.php') > -1) {
174+
var params = $mmUtil.extractUrlParams(url);
175+
if (typeof params.id != 'undefined') {
176+
// Return actions.
177+
return [{
178+
message: 'mm.core.view',
179+
icon: 'ion-eye',
180+
action: function(siteId) {
181+
siteId = siteId || $mmSite.getId();
182+
if (siteId == $mmSite.getId()) {
183+
actionEnrol(parseInt(params.id, 10), url);
184+
} else {
185+
$mmContentLinksHelper.goInSite('site.mm_course', {courseid: parseInt(params.id, 10)}, siteId);
183186
}
184-
}];
185-
}
187+
}
188+
}];
186189
}
187190
}
188191
return [];

0 commit comments

Comments
 (0)