1 |
efrain |
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 |
|
|
|
24 |
import Ajax from 'core/ajax';
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Get the list of courses that the logged in user is enrolled in for a given
|
|
|
28 |
* timeline classification.
|
|
|
29 |
*
|
|
|
30 |
* @param {string} classification past, inprogress, or future
|
|
|
31 |
* @param {int} limit Only return this many results
|
|
|
32 |
* @param {int} offset Skip this many results from the start of the result set
|
|
|
33 |
* @param {string} sort Column to sort by and direction, e.g. 'shortname asc'
|
|
|
34 |
* @return {object} jQuery promise resolved with courses.
|
|
|
35 |
*/
|
|
|
36 |
const getEnrolledCoursesByTimelineClassification = (classification, limit, offset, sort) => {
|
|
|
37 |
const args = {
|
|
|
38 |
classification: classification
|
|
|
39 |
};
|
|
|
40 |
|
|
|
41 |
if (typeof limit !== 'undefined') {
|
|
|
42 |
args.limit = limit;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
if (typeof offset !== 'undefined') {
|
|
|
46 |
args.offset = offset;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
if (typeof sort !== 'undefined') {
|
|
|
50 |
args.sort = sort;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
const request = {
|
|
|
54 |
methodname: 'core_course_get_enrolled_courses_by_timeline_classification',
|
|
|
55 |
args: args
|
|
|
56 |
};
|
|
|
57 |
|
|
|
58 |
return Ajax.call([request])[0];
|
|
|
59 |
};
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Get a list of courses that the logged in user is enrolled in, where they have at least one action event,
|
|
|
63 |
* for a given timeline classification.
|
|
|
64 |
*
|
|
|
65 |
* @param {string} classification past, inprogress, or future
|
|
|
66 |
* @param {int} limit The maximum number of courses to return
|
|
|
67 |
* @param {int} offset Skip this many results from the start of the result set
|
|
|
68 |
* @param {string} sort Column to sort by and direction, e.g. 'shortname asc'
|
|
|
69 |
* @param {string} searchValue Optional text search value
|
|
|
70 |
* @param {int} eventsFrom Optional start timestamp (inclusive) that the course should have event(s) in
|
|
|
71 |
* @param {int} eventsTo Optional end timestamp (inclusive) that the course should have event(s) in
|
|
|
72 |
* @return {object} jQuery promise resolved with courses.
|
|
|
73 |
*/
|
|
|
74 |
const getEnrolledCoursesWithEventsByTimelineClassification = (classification, limit = 0, offset = 0, sort = null,
|
|
|
75 |
searchValue = null, eventsFrom = null, eventsTo = null) => {
|
|
|
76 |
|
|
|
77 |
const args = {
|
|
|
78 |
classification: classification,
|
|
|
79 |
limit: limit,
|
|
|
80 |
offset: offset,
|
|
|
81 |
sort: sort,
|
|
|
82 |
eventsfrom: eventsFrom,
|
|
|
83 |
eventsto: eventsTo,
|
|
|
84 |
searchvalue: searchValue,
|
|
|
85 |
};
|
|
|
86 |
|
|
|
87 |
const request = {
|
|
|
88 |
methodname: 'core_course_get_enrolled_courses_with_action_events_by_timeline_classification',
|
|
|
89 |
args: args
|
|
|
90 |
};
|
|
|
91 |
|
|
|
92 |
return Ajax.call([request])[0];
|
|
|
93 |
};
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Get the list of courses that the user has most recently accessed.
|
|
|
97 |
*
|
|
|
98 |
* @method getLastAccessedCourses
|
|
|
99 |
* @param {int} userid User from which the courses will be obtained
|
|
|
100 |
* @param {int} limit Only return this many results
|
|
|
101 |
* @param {int} offset Skip this many results from the start of the result set
|
|
|
102 |
* @param {string} sort Column to sort by and direction, e.g. 'shortname asc'
|
|
|
103 |
* @return {promise} Resolved with an array of courses
|
|
|
104 |
*/
|
|
|
105 |
const getLastAccessedCourses = (userid, limit, offset, sort) => {
|
|
|
106 |
const args = {};
|
|
|
107 |
|
|
|
108 |
if (typeof userid !== 'undefined') {
|
|
|
109 |
args.userid = userid;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
if (typeof limit !== 'undefined') {
|
|
|
113 |
args.limit = limit;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
if (typeof offset !== 'undefined') {
|
|
|
117 |
args.offset = offset;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
if (typeof sort !== 'undefined') {
|
|
|
121 |
args.sort = sort;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
const request = {
|
|
|
125 |
methodname: 'core_course_get_recent_courses',
|
|
|
126 |
args: args
|
|
|
127 |
};
|
|
|
128 |
|
|
|
129 |
return Ajax.call([request])[0];
|
|
|
130 |
};
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
* Get the list of users enrolled in this cmid.
|
|
|
134 |
*
|
|
|
135 |
* @param {Number} cmid Course Module from which the users will be obtained
|
|
|
136 |
* @param {Number} groupID Group ID from which the users will be obtained
|
|
|
137 |
* @param {Boolean} onlyActive Whether to fetch only the active enrolled users or all enrolled users in the course.
|
|
|
138 |
* @returns {Promise} Promise containing a list of users
|
|
|
139 |
*/
|
|
|
140 |
const getEnrolledUsersFromCourseModuleID = (cmid, groupID, onlyActive = false) => {
|
|
|
141 |
var request = {
|
|
|
142 |
methodname: 'core_course_get_enrolled_users_by_cmid',
|
|
|
143 |
args: {
|
|
|
144 |
cmid: cmid,
|
|
|
145 |
groupid: groupID,
|
|
|
146 |
onlyactive: onlyActive,
|
|
|
147 |
},
|
|
|
148 |
};
|
|
|
149 |
|
|
|
150 |
return Ajax.call([request])[0];
|
|
|
151 |
};
|
|
|
152 |
|
|
|
153 |
/**
|
|
|
154 |
* Get the list of gradable users enrolled in this course.
|
|
|
155 |
*
|
|
|
156 |
* @param {Number} courseid Course ID from which the users will be obtained
|
|
|
157 |
* @param {Number} groupID Group ID from which the users will be obtained
|
|
|
158 |
* @param {Boolean} onlyActive Whether to fetch only the active enrolled users or all enrolled users in the course.
|
|
|
159 |
* @returns {Promise} Promise containing a list of users
|
|
|
160 |
*/
|
|
|
161 |
const getGradabaleUsersFromCourseID = (courseid, groupID, onlyActive = false) => {
|
|
|
162 |
const request = {
|
|
|
163 |
methodname: 'core_grades_get_gradable_users',
|
|
|
164 |
args: {
|
|
|
165 |
courseid: courseid,
|
|
|
166 |
groupid: groupID,
|
|
|
167 |
onlyactive: onlyActive,
|
|
|
168 |
},
|
|
|
169 |
};
|
|
|
170 |
|
|
|
171 |
return Ajax.call([request])[0];
|
|
|
172 |
};
|
|
|
173 |
|
|
|
174 |
/**
|
|
|
175 |
* Toggle the completion state of an activity with manual completion.
|
|
|
176 |
*
|
|
|
177 |
* @param {Number} cmid The course module ID.
|
|
|
178 |
* @param {Boolean} completed Whether to set as complete or not.
|
|
|
179 |
* @returns {object} jQuery promise
|
|
|
180 |
*/
|
|
|
181 |
const toggleManualCompletion = (cmid, completed) => {
|
|
|
182 |
const request = {
|
|
|
183 |
methodname: 'core_completion_update_activity_completion_status_manually',
|
|
|
184 |
args: {
|
|
|
185 |
cmid,
|
|
|
186 |
completed,
|
|
|
187 |
}
|
|
|
188 |
};
|
|
|
189 |
return Ajax.call([request])[0];
|
|
|
190 |
};
|
|
|
191 |
|
|
|
192 |
export default {
|
|
|
193 |
getEnrolledCoursesByTimelineClassification,
|
|
|
194 |
getLastAccessedCourses,
|
|
|
195 |
getUsersFromCourseModuleID: getEnrolledUsersFromCourseModuleID,
|
|
|
196 |
getGradableUsersFromCourseID: getGradabaleUsersFromCourseID,
|
|
|
197 |
toggleManualCompletion,
|
|
|
198 |
getEnrolledCoursesWithEventsByTimelineClassification,
|
|
|
199 |
};
|