MDL-66381 core_course: Modify get_enrolled_users_by_cmid
We need to also provide a user's picture along with the current information
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user