mirror of
https://github.com/moodle/moodle.git
synced 2025-03-18 22:50:19 +01:00
MDL-47084 forum: Return attachments and pluginfiles in get_posts WS
This commit is contained in:
parent
6597413d41
commit
48fb0250d2
@ -473,6 +473,29 @@ class mod_forum_external extends external_api {
|
||||
$user = username_load_fields_from_object($user, $post);
|
||||
$posts[$pid]->userfullname = fullname($user, $canviewfullname);
|
||||
|
||||
// Rewrite embedded images URLs.
|
||||
list($post->message, $post->messageformat) =
|
||||
external_format_text($post->message, $post->messageformat, $modcontext->id, 'mod_forum', 'post', $post->id);
|
||||
|
||||
// List attachments.
|
||||
if (!empty($post->attachment)) {
|
||||
$post->attachments = array();
|
||||
|
||||
$fs = get_file_storage();
|
||||
if ($files = $fs->get_area_files($modcontext->id, 'mod_forum', 'attachment', $post->id, "filename", false)) {
|
||||
foreach ($files as $file) {
|
||||
$filename = $file->get_filename();
|
||||
|
||||
$post->attachments[] = array(
|
||||
'filename' => $filename,
|
||||
'mimetype' => $file->get_mimetype(),
|
||||
'fileurl' => file_encode_url($CFG->wwwroot.'/webservice/pluginfile.php',
|
||||
'/'.$modcontext->id.'/mod_forum/attachment/'.$post->id.'/'.$filename)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$posts[$pid] = (array) $post;
|
||||
}
|
||||
|
||||
@ -503,9 +526,18 @@ class mod_forum_external extends external_api {
|
||||
'mailed' => new external_value(PARAM_INT, 'Mailed?'),
|
||||
'subject' => new external_value(PARAM_TEXT, 'The post subject'),
|
||||
'message' => new external_value(PARAM_RAW, 'The post message'),
|
||||
'messageformat' => new external_value(PARAM_INT, 'The post message format'),
|
||||
'messageformat' => new external_format_value('message'),
|
||||
'messagetrust' => new external_value(PARAM_INT, 'Can we trust?'),
|
||||
'attachment' => new external_value(PARAM_RAW, 'Attachments'),
|
||||
'attachment' => new external_value(PARAM_RAW, 'Has attachments?'),
|
||||
'attachments' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array (
|
||||
'filename' => new external_value(PARAM_FILE, 'file name'),
|
||||
'mimetype' => new external_value(PARAM_RAW, 'mime type'),
|
||||
'fileurl' => new external_value(PARAM_URL, 'file download url')
|
||||
)
|
||||
), 'attachments', VALUE_OPTIONAL
|
||||
),
|
||||
'totalscore' => new external_value(PARAM_INT, 'The post message total score'),
|
||||
'mailnow' => new external_value(PARAM_INT, 'Mail now?'),
|
||||
'children' => new external_multiple_structure(new external_value(PARAM_INT, 'children post id')),
|
||||
|
@ -468,14 +468,14 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
||||
'id' => $discussion1reply2->id,
|
||||
'discussion' => $discussion1reply2->discussion,
|
||||
'parent' => $discussion1reply2->parent,
|
||||
'userid' => $discussion1reply2->userid,
|
||||
'userid' => (int) $discussion1reply2->userid,
|
||||
'created' => $discussion1reply2->created,
|
||||
'modified' => $discussion1reply2->modified,
|
||||
'mailed' => $discussion1reply2->mailed,
|
||||
'subject' => $discussion1reply2->subject,
|
||||
'message' => file_rewrite_pluginfile_urls($discussion1reply2->message, 'pluginfile.php',
|
||||
$forum1context->id, 'mod_forum', 'post', $discussion1reply2->id),
|
||||
'messageformat' => $discussion1reply2->messageformat,
|
||||
'messageformat' => 1, // This value is usually changed by external_format_text() function.
|
||||
'messagetrust' => $discussion1reply2->messagetrust,
|
||||
'attachment' => $discussion1reply2->attachment,
|
||||
'totalscore' => $discussion1reply2->totalscore,
|
||||
@ -489,14 +489,14 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
||||
'id' => $discussion1reply1->id,
|
||||
'discussion' => $discussion1reply1->discussion,
|
||||
'parent' => $discussion1reply1->parent,
|
||||
'userid' => $discussion1reply1->userid,
|
||||
'userid' => (int) $discussion1reply1->userid,
|
||||
'created' => $discussion1reply1->created,
|
||||
'modified' => $discussion1reply1->modified,
|
||||
'mailed' => $discussion1reply1->mailed,
|
||||
'subject' => $discussion1reply1->subject,
|
||||
'message' => file_rewrite_pluginfile_urls($discussion1reply1->message, 'pluginfile.php',
|
||||
$forum1context->id, 'mod_forum', 'post', $discussion1reply1->id),
|
||||
'messageformat' => $discussion1reply1->messageformat,
|
||||
'messageformat' => 1, // This value is usually changed by external_format_text() function.
|
||||
'messagetrust' => $discussion1reply1->messagetrust,
|
||||
'attachment' => $discussion1reply1->attachment,
|
||||
'totalscore' => $discussion1reply1->totalscore,
|
||||
|
Loading…
x
Reference in New Issue
Block a user