1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * A javascript module to handle course ajax actions.
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
23 define(['jquery', 'core/ajax'], function($, Ajax) {
26 * Get the list of courses that the logged in user is enrolled in for a given
27 * timeline classification.
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.
35 var getEnrolledCoursesByTimelineClassification = function(classification, limit, offset, sort) {
37 classification: classification
40 if (typeof limit !== 'undefined') {
44 if (typeof offset !== 'undefined') {
48 if (typeof sort !== 'undefined') {
53 methodname: 'core_course_get_enrolled_courses_by_timeline_classification',
57 return Ajax.call([request])[0];
61 * Get the list of courses that the user has most recently accessed.
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
70 var getLastAccessedCourses = function(userid, limit, offset, sort) {
73 if (typeof userid !== 'undefined') {
77 if (typeof limit !== 'undefined') {
81 if (typeof offset !== 'undefined') {
85 if (typeof sort !== 'undefined') {
90 methodname: 'core_course_get_recent_courses',
94 return Ajax.call([request])[0];
98 * Get the list of users enrolled in this cmid.
100 * @param {Number} cmid Course Module from which the users will be obtained
101 * @returns {Promise} Promise containing a list of users
103 var getEnrolledUsersFromCourseModuleID = function(cmid) {
105 methodname: 'core_course_get_enrolled_users_by_cmid',
111 return Ajax.call([request])[0];
115 getEnrolledCoursesByTimelineClassification: getEnrolledCoursesByTimelineClassification,
116 getLastAccessedCourses: getLastAccessedCourses,
117 getUsersFromCourseModuleID: getEnrolledUsersFromCourseModuleID,