Merge branch 'MDL-55728-master' of git://github.com/jleyva/moodle

This commit is contained in:
Dan Poltawski 2016-10-04 10:15:37 +01:00
commit 917a59a1a0
6 changed files with 71 additions and 0 deletions

View file

@ -286,6 +286,10 @@ class mod_forum_external extends external_api {
if (!empty($post->attachment)) {
$post->attachments = external_util::get_area_files($modcontext->id, 'mod_forum', 'attachment', $post->id);
}
$messageinlinefiles = external_util::get_area_files($modcontext->id, 'mod_forum', 'post', $post->id);
if (!empty($messageinlinefiles)) {
$post->messageinlinefiles = $messageinlinefiles;
}
$posts[] = $post;
}
@ -319,6 +323,7 @@ class mod_forum_external extends external_api {
'message' => new external_value(PARAM_RAW, 'The post message'),
'messageformat' => new external_format_value('message'),
'messagetrust' => new external_value(PARAM_INT, 'Can we trust?'),
'messageinlinefiles' => new external_files('post message inline files', VALUE_OPTIONAL),
'attachment' => new external_value(PARAM_RAW, 'Has attachments?'),
'attachments' => new external_files('attachments', VALUE_OPTIONAL),
'totalscore' => new external_value(PARAM_INT, 'The post message total score'),
@ -499,6 +504,10 @@ class mod_forum_external extends external_api {
$discussion->attachments = external_util::get_area_files($modcontext->id, 'mod_forum', 'attachment',
$discussion->id);
}
$messageinlinefiles = external_util::get_area_files($modcontext->id, 'mod_forum', 'post', $discussion->id);
if (!empty($messageinlinefiles)) {
$discussion->messageinlinefiles = $messageinlinefiles;
}
$discussion->locked = forum_discussion_is_locked($forum, $discussion);
$discussion->canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
@ -543,6 +552,7 @@ class mod_forum_external extends external_api {
'message' => new external_value(PARAM_RAW, 'The post message'),
'messageformat' => new external_format_value('message'),
'messagetrust' => new external_value(PARAM_INT, 'Can we trust?'),
'messageinlinefiles' => new external_files('post message inline files', VALUE_OPTIONAL),
'attachment' => new external_value(PARAM_RAW, 'Has attachments?'),
'attachments' => new external_files('attachments', VALUE_OPTIONAL),
'totalscore' => new external_value(PARAM_INT, 'The post message total score'),

View file

@ -225,6 +225,19 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$record->parent = $discussion1->firstpost;
$record->userid = $user2->id;
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$filename = 'shouldbeanimage.jpg';
// Add a fake inline image to the post.
$filerecordinline = array(
'contextid' => $forum1context->id,
'component' => 'mod_forum',
'filearea' => 'post',
'itemid' => $discussion1reply1->id,
'filepath' => '/',
'filename' => $filename,
);
$fs = get_file_storage();
$timepost = time();
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$record->parent = $discussion1reply1->id;
$record->userid = $user3->id;
@ -284,6 +297,17 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'messageformat' => 1, // This value is usually changed by external_format_text() function.
'messagetrust' => $discussion1reply1->messagetrust,
'attachment' => $discussion1reply1->attachment,
'messageinlinefiles' => array(
array(
'filename' => $filename,
'filepath' => '/',
'filesize' => '27',
'fileurl' => moodle_url::make_webservice_pluginfile_url($forum1context->id, 'mod_forum', 'post',
$discussion1reply1->id, '/', $filename),
'timemodified' => $timepost,
'mimetype' => 'image/jpeg',
)
),
'totalscore' => $discussion1reply1->totalscore,
'mailnow' => $discussion1reply1->mailnow,
'children' => array($discussion1reply2->id),

View file

@ -90,6 +90,7 @@ class mod_glossary_external extends external_api {
'definition' => new external_value(PARAM_RAW, 'The definition'),
'definitionformat' => new external_format_value('definition'),
'definitiontrust' => new external_value(PARAM_BOOL, 'The definition trust flag'),
'definitioninlinefiles' => new external_files('entry definition inline files', VALUE_OPTIONAL),
'attachment' => new external_value(PARAM_BOOL, 'Whether or not the entry has attachments'),
'attachments' => new external_files('attachments', VALUE_OPTIONAL),
'timecreated' => new external_value(PARAM_INT, 'Time created'),
@ -144,6 +145,10 @@ class mod_glossary_external extends external_api {
if ($entry->attachment) {
$entry->attachments = external_util::get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
}
$definitioninlinefiles = external_util::get_area_files($context->id, 'mod_glossary', 'entry', $entry->id);
if (!empty($definitioninlinefiles)) {
$entry->definitioninlinefiles = $definitioninlinefiles;
}
}
/**

View file

@ -1064,6 +1064,19 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$this->getDataGenerator()->enrol_user($u1->id, $c1->id);
$e1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
// Add a fake inline image to the entry.
$filename = 'shouldbeanimage.jpg';
$filerecordinline = array(
'contextid' => $ctx->id,
'component' => 'mod_glossary',
'filearea' => 'entry',
'itemid' => $e1->id,
'filepath' => '/',
'filename' => $filename,
);
$fs = get_file_storage();
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$e2 = $gg->create_content($g1, array('approved' => 0, 'userid' => $u1->id));
$e3 = $gg->create_content($g1, array('approved' => 0, 'userid' => $u2->id));
$e4 = $gg->create_content($g2, array('approved' => 1));
@ -1072,6 +1085,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$return = mod_glossary_external::get_entry_by_id($e1->id);
$return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
$this->assertEquals($e1->id, $return['entry']['id']);
$this->assertEquals($filename, $return['entry']['definitioninlinefiles'][0]['filename']);
$return = mod_glossary_external::get_entry_by_id($e2->id);
$return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);

View file

@ -1641,6 +1641,10 @@ class mod_quiz_external extends external_api {
'mod_quiz', 'feedback', $feedback->id);
$result['feedbacktext'] = $text;
$result['feedbacktextformat'] = $format;
$feedbackinlinefiles = external_util::get_area_files($context->id, 'mod_quiz', 'feedback', $feedback->id);
if (!empty($feedbackinlinefiles)) {
$result['feedbackinlinefiles'] = $feedbackinlinefiles;
}
}
$result['warnings'] = $warnings;
@ -1658,6 +1662,7 @@ class mod_quiz_external extends external_api {
array(
'feedbacktext' => new external_value(PARAM_RAW, 'the comment that corresponds to this grade (empty for none)'),
'feedbacktextformat' => new external_format_value('feedbacktext', VALUE_OPTIONAL),
'feedbackinlinefiles' => new external_files('feedback inline files', VALUE_OPTIONAL),
'warnings' => new external_warnings(),
)
);

View file

@ -1474,6 +1474,18 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase {
$feedback->mingrade = 49;
$feedback->maxgrade = 100;
$feedback->id = $DB->insert_record('quiz_feedback', $feedback);
// Add a fake inline image to the feedback text.
$filename = 'shouldbeanimage.jpg';
$filerecordinline = array(
'contextid' => $this->context->id,
'component' => 'mod_quiz',
'filearea' => 'feedback',
'itemid' => $feedback->id,
'filepath' => '/',
'filename' => $filename,
);
$fs = get_file_storage();
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$feedback->feedbacktext = 'Feedback text 2';
$feedback->feedbacktextformat = 1;
@ -1484,6 +1496,7 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase {
$result = mod_quiz_external::get_quiz_feedback_for_grade($this->quiz->id, 50);
$result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_feedback_for_grade_returns(), $result);
$this->assertEquals('Feedback text 1', $result['feedbacktext']);
$this->assertEquals($filename, $result['feedbackinlinefiles'][0]['filename']);
$this->assertEquals(FORMAT_HTML, $result['feedbacktextformat']);
$result = mod_quiz_external::get_quiz_feedback_for_grade($this->quiz->id, 30);