From: Mathew May Date: Fri, 1 Nov 2019 05:39:10 +0000 (+0800) Subject: MDL-66359 core_course: Modify get_enrolled_users_by_cmid X-Git-Tag: v3.8.0-beta~58^2~1 X-Git-Url: http://git.moodle.org/gw?p=moodle.git;a=commitdiff_plain;h=e3bb3da4066329c1a3a50cbb9ea6614f12fb539c MDL-66359 core_course: Modify get_enrolled_users_by_cmid We need to also provide a user's group along with the current information --- diff --git a/course/amd/build/repository.min.js b/course/amd/build/repository.min.js index 2e4849bbfd8..8d7c2a2ecec 100644 Binary files a/course/amd/build/repository.min.js and b/course/amd/build/repository.min.js differ diff --git a/course/amd/build/repository.min.js.map b/course/amd/build/repository.min.js.map index 1e49dc2d9b0..c6b8c7c7352 100644 Binary files a/course/amd/build/repository.min.js.map and b/course/amd/build/repository.min.js.map differ diff --git a/course/amd/src/repository.js b/course/amd/src/repository.js index 7e530a72543..956f30979f5 100644 --- a/course/amd/src/repository.js +++ b/course/amd/src/repository.js @@ -98,13 +98,15 @@ define(['jquery', 'core/ajax'], function($, Ajax) { * Get the list of users enrolled in this cmid. * * @param {Number} cmid Course Module from which the users will be obtained + * @param {Number} groupID Group ID from which the users will be obtained * @returns {Promise} Promise containing a list of users */ - var getEnrolledUsersFromCourseModuleID = function(cmid) { + var getEnrolledUsersFromCourseModuleID = function(cmid, groupID) { var request = { methodname: 'core_course_get_enrolled_users_by_cmid', args: { cmid: cmid, + groupid: groupID, }, }; diff --git a/course/externallib.php b/course/externallib.php index 992ba224188..b39acfe3a0f 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -4062,6 +4062,7 @@ class core_course_external extends external_api { public static function get_enrolled_users_by_cmid_parameters() { 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), ]); } @@ -4069,24 +4070,27 @@ class core_course_external extends external_api { * Get all users in a course for a given cmid. * * @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 * @return array List of users * @throws invalid_parameter_exception */ - public static function get_enrolled_users_by_cmid(int $cmid) { - global $PAGE; + public static function get_enrolled_users_by_cmid(int $cmid, int $groupid = 0) { + global $PAGE; $warnings = []; [ 'cmid' => $cmid, + 'groupid' => $groupid, ] = self::validate_parameters(self::get_enrolled_users_by_cmid_parameters(), [ 'cmid' => $cmid, + 'groupid' => $groupid, ]); 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); + $enrolledusers = get_enrolled_users($coursecontext, '', $groupid); $users = array_map(function ($user) use ($PAGE) { $user->fullname = fullname($user); diff --git a/lib/db/services.php b/lib/db/services.php index 15adc29f627..b629e937be7 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -625,7 +625,7 @@ $functions = array( 'classname' => 'core_course_external', 'methodname' => 'get_enrolled_users_by_cmid', 'classpath' => 'course/externallib.php', - 'description' => 'List users bycourse module id.', + 'description' => 'List users by course module id & filter by group id.', 'type' => 'read', 'ajax' => true, ),