MDL-47084 forum: Return user picture URL in get_posts WS

This commit is contained in:
Juan Leyva 2014-09-19 21:45:22 +02:00
parent 48fb0250d2
commit 694bf0c74b
2 changed files with 25 additions and 4 deletions

View File

@ -470,8 +470,14 @@ class mod_forum_external extends external_api {
}
$user = new stdclass();
$user->id = $post->userid;
$user = username_load_fields_from_object($user, $post);
$posts[$pid]->userfullname = fullname($user, $canviewfullname);
$post->userfullname = fullname($user, $canviewfullname);
$post->userpictureurl = moodle_url::make_pluginfile_url(
context_user::instance($user->id)->id, 'user', 'icon', null, '/', 'f1');
// Fix the pluginfile.php link.
$post->userpictureurl = str_replace("pluginfile.php", "webservice/pluginfile.php",
$post->userpictureurl);
// Rewrite embedded images URLs.
list($post->message, $post->messageformat) =
@ -543,7 +549,8 @@ class mod_forum_external extends external_api {
'children' => new external_multiple_structure(new external_value(PARAM_INT, 'children post id')),
'canreply' => new external_value(PARAM_BOOL, 'The user can reply to posts?'),
'postread' => new external_value(PARAM_BOOL, 'The post was read'),
'userfullname' => new external_value(PARAM_TEXT, 'Post author full name')
'userfullname' => new external_value(PARAM_TEXT, 'Post author full name'),
'userpictureurl' => new external_value(PARAM_URL, 'Post author picture.', VALUE_OPTIONAL)
), 'post'
)
),

View File

@ -464,6 +464,12 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'posts' => array(),
'warnings' => array(),
);
$userpictureurl = moodle_url::make_pluginfile_url(
context_user::instance($discussion1reply2->userid)->id, 'user', 'icon', null, '/', 'f1');
// Fix the pluginfile.php link.
$userpictureurl = str_replace("pluginfile.php", "webservice/pluginfile.php", $userpictureurl);
$expectedposts['posts'][] = array(
'id' => $discussion1reply2->id,
'discussion' => $discussion1reply2->discussion,
@ -483,8 +489,15 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'children' => array(),
'canreply' => true,
'postread' => false,
'userfullname' => fullname($user3)
'userfullname' => fullname($user3),
'userpictureurl' => $userpictureurl
);
$userpictureurl = moodle_url::make_pluginfile_url(
context_user::instance($discussion1reply1->userid)->id, 'user', 'icon', null, '/', 'f1');
// Fix the pluginfile.php link.
$userpictureurl = str_replace("pluginfile.php", "webservice/pluginfile.php", $userpictureurl);
$expectedposts['posts'][] = array(
'id' => $discussion1reply1->id,
'discussion' => $discussion1reply1->discussion,
@ -504,7 +517,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'children' => array($discussion1reply2->id),
'canreply' => true,
'postread' => false,
'userfullname' => fullname($user2)
'userfullname' => fullname($user2),
'userpictureurl' => $userpictureurl
);
// Test a discussion with two additional posts (total 3 posts).