Commit | Line | Data |
---|---|---|
2c1d19fd RW |
1 | // This file is part of Moodle - http://moodle.org/ |
2 | // | |
3 | // Moodle is free software: you can redistribute it and/or modify | |
4 | // it under the terms of the GNU General Public License as published by | |
5 | // the Free Software Foundation, either version 3 of the License, or | |
6 | // (at your option) any later version. | |
7 | // | |
8 | // Moodle is distributed in the hope that it will be useful, | |
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | // GNU General Public License for more details. | |
12 | // | |
13 | // You should have received a copy of the GNU General Public License | |
14 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | /** | |
17 | * A javascript module to handle course ajax actions. | |
18 | * | |
19 | * @module core_course/repository | |
20 | * @copyright 2018 Ryan Wyllie <ryan@moodle.com> | |
21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
22 | */ | |
23 | define(['jquery', 'core/ajax'], function($, Ajax) { | |
24 | ||
25 | /** | |
26 | * Get the list of courses that the logged in user is enrolled in for a given | |
27 | * timeline classification. | |
28 | * | |
29 | * @param {string} classification past, inprogress, or future | |
30 | * @param {int} limit Only return this many results | |
31 | * @param {int} offset Skip this many results from the start of the result set | |
32 | * @param {string} sort Column to sort by and direction, e.g. 'shortname asc' | |
33 | * @return {object} jQuery promise resolved with courses. | |
34 | */ | |
35 | var getEnrolledCoursesByTimelineClassification = function(classification, limit, offset, sort) { | |
36 | var args = { | |
37 | classification: classification | |
38 | }; | |
39 | ||
40 | if (typeof limit !== 'undefined') { | |
41 | args.limit = limit; | |
42 | } | |
43 | ||
44 | if (typeof offset !== 'undefined') { | |
45 | args.offset = offset; | |
46 | } | |
47 | ||
48 | if (typeof sort !== 'undefined') { | |
49 | args.sort = sort; | |
50 | } | |
51 | ||
52 | var request = { | |
53 | methodname: 'core_course_get_enrolled_courses_by_timeline_classification', | |
54 | args: args | |
55 | }; | |
56 | ||
57 | return Ajax.call([request])[0]; | |
58 | }; | |
59 | ||
98a52c80 VD |
60 | /** |
61 | * Get the list of courses that the user has most recently accessed. | |
62 | * | |
63 | * @method getLastAccessedCourses | |
64 | * @param {int} userid User from which the courses will be obtained | |
65 | * @param {int} limit Only return this many results | |
66 | * @param {int} offset Skip this many results from the start of the result set | |
67 | * @param {string} sort Column to sort by and direction, e.g. 'shortname asc' | |
68 | * @return {promise} Resolved with an array of courses | |
69 | */ | |
70 | var getLastAccessedCourses = function(userid, limit, offset, sort) { | |
71 | var args = {}; | |
72 | ||
73 | if (typeof userid !== 'undefined') { | |
85d142f5 | 74 | args.userid = userid; |
98a52c80 VD |
75 | } |
76 | ||
77 | if (typeof limit !== 'undefined') { | |
78 | args.limit = limit; | |
79 | } | |
80 | ||
81 | if (typeof offset !== 'undefined') { | |
82 | args.offset = offset; | |
83 | } | |
84 | ||
85 | if (typeof sort !== 'undefined') { | |
86 | args.sort = sort; | |
87 | } | |
88 | ||
89 | var request = { | |
90 | methodname: 'core_course_get_recent_courses', | |
91 | args: args | |
92 | }; | |
93 | ||
94 | return Ajax.call([request])[0]; | |
95 | }; | |
96 | ||
06e50afd MM |
97 | /** |
98 | * Get the list of users enrolled in this cmid. | |
99 | * | |
100 | * @param {Number} cmid Course Module from which the users will be obtained | |
e3bb3da4 | 101 | * @param {Number} groupID Group ID from which the users will be obtained |
06e50afd MM |
102 | * @returns {Promise} Promise containing a list of users |
103 | */ | |
e3bb3da4 | 104 | var getEnrolledUsersFromCourseModuleID = function(cmid, groupID) { |
06e50afd MM |
105 | var request = { |
106 | methodname: 'core_course_get_enrolled_users_by_cmid', | |
107 | args: { | |
108 | cmid: cmid, | |
e3bb3da4 | 109 | groupid: groupID, |
06e50afd MM |
110 | }, |
111 | }; | |
112 | ||
113 | return Ajax.call([request])[0]; | |
114 | }; | |
115 | ||
2c1d19fd | 116 | return { |
98a52c80 | 117 | getEnrolledCoursesByTimelineClassification: getEnrolledCoursesByTimelineClassification, |
06e50afd MM |
118 | getLastAccessedCourses: getLastAccessedCourses, |
119 | getUsersFromCourseModuleID: getEnrolledUsersFromCourseModuleID, | |
2c1d19fd RW |
120 | }; |
121 | }); |