MDL-35053 questions: question files outside an attempt.
Now update all the places that display files outside attempts to use the new API.
This commit is contained in:
+21
-10
@@ -1753,7 +1753,7 @@ function question_rewrite_questiontext_preview_urls($questiontext, $contextid,
|
||||
FROM {question} q
|
||||
JOIN {question_categories} qc ON qc.id = q.category
|
||||
WHERE q.id = :id', array('id' => $questionid), MUST_EXIST);
|
||||
|
||||
|
||||
return question_rewrite_question_preview_urls($questiontext, $questioncontextid,
|
||||
'question', 'questiontext', $contextid, $component, $questionid, $options);
|
||||
}
|
||||
@@ -1971,13 +1971,17 @@ function question_pluginfile($course, $context, $component, $filearea, $args, $f
|
||||
*
|
||||
* @package core_files
|
||||
* @category files
|
||||
* @param stdClass $context the context
|
||||
* @param int $questionid the question id
|
||||
* @param array $args remaining file args
|
||||
* @param bool $forcedownload
|
||||
* @param array $options additional options affecting the file serving
|
||||
* @param context $previewcontext the context in which the preview is happening.
|
||||
* @param int $questionid the question id.
|
||||
* @param context $filecontext the file (question) context.
|
||||
* @param string $filecomponent the component the file belongs to.
|
||||
* @param string $filearea the file area.
|
||||
* @param array $args remaining file args.
|
||||
* @param bool $forcedownload.
|
||||
* @param array $options additional options affecting the file serving.
|
||||
*/
|
||||
function core_question_questiontext_preview_pluginfile($context, $questionid, $args, $forcedownload, array $options=array()) {
|
||||
function core_question_question_preview_pluginfile($previewcontext, $questionid,
|
||||
$filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array()) {
|
||||
global $DB;
|
||||
|
||||
// Verify that contextid matches the question.
|
||||
@@ -1986,15 +1990,22 @@ function core_question_questiontext_preview_pluginfile($context, $questionid, $a
|
||||
FROM {question} q
|
||||
JOIN {question_categories} qc ON qc.id = q.category
|
||||
WHERE q.id = :id AND qc.contextid = :contextid',
|
||||
array('id' => $questionid, 'contextid' => $context->id), MUST_EXIST);
|
||||
array('id' => $questionid, 'contextid' => $filecontext->id), MUST_EXIST);
|
||||
|
||||
// Check the capability.
|
||||
list($context, $course, $cm) = get_context_info_array($context->id);
|
||||
list($context, $course, $cm) = get_context_info_array($previewcontext->id);
|
||||
require_login($course, false, $cm);
|
||||
|
||||
question_require_capability_on($question, 'use');
|
||||
|
||||
question_send_questiontext_file($questionid, $args, $forcedownload, $options);
|
||||
$fs = get_file_storage();
|
||||
$relativepath = implode('/', $args);
|
||||
$fullpath = "/{$filecontext->id}/{$filecomponent}/{$filearea}/{$relativepath}";
|
||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
send_stored_file($file, 0, 0, $forcedownload, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user