MDL-66359 core_course: Modify get_enrolled_users_by_cmid
authorMathew May <mathewm@hotmail.co.nz>
Fri, 1 Nov 2019 05:39:10 +0000 (13:39 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Thu, 7 Nov 2019 02:47:45 +0000 (10:47 +0800)
We need to also provide a user's group along with the current information

course/amd/build/repository.min.js
course/amd/build/repository.min.js.map
course/amd/src/repository.js
course/externallib.php
lib/db/services.php

index 2e4849b..8d7c2a2 100644 (file)
Binary files a/course/amd/build/repository.min.js and b/course/amd/build/repository.min.js differ
index 1e49dc2..c6b8c7c 100644 (file)
Binary files a/course/amd/build/repository.min.js.map and b/course/amd/build/repository.min.js.map differ
index 7e530a7..956f309 100644 (file)
@@ -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,
             },
         };
 
index 992ba22..b39acfe 100644 (file)
@@ -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);
index 15adc29..b629e93 100644 (file)
@@ -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,
     ),