Skip to content

Commit

Permalink
MDL-66381 core_course: Modify get_enrolled_users_by_cmid
Browse files Browse the repository at this point in the history
We need to also provide a user's picture along with the current information
  • Loading branch information
Chocolate-lightning committed Nov 1, 2019
1 parent e04a73c commit 9d75248
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4073,6 +4073,7 @@ public static function get_enrolled_users_by_cmid_parameters() {
* @throws invalid_parameter_exception
*/
public static function get_enrolled_users_by_cmid(int $cmid) {
global $PAGE;
$warnings = [];

[
Expand All @@ -4087,8 +4088,11 @@ public static function get_enrolled_users_by_cmid(int $cmid) {

$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);
Expand Down Expand Up @@ -4119,6 +4123,7 @@ public static function get_enrolled_users_by_cmid_returns() {
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'),
Expand Down
11 changes: 11 additions & 0 deletions course/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2993,11 +2993,20 @@ public function test_get_recent_courses() {
* 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);

Expand All @@ -3024,12 +3033,14 @@ public function test_get_enrolled_users_by_cmid() {
'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.
Expand Down

0 comments on commit 9d75248

Please sign in to comment.