diff --git a/course/amd/build/repository.min.js b/course/amd/build/repository.min.js index 113b947fd09..090572e95e2 100644 --- a/course/amd/build/repository.min.js +++ b/course/amd/build/repository.min.js @@ -5,6 +5,6 @@ define("core_course/repository",["exports","core/ajax"],(function(_exports,_ajax * @module core_course/repository * @copyright 2018 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};var _default={getEnrolledCoursesByTimelineClassification:(classification,limit,offset,sort)=>{const args={classification:classification};void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]},getLastAccessedCourses:(userid,limit,offset,sort)=>{const args={};void 0!==userid&&(args.userid=userid),void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_recent_courses",args:args};return _ajax.default.call([request])[0]},getUsersFromCourseModuleID:(cmid,groupID)=>{var request={methodname:"core_course_get_enrolled_users_by_cmid",args:{cmid:cmid,groupid:groupID}};return _ajax.default.call([request])[0]},toggleManualCompletion:(cmid,completed)=>{const request={methodname:"core_completion_update_activity_completion_status_manually",args:{cmid:cmid,completed:completed}};return _ajax.default.call([request])[0]},getEnrolledCoursesWithEventsByTimelineClassification:function(classification){let limit=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,offset=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,sort=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,searchValue=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,eventsFrom=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,eventsTo=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null;const args={classification:classification,limit:limit,offset:offset,sort:sort,eventsfrom:eventsFrom,eventsto:eventsTo,searchvalue:searchValue},request={methodname:"core_course_get_enrolled_courses_with_action_events_by_timeline_classification",args:args};return _ajax.default.call([request])[0]}};return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};var _default={getEnrolledCoursesByTimelineClassification:(classification,limit,offset,sort)=>{const args={classification:classification};void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]},getLastAccessedCourses:(userid,limit,offset,sort)=>{const args={};void 0!==userid&&(args.userid=userid),void 0!==limit&&(args.limit=limit),void 0!==offset&&(args.offset=offset),void 0!==sort&&(args.sort=sort);const request={methodname:"core_course_get_recent_courses",args:args};return _ajax.default.call([request])[0]},getUsersFromCourseModuleID:function(cmid,groupID){let onlyActive=arguments.length>2&&void 0!==arguments[2]&&arguments[2];var request={methodname:"core_course_get_enrolled_users_by_cmid",args:{cmid:cmid,groupid:groupID,onlyactive:onlyActive}};return _ajax.default.call([request])[0]},toggleManualCompletion:(cmid,completed)=>{const request={methodname:"core_completion_update_activity_completion_status_manually",args:{cmid:cmid,completed:completed}};return _ajax.default.call([request])[0]},getEnrolledCoursesWithEventsByTimelineClassification:function(classification){let limit=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,offset=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,sort=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,searchValue=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,eventsFrom=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,eventsTo=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null;const args={classification:classification,limit:limit,offset:offset,sort:sort,eventsfrom:eventsFrom,eventsto:eventsTo,searchvalue:searchValue},request={methodname:"core_course_get_enrolled_courses_with_action_events_by_timeline_classification",args:args};return _ajax.default.call([request])[0]}};return _exports.default=_default,_exports.default})); //# sourceMappingURL=repository.min.js.map \ No newline at end of file diff --git a/course/amd/build/repository.min.js.map b/course/amd/build/repository.min.js.map index f4c17fd8a08..b2b7eeddad9 100644 --- a/course/amd/build/repository.min.js.map +++ b/course/amd/build/repository.min.js.map @@ -1 +1 @@ -{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * A javascript module to handle course ajax actions.\n *\n * @module core_course/repository\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Get the list of courses that the logged in user is enrolled in for a given\n * timeline classification.\n *\n * @param {string} classification past, inprogress, or future\n * @param {int} limit Only return this many results\n * @param {int} offset Skip this many results from the start of the result set\n * @param {string} sort Column to sort by and direction, e.g. 'shortname asc'\n * @return {object} jQuery promise resolved with courses.\n */\nconst getEnrolledCoursesByTimelineClassification = (classification, limit, offset, sort) => {\n const args = {\n classification: classification\n };\n\n if (typeof limit !== 'undefined') {\n args.limit = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.offset = offset;\n }\n\n if (typeof sort !== 'undefined') {\n args.sort = sort;\n }\n\n const request = {\n methodname: 'core_course_get_enrolled_courses_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Get a list of courses that the logged in user is enrolled in, where they have at least one action event,\n * for a given timeline classification.\n *\n * @param {string} classification past, inprogress, or future\n * @param {int} limit The maximum number of courses to return\n * @param {int} offset Skip this many results from the start of the result set\n * @param {string} sort Column to sort by and direction, e.g. 'shortname asc'\n * @param {string} searchValue Optional text search value\n * @param {int} eventsFrom Optional start timestamp (inclusive) that the course should have event(s) in\n * @param {int} eventsTo Optional end timestamp (inclusive) that the course should have event(s) in\n * @return {object} jQuery promise resolved with courses.\n */\n const getEnrolledCoursesWithEventsByTimelineClassification = (classification, limit = 0, offset = 0, sort = null,\n searchValue = null, eventsFrom = null, eventsTo = null) => {\n\n const args = {\n classification: classification,\n limit: limit,\n offset: offset,\n sort: sort,\n eventsfrom: eventsFrom,\n eventsto: eventsTo,\n searchvalue: searchValue,\n };\n\n const request = {\n methodname: 'core_course_get_enrolled_courses_with_action_events_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Get the list of courses that the user has most recently accessed.\n *\n * @method getLastAccessedCourses\n * @param {int} userid User from which the courses will be obtained\n * @param {int} limit Only return this many results\n * @param {int} offset Skip this many results from the start of the result set\n * @param {string} sort Column to sort by and direction, e.g. 'shortname asc'\n * @return {promise} Resolved with an array of courses\n */\nconst getLastAccessedCourses = (userid, limit, offset, sort) => {\n const args = {};\n\n if (typeof userid !== 'undefined') {\n args.userid = userid;\n }\n\n if (typeof limit !== 'undefined') {\n args.limit = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.offset = offset;\n }\n\n if (typeof sort !== 'undefined') {\n args.sort = sort;\n }\n\n const request = {\n methodname: 'core_course_get_recent_courses',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Get the list of users enrolled in this cmid.\n *\n * @param {Number} cmid Course Module from which the users will be obtained\n * @param {Number} groupID Group ID from which the users will be obtained\n * @returns {Promise} Promise containing a list of users\n */\nconst getEnrolledUsersFromCourseModuleID = (cmid, groupID) => {\n var request = {\n methodname: 'core_course_get_enrolled_users_by_cmid',\n args: {\n cmid: cmid,\n groupid: groupID,\n },\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Toggle the completion state of an activity with manual completion.\n *\n * @param {Number} cmid The course module ID.\n * @param {Boolean} completed Whether to set as complete or not.\n * @returns {object} jQuery promise\n */\nconst toggleManualCompletion = (cmid, completed) => {\n const request = {\n methodname: 'core_completion_update_activity_completion_status_manually',\n args: {\n cmid,\n completed,\n }\n };\n return Ajax.call([request])[0];\n};\n\nexport default {\n getEnrolledCoursesByTimelineClassification,\n getLastAccessedCourses,\n getUsersFromCourseModuleID: getEnrolledUsersFromCourseModuleID,\n toggleManualCompletion,\n getEnrolledCoursesWithEventsByTimelineClassification,\n};\n"],"names":["getEnrolledCoursesByTimelineClassification","classification","limit","offset","sort","args","request","methodname","Ajax","call","getLastAccessedCourses","userid","getUsersFromCourseModuleID","cmid","groupID","groupid","toggleManualCompletion","completed","getEnrolledCoursesWithEventsByTimelineClassification","searchValue","eventsFrom","eventsTo","eventsfrom","eventsto","searchvalue"],"mappings":";;;;;;;sJAwKe,CACXA,2CAtI+C,CAACC,eAAgBC,MAAOC,OAAQC,cACzEC,KAAO,CACTJ,eAAgBA,qBAGC,IAAVC,QACPG,KAAKH,MAAQA,YAGK,IAAXC,SACPE,KAAKF,OAASA,aAGE,IAATC,OACPC,KAAKD,KAAOA,YAGVE,QAAU,CACZC,WAAY,8DACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,IAiH5BI,uBAlE2B,CAACC,OAAQT,MAAOC,OAAQC,cAC7CC,KAAO,QAES,IAAXM,SACPN,KAAKM,OAASA,aAGG,IAAVT,QACPG,KAAKH,MAAQA,YAGK,IAAXC,SACPE,KAAKF,OAASA,aAGE,IAATC,OACPC,KAAKD,KAAOA,YAGVE,QAAU,CACZC,WAAY,iCACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,IA2C5BM,2BAjCuC,CAACC,KAAMC,eAC1CR,QAAU,CACVC,WAAY,yCACZF,KAAM,CACFQ,KAAMA,KACNE,QAASD,iBAIVN,cAAKC,KAAK,CAACH,UAAU,IAyB5BU,uBAf2B,CAACH,KAAMI,mBAC5BX,QAAU,CACZC,WAAY,6DACZF,KAAM,CACFQ,KAAAA,KACAI,UAAAA,mBAGDT,cAAKC,KAAK,CAACH,UAAU,IAQ5BY,qDApG0D,SAACjB,oBAAgBC,6DAAQ,EAAGC,8DAAS,EAAGC,4DAAO,KACrGe,mEAAc,KAAMC,kEAAa,KAAMC,gEAAW,WAEhDhB,KAAO,CACTJ,eAAgBA,eAChBC,MAAOA,MACPC,OAAQA,OACRC,KAAMA,KACNkB,WAAYF,WACZG,SAAUF,SACVG,YAAaL,aAGXb,QAAU,CACZC,WAAY,iFACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU"} \ No newline at end of file +{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * A javascript module to handle course ajax actions.\n *\n * @module core_course/repository\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Get the list of courses that the logged in user is enrolled in for a given\n * timeline classification.\n *\n * @param {string} classification past, inprogress, or future\n * @param {int} limit Only return this many results\n * @param {int} offset Skip this many results from the start of the result set\n * @param {string} sort Column to sort by and direction, e.g. 'shortname asc'\n * @return {object} jQuery promise resolved with courses.\n */\nconst getEnrolledCoursesByTimelineClassification = (classification, limit, offset, sort) => {\n const args = {\n classification: classification\n };\n\n if (typeof limit !== 'undefined') {\n args.limit = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.offset = offset;\n }\n\n if (typeof sort !== 'undefined') {\n args.sort = sort;\n }\n\n const request = {\n methodname: 'core_course_get_enrolled_courses_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Get a list of courses that the logged in user is enrolled in, where they have at least one action event,\n * for a given timeline classification.\n *\n * @param {string} classification past, inprogress, or future\n * @param {int} limit The maximum number of courses to return\n * @param {int} offset Skip this many results from the start of the result set\n * @param {string} sort Column to sort by and direction, e.g. 'shortname asc'\n * @param {string} searchValue Optional text search value\n * @param {int} eventsFrom Optional start timestamp (inclusive) that the course should have event(s) in\n * @param {int} eventsTo Optional end timestamp (inclusive) that the course should have event(s) in\n * @return {object} jQuery promise resolved with courses.\n */\n const getEnrolledCoursesWithEventsByTimelineClassification = (classification, limit = 0, offset = 0, sort = null,\n searchValue = null, eventsFrom = null, eventsTo = null) => {\n\n const args = {\n classification: classification,\n limit: limit,\n offset: offset,\n sort: sort,\n eventsfrom: eventsFrom,\n eventsto: eventsTo,\n searchvalue: searchValue,\n };\n\n const request = {\n methodname: 'core_course_get_enrolled_courses_with_action_events_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Get the list of courses that the user has most recently accessed.\n *\n * @method getLastAccessedCourses\n * @param {int} userid User from which the courses will be obtained\n * @param {int} limit Only return this many results\n * @param {int} offset Skip this many results from the start of the result set\n * @param {string} sort Column to sort by and direction, e.g. 'shortname asc'\n * @return {promise} Resolved with an array of courses\n */\nconst getLastAccessedCourses = (userid, limit, offset, sort) => {\n const args = {};\n\n if (typeof userid !== 'undefined') {\n args.userid = userid;\n }\n\n if (typeof limit !== 'undefined') {\n args.limit = limit;\n }\n\n if (typeof offset !== 'undefined') {\n args.offset = offset;\n }\n\n if (typeof sort !== 'undefined') {\n args.sort = sort;\n }\n\n const request = {\n methodname: 'core_course_get_recent_courses',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Get the list of users enrolled in this cmid.\n *\n * @param {Number} cmid Course Module from which the users will be obtained\n * @param {Number} groupID Group ID from which the users will be obtained\n * @param {Boolean} onlyActive Whether to fetch only the active enrolled users or all enrolled users in the course.\n * @returns {Promise} Promise containing a list of users\n */\nconst getEnrolledUsersFromCourseModuleID = (cmid, groupID, onlyActive = false) => {\n var request = {\n methodname: 'core_course_get_enrolled_users_by_cmid',\n args: {\n cmid: cmid,\n groupid: groupID,\n onlyactive: onlyActive,\n },\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Toggle the completion state of an activity with manual completion.\n *\n * @param {Number} cmid The course module ID.\n * @param {Boolean} completed Whether to set as complete or not.\n * @returns {object} jQuery promise\n */\nconst toggleManualCompletion = (cmid, completed) => {\n const request = {\n methodname: 'core_completion_update_activity_completion_status_manually',\n args: {\n cmid,\n completed,\n }\n };\n return Ajax.call([request])[0];\n};\n\nexport default {\n getEnrolledCoursesByTimelineClassification,\n getLastAccessedCourses,\n getUsersFromCourseModuleID: getEnrolledUsersFromCourseModuleID,\n toggleManualCompletion,\n getEnrolledCoursesWithEventsByTimelineClassification,\n};\n"],"names":["getEnrolledCoursesByTimelineClassification","classification","limit","offset","sort","args","request","methodname","Ajax","call","getLastAccessedCourses","userid","getUsersFromCourseModuleID","cmid","groupID","onlyActive","groupid","onlyactive","toggleManualCompletion","completed","getEnrolledCoursesWithEventsByTimelineClassification","searchValue","eventsFrom","eventsTo","eventsfrom","eventsto","searchvalue"],"mappings":";;;;;;;sJA0Ke,CACXA,2CAxI+C,CAACC,eAAgBC,MAAOC,OAAQC,cACzEC,KAAO,CACTJ,eAAgBA,qBAGC,IAAVC,QACPG,KAAKH,MAAQA,YAGK,IAAXC,SACPE,KAAKF,OAASA,aAGE,IAATC,OACPC,KAAKD,KAAOA,YAGVE,QAAU,CACZC,WAAY,8DACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,IAmH5BI,uBApE2B,CAACC,OAAQT,MAAOC,OAAQC,cAC7CC,KAAO,QAES,IAAXM,SACPN,KAAKM,OAASA,aAGG,IAAVT,QACPG,KAAKH,MAAQA,YAGK,IAAXC,SACPE,KAAKF,OAASA,aAGE,IAATC,OACPC,KAAKD,KAAOA,YAGVE,QAAU,CACZC,WAAY,iCACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,IA6C5BM,2BAlCuC,SAACC,KAAMC,aAASC,uEACnDT,QAAU,CACVC,WAAY,yCACZF,KAAM,CACFQ,KAAMA,KACNG,QAASF,QACTG,WAAYF,oBAIbP,cAAKC,KAAK,CAACH,UAAU,IAyB5BY,uBAf2B,CAACL,KAAMM,mBAC5Bb,QAAU,CACZC,WAAY,6DACZF,KAAM,CACFQ,KAAAA,KACAM,UAAAA,mBAGDX,cAAKC,KAAK,CAACH,UAAU,IAQ5Bc,qDAtG0D,SAACnB,oBAAgBC,6DAAQ,EAAGC,8DAAS,EAAGC,4DAAO,KACrGiB,mEAAc,KAAMC,kEAAa,KAAMC,gEAAW,WAEhDlB,KAAO,CACTJ,eAAgBA,eAChBC,MAAOA,MACPC,OAAQA,OACRC,KAAMA,KACNoB,WAAYF,WACZG,SAAUF,SACVG,YAAaL,aAGXf,QAAU,CACZC,WAAY,iFACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU"} \ No newline at end of file diff --git a/course/amd/src/repository.js b/course/amd/src/repository.js index 7e08a725a60..96dfa488f91 100644 --- a/course/amd/src/repository.js +++ b/course/amd/src/repository.js @@ -134,14 +134,16 @@ const getLastAccessedCourses = (userid, limit, offset, sort) => { * * @param {Number} cmid Course Module from which the users will be obtained * @param {Number} groupID Group ID from which the users will be obtained + * @param {Boolean} onlyActive Whether to fetch only the active enrolled users or all enrolled users in the course. * @returns {Promise} Promise containing a list of users */ -const getEnrolledUsersFromCourseModuleID = (cmid, groupID) => { +const getEnrolledUsersFromCourseModuleID = (cmid, groupID, onlyActive = false) => { var request = { methodname: 'core_course_get_enrolled_users_by_cmid', args: { cmid: cmid, groupid: groupID, + onlyactive: onlyActive, }, }; diff --git a/course/externallib.php b/course/externallib.php index 95a43cf5094..0397a8d9ed1 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -4151,6 +4151,8 @@ class core_course_external extends external_api { return new external_function_parameters([ 'cmid' => new external_value(PARAM_INT, 'id of the course module', VALUE_REQUIRED), 'groupid' => new external_value(PARAM_INT, 'id of the group', VALUE_DEFAULT, 0), + 'onlyactive' => new external_value(PARAM_BOOL, 'whether to return only active users or all.', + VALUE_DEFAULT, false), ]); } @@ -4159,26 +4161,25 @@ class core_course_external extends external_api { * * @param int $cmid Course Module id from which the users will be obtained * @param int $groupid Group id from which the users will be obtained + * @param bool $onlyactive Whether to return only the active enrolled users or all enrolled users in the course. * @return array List of users * @throws invalid_parameter_exception */ - public static function get_enrolled_users_by_cmid(int $cmid, int $groupid = 0) { + public static function get_enrolled_users_by_cmid(int $cmid, int $groupid = 0, bool $onlyactive = false) { global $PAGE; $warnings = []; - [ - 'cmid' => $cmid, - 'groupid' => $groupid, - ] = self::validate_parameters(self::get_enrolled_users_by_cmid_parameters(), [ + self::validate_parameters(self::get_enrolled_users_by_cmid_parameters(), [ 'cmid' => $cmid, 'groupid' => $groupid, + 'onlyactive' => $onlyactive, ]); list($course, $cm) = get_course_and_cm_from_cmid($cmid); $coursecontext = context_course::instance($course->id); self::validate_context($coursecontext); - $enrolledusers = get_enrolled_users($coursecontext, '', $groupid); + $enrolledusers = get_enrolled_users($coursecontext, '', $groupid, 'u.*', null, 0, 0, $onlyactive); $users = array_map(function ($user) use ($PAGE) { $user->fullname = fullname($user); diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 4f97c8568bc..e547b781f43 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -3630,6 +3630,7 @@ class externallib_test extends externallib_advanced_testcase { $user1 = self::getDataGenerator()->create_user(); $user2 = self::getDataGenerator()->create_user(); + $user3 = self::getDataGenerator()->create_user(); $user1picture = new user_picture($user1); $user1picture->size = 1; @@ -3639,6 +3640,10 @@ class externallib_test extends externallib_advanced_testcase { $user2picture->size = 1; $user2->profileimage = $user2picture->get_url($PAGE)->out(false); + $user3picture = new user_picture($user3); + $user3picture->size = 1; + $user3->profileimage = $user3picture->get_url($PAGE)->out(false); + // Set the first created user to the test user. self::setUser($user1); @@ -3653,6 +3658,8 @@ class externallib_test extends externallib_advanced_testcase { // Following lines enrol and assign default role id to the users. $this->getDataGenerator()->enrol_user($user1->id, $course1->id); $this->getDataGenerator()->enrol_user($user2->id, $course1->id); + // Enrol a suspended user in the course. + $this->getDataGenerator()->enrol_user($user3->id, $course1->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED); // Create what we expect to be returned when querying the course module. $expectedusers = array( @@ -3674,11 +3681,42 @@ class externallib_test extends externallib_advanced_testcase { 'lastname' => $user2->lastname, 'profileimage' => $user2->profileimage, ]; + $expectedusers['users'][2] = [ + 'id' => $user3->id, + 'fullname' => fullname($user3), + 'firstname' => $user3->firstname, + 'lastname' => $user3->lastname, + 'profileimage' => $user3->profileimage, + ]; // Test getting the users in a given context. $users = core_course_external::get_enrolled_users_by_cmid($forum1->cmid); $users = external_api::clean_returnvalue(core_course_external::get_enrolled_users_by_cmid_returns(), $users); + $this->assertEquals(3, count($users['users'])); + $this->assertEquals($expectedusers, $users); + + // Test getting only the active users in a given context. + $users = core_course_external::get_enrolled_users_by_cmid($forum1->cmid, 0, true); + $users = external_api::clean_returnvalue(core_course_external::get_enrolled_users_by_cmid_returns(), $users); + + $expectedusers['users'] = [ + [ + 'id' => $user1->id, + 'fullname' => fullname($user1), + 'firstname' => $user1->firstname, + 'lastname' => $user1->lastname, + 'profileimage' => $user1->profileimage, + ], + [ + 'id' => $user2->id, + 'fullname' => fullname($user2), + 'firstname' => $user2->firstname, + 'lastname' => $user2->lastname, + 'profileimage' => $user2->profileimage, + ] + ]; + $this->assertEquals(2, count($users['users'])); $this->assertEquals($expectedusers, $users); } diff --git a/lib/db/services.php b/lib/db/services.php index b1a14ef8c0e..e2ff0df1a2e 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -679,7 +679,7 @@ $functions = array( 'classname' => 'core_course_external', 'methodname' => 'get_enrolled_users_by_cmid', 'classpath' => 'course/externallib.php', - 'description' => 'List users by course module id & filter by group id.', + 'description' => 'List users by course module id, filter by group and active enrolment status.', 'type' => 'read', 'ajax' => true, ),