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:
Tim Hunt 2013-07-17 20:26:39 +01:00
parent 181393aad2
commit 68d2f6a008
4 changed files with 47 additions and 23 deletions

View File

@ -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);
}
/**

View File

@ -29,26 +29,37 @@ defined('MOODLE_INTERNAL') || die();
/**
* Serve questiontext files in the question text when they are displayed in this report.
*
* @package mod_quiz
* @package quiz_statistics
* @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 quiz context
* @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 quiz_statistics_questiontext_preview_pluginfile($context, $questionid, $args, $forcedownload, array $options=array()) {
function quiz_statistics_question_preview_pluginfile($previewcontext, $questionid,
$filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array()) {
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
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);
// Assume only trusted people can see this report. There is no real way to
// validate questionid, becuase of the complexity of random quetsions.
require_capability('quiz/statistics:view', $context);
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);
}
/**

View File

@ -326,8 +326,9 @@ class quiz_statistics_report extends quiz_default_report {
protected function render_question_text($question) {
global $OUTPUT;
$text = question_rewrite_questiontext_preview_urls($question->questiontext,
$this->context->id, 'quiz_statistics', $question->id);
$text = question_rewrite_question_preview_urls($question->questiontext, $question->id,
$question->contextid, 'question', 'questiontext', $question->id,
$this->context->id, 'quiz_statistics');
return $OUTPUT->box(format_text($text, $question->questiontextformat,
array('noclean' => true, 'para' => false, 'overflowdiv' => true)),

View File

@ -852,8 +852,9 @@ class question_bank_question_text_row extends question_bank_row_base {
}
protected function display_content($question, $rowclasses) {
$text = question_rewrite_questiontext_preview_urls($question->questiontext,
$question->contextid, 'question', $question->id);
$text = question_rewrite_question_preview_urls($question->questiontext, $question->id,
$question->contextid, 'question', 'questiontext', $question->id,
$question->contextid, 'core_question');
$text = format_text($text, $question->questiontextformat,
$this->formatoptions);
if ($text == '') {