Skip to content

Commit

Permalink
MDL-47084 forum: Return user picture URL in get_posts WS
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Oct 3, 2014
1 parent 48fb025 commit 694bf0c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 9 additions & 2 deletions mod/forum/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,14 @@ public static function get_forum_discussion_posts($discussionid, $sortby = "crea
}

$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) =
Expand Down Expand Up @@ -543,7 +549,8 @@ public static function get_forum_discussion_posts_returns() {
'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'
)
),
Expand Down
18 changes: 16 additions & 2 deletions mod/forum/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ public function test_mod_forum_get_forum_discussion_posts() {
'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,
Expand All @@ -483,8 +489,15 @@ public function test_mod_forum_get_forum_discussion_posts() {
'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,
Expand All @@ -504,7 +517,8 @@ public function test_mod_forum_get_forum_discussion_posts() {
'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).
Expand Down

0 comments on commit 694bf0c

Please sign in to comment.