MDL-32471 preview thumbnails support for other component types

This commit affects mostly qtypes. Other standard components either do
not have pluginfile handler or have been already updated to the new API.
This commit is contained in:
David Mudrak 2012-04-24 14:29:44 +02:00
parent 957fc845b6
commit 7a00d4385d
14 changed files with 49 additions and 31 deletions

View File

@ -3981,6 +3981,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
send_file_not_found();
// ========================================================================================================================
} else if (strpos($component, '_') === false) {
// all core subsystems have to be specified above, no more guessing here!
send_file_not_found();
@ -3996,7 +3997,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
$filefunction = $component.'_pluginfile';
if (function_exists($filefunction)) {
// if the function exists, it must send the file and terminate. Whatever it returns leads to "not found"
$filefunction($course, $cm, $context, $filearea, $args, $forcedownload);
$filefunction($course, $cm, $context, $filearea, $args, $forcedownload, array('preview' => $preview));
}
send_file_not_found();

View File

@ -1719,8 +1719,9 @@ function question_rewrite_questiontext_preview_urls($questiontext, $contextid,
* @param int $questionid the question id
* @param array $args the remaining file arguments (file path).
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $options additional options affecting the file serving
*/
function question_send_questiontext_file($questionid, $args, $forcedownload) {
function question_send_questiontext_file($questionid, $args, $forcedownload, $options) {
global $DB;
$question = $DB->get_record_sql('
@ -1735,7 +1736,7 @@ function question_send_questiontext_file($questionid, $args, $forcedownload) {
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload);
send_stored_file($file, 0, 0, $forcedownload, $options);
}
/**
@ -1759,8 +1760,9 @@ function question_send_questiontext_file($questionid, $args, $forcedownload) {
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $options additional options affecting the file serving
*/
function question_pluginfile($course, $context, $component, $filearea, $args, $forcedownload) {
function question_pluginfile($course, $context, $component, $filearea, $args, $forcedownload, array $options=array()) {
global $DB, $CFG;
if ($filearea === 'questiontext_preview') {
@ -1768,7 +1770,7 @@ function question_pluginfile($course, $context, $component, $filearea, $args, $f
$questionid = array_shift($args);
component_callback($component, 'questiontext_preview_pluginfile', array(
$context, $questionid, $args, $forcedownload));
$context, $questionid, $args, $forcedownload, $options));
send_file_not_found();
}
@ -1841,7 +1843,7 @@ function question_pluginfile($course, $context, $component, $filearea, $args, $f
if ($module === 'core_question_preview') {
require_once($CFG->dirroot . '/question/previewlib.php');
return question_preview_question_pluginfile($course, $context,
$component, $filearea, $qubaid, $slot, $args, $forcedownload);
$component, $filearea, $qubaid, $slot, $args, $forcedownload, $options);
} else {
$dir = get_component_directory($module);
@ -1856,7 +1858,7 @@ function question_pluginfile($course, $context, $component, $filearea, $args, $f
}
$filefunction($course, $context, $component, $filearea, $qubaid, $slot,
$args, $forcedownload);
$args, $forcedownload, $options);
send_file_not_found();
}
@ -1871,8 +1873,9 @@ function question_pluginfile($course, $context, $component, $filearea, $args, $f
* @param int $questionid the question id
* @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) {
function core_question_questiontext_preview_pluginfile($context, $questionid, $args, $forcedownload, array $options=array()) {
global $DB;
// Verify that contextid matches the question.
@ -1889,7 +1892,7 @@ function core_question_questiontext_preview_pluginfile($context, $questionid, $a
question_require_capability_on($question, 'use');
question_send_questiontext_file($questionid, $args, $forcedownload);
question_send_questiontext_file($questionid, $args, $forcedownload, $options);
}
/**

View File

@ -36,8 +36,9 @@ defined('MOODLE_INTERNAL') || die();
* @param int $questionid the question id
* @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) {
function quiz_statistics_questiontext_preview_pluginfile($context, $questionid, $args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
@ -48,7 +49,7 @@ function quiz_statistics_questiontext_preview_pluginfile($context, $questionid,
// validate questionid, becuase of the complexity of random quetsions.
require_capability('quiz/statistics:view', $context);
question_send_questiontext_file($questionid, $args, $forcedownload);
question_send_questiontext_file($questionid, $args, $forcedownload, $options);
}
/**

View File

@ -224,10 +224,11 @@ class question_preview_options extends question_display_options {
* @param int $slot the relevant slot within the usage.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - justsend the file
*/
function question_preview_question_pluginfile($course, $context, $component,
$filearea, $qubaid, $slot, $args, $forcedownload) {
$filearea, $qubaid, $slot, $args, $forcedownload, $options) {
global $USER, $DB, $CFG;
$quba = question_engine::load_questions_usage_by_activity($qubaid);
@ -255,7 +256,7 @@ function question_preview_question_pluginfile($course, $context, $component,
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload);
send_stored_file($file, 0, 0, $forcedownload, $options);
}
/**

View File

@ -38,10 +38,11 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_calculated_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function qtype_calculated_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_calculated', $filearea, $args, $forcedownload);
question_pluginfile($course, $context, 'qtype_calculated', $filearea, $args, $forcedownload, $options);
}

View File

@ -38,12 +38,13 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_calculatedmulti_pluginfile($course, $cm, $context, $filearea, $args,
$forcedownload) {
$forcedownload, array $options=array()) {
global $DB, $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_calculatedmulti', $filearea, $args,
$forcedownload);
$forcedownload, $options);
}

View File

@ -39,12 +39,13 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_calculatedsimple_pluginfile($course, $cm, $context, $filearea,
$args, $forcedownload) {
$args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_calculatedsimple', $filearea,
$args, $forcedownload);
$args, $forcedownload, $options);
}

View File

@ -38,10 +38,11 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_essay_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function qtype_essay_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_essay', $filearea, $args, $forcedownload);
question_pluginfile($course, $context, 'qtype_essay', $filearea, $args, $forcedownload, $options);
}

View File

@ -37,10 +37,11 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_match_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function qtype_match_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $DB, $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_match', $filearea, $args, $forcedownload);
question_pluginfile($course, $context, 'qtype_match', $filearea, $args, $forcedownload, $options);
}

View File

@ -38,10 +38,11 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_multichoice_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function qtype_multichoice_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_multichoice', $filearea, $args, $forcedownload);
question_pluginfile($course, $context, 'qtype_multichoice', $filearea, $args, $forcedownload, $options);
}

View File

@ -38,10 +38,11 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_numerical_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function qtype_numerical_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_numerical', $filearea, $args, $forcedownload);
question_pluginfile($course, $context, 'qtype_numerical', $filearea, $args, $forcedownload, $options);
}

View File

@ -37,10 +37,11 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_shortanswer_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function qtype_shortanswer_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $DB, $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_shortanswer', $filearea, $args, $forcedownload);
question_pluginfile($course, $context, 'qtype_shortanswer', $filearea, $args, $forcedownload, $options);
}

View File

@ -37,10 +37,11 @@ defined('MOODLE_INTERNAL') || die();
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_truefalse_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function qtype_truefalse_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_truefalse', $filearea, $args, $forcedownload);
question_pluginfile($course, $context, 'qtype_truefalse', $filearea, $args, $forcedownload, $options);
}

View File

@ -7,6 +7,9 @@ This files describes API changes for question type plugins.
import and export, then you will probably get PHP strict syntax notices in developer
debug mode until you change the method signature to include qformat_xml $format.
That is, you need to specify the argument type.
* qtype_xxx_pluginfile() is now given the 7th parameter (hopefully the last
one) that contains additional options for the file serving. The array should
be re-passed to question_pluginfile() as is.
=== 2.2 ===