From 6dbf42a60091de23721b4c8f5966f1173321b7db Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 28 Jan 2015 17:20:02 +0100 Subject: [PATCH] MDL-48525 webservices: Fixed profile user image is not always returned --- message/externallib.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/message/externallib.php b/message/externallib.php index b1468ad9d8d56..13d754c61b1a1 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -444,12 +444,11 @@ public static function get_contacts() { 'unread' => $contact->messagecount ); - // Try to get the user picture, but sometimes this method can return null. - $userdetails = user_get_user_details($contact, null, array('profileimageurl', 'profileimageurlsmall')); - if (!empty($userdetails)) { - $newcontact['profileimageurl'] = $userdetails['profileimageurl']; - $newcontact['profileimageurlsmall'] = $userdetails['profileimageurlsmall']; - } + $usercontextid = context_user::instance($contact->id)->id; + $newcontact['profileimageurl'] = moodle_url::make_webservice_pluginfile_url( + $usercontextid, 'user', 'icon', null, '/', 'f1')->out(false); + $newcontact['profileimageurlsmall'] = moodle_url::make_webservice_pluginfile_url( + $usercontextid, 'user', 'icon', null, '/', 'f2')->out(false); $allcontacts[$mode][$key] = $newcontact; } @@ -576,12 +575,11 @@ public static function search_contacts($searchtext, $onlymycourses = false) { $user->phone1 = null; $user->phone2 = null; - // Try to get the user picture, but sometimes this method can return null. - $userdetails = user_get_user_details($user, null, array('profileimageurl', 'profileimageurlsmall')); - if (!empty($userdetails)) { - $newuser['profileimageurl'] = $userdetails['profileimageurl']; - $newuser['profileimageurlsmall'] = $userdetails['profileimageurlsmall']; - } + $usercontextid = context_user::instance($user->id)->id; + $newuser['profileimageurl'] = moodle_url::make_webservice_pluginfile_url( + $usercontextid, 'user', 'icon', null, '/', 'f1')->out(false); + $newuser['profileimageurlsmall'] = moodle_url::make_webservice_pluginfile_url( + $usercontextid, 'user', 'icon', null, '/', 'f2')->out(false); $user = $newuser; }