From e3bb3da4066329c1a3a50cbb9ea6614f12fb539c Mon Sep 17 00:00:00 2001 From: Mathew May Date: Fri, 1 Nov 2019 13:39:10 +0800 Subject: [PATCH] MDL-66359 core_course: Modify get_enrolled_users_by_cmid We need to also provide a user's group along with the current information --- course/amd/build/repository.min.js | Bin 919 -> 931 bytes course/amd/build/repository.min.js.map | Bin 5738 -> 5915 bytes course/amd/src/repository.js | 4 +++- course/externallib.php | 10 +++++++--- lib/db/services.php | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/course/amd/build/repository.min.js b/course/amd/build/repository.min.js index 2e4849bbfd8150fdf569564e138ff99e912682b6..8d7c2a2ececf885911d3884348c5177283bd6feb 100644 GIT binary patch delta 29 kcmbQvzL7-ATFKsqWsc=%oMBS$??n<0DA}si2wiq delta 15 WcmZ3?KAn97FY{!6=Ag;h%oYG7q69er diff --git a/course/amd/build/repository.min.js.map b/course/amd/build/repository.min.js.map index 1e49dc2d9b02edc66dfeac39bd8b1cb0679dedae..c6b8c7c7352ebf478cfcc853b10392021b904a59 100644 GIT binary patch delta 267 zcmaE*Gh1(i2BV;kQhHH-X@RGU5|lMrl`%oe%+1nS$Jf!(U&qfx?a?BwWJ>;&XwxNPoY=3^2mbOK4adwA;@0Hq8-QfZSnu&PRc zv^%DOh;oo%u(=D^hLp(+gmCb2olxVpLO_(Lppbaer$aSH$uoOrMXF|MYRf0Pbj#9Jfq<0GWnqJN=_Y^@Z>C!`63EH09KZn NVg-}f{7a;O5daqHPt^bb delta 157 zcmbQO_ey7j2IFKK##kvMH%n(7Uq?rO9cM>p4`&?%XGcc^XCNnI^Jd0djH2Z(zCezv zhr3R(lcQs?6Od!+ym=8bACpL~6G+P4!&}DyC}jYWN|}6wRh0+G2rO^`o0>G4kxh;< wV6p<61Dl&CP{Mz54VwyM#^!}=ZM>7qL@Jpz6{;uu@cB;m5cS`@OEi%Y0FQJm1ONa4 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, ), -- 2.43.0