MDL-66381 core_course: Modify get_enrolled_users_by_cmid
authorMathew May <mathewm@hotmail.co.nz>
Mon, 14 Oct 2019 07:21:45 +0000 (15:21 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Fri, 1 Nov 2019 03:46:37 +0000 (11:46 +0800)
We need to also provide a user's picture along with the current information

course/externallib.php
course/tests/externallib_test.php

index d3bab4d..992ba22 100644 (file)
@@ -4073,6 +4073,7 @@ class core_course_external extends external_api {
      * @throws invalid_parameter_exception
      */
     public static function get_enrolled_users_by_cmid(int $cmid) {
+        global $PAGE;
         $warnings = [];
 
         [
@@ -4087,8 +4088,11 @@ class core_course_external extends external_api {
 
         $enrolledusers = get_enrolled_users($coursecontext);
 
-        $users = array_map(function ($user) {
+        $users = array_map(function ($user) use ($PAGE) {
             $user->fullname = fullname($user);
+            $userpicture = new user_picture($user);
+            $userpicture->size = 1;
+            $user->profileimage = $userpicture->get_url($PAGE)->out(false);
             return $user;
         }, $enrolledusers);
         sort($users);
@@ -4119,6 +4123,7 @@ class core_course_external extends external_api {
     public static function user_description() {
         $userfields = array(
             'id'    => new external_value(core_user::get_property_type('id'), 'ID of the user'),
+            'profileimage' => new external_value(PARAM_URL, 'The location of the users larger image', VALUE_OPTIONAL),
             'fullname' => new external_value(PARAM_TEXT, 'The full name of the user', VALUE_OPTIONAL),
             'firstname'   => new external_value(
                     core_user::get_property_type('firstname'),
index dd752c0..5454df4 100644 (file)
@@ -2993,11 +2993,20 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
      * Test get enrolled users by cmid function.
      */
     public function test_get_enrolled_users_by_cmid() {
+        global $PAGE;
         $this->resetAfterTest(true);
 
         $user1 = self::getDataGenerator()->create_user();
         $user2 = self::getDataGenerator()->create_user();
 
+        $user1picture = new user_picture($user1);
+        $user1picture->size = 1;
+        $user1->profileimage = $user1picture->get_url($PAGE)->out(false);
+
+        $user2picture = new user_picture($user2);
+        $user2picture->size = 1;
+        $user2->profileimage = $user2picture->get_url($PAGE)->out(false);
+
         // Set the first created user to the test user.
         self::setUser($user1);
 
@@ -3024,12 +3033,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
             'fullname' => fullname($user1),
             'firstname' => $user1->firstname,
             'lastname' => $user1->lastname,
+            'profileimage' => $user1->profileimage,
         ];
         $expectedusers['users'][1] = [
             'id' => $user2->id,
             'fullname' => fullname($user2),
             'firstname' => $user2->firstname,
             'lastname' => $user2->lastname,
+            'profileimage' => $user2->profileimage,
         ];
 
         // Test getting the users in a given context.