Took care of some issues concerning the use of
individual quiz files in datasetdependent questions
This commit is contained in:
@@ -53,6 +53,11 @@ class quiz_default_questiontype {
|
||||
return 'default';
|
||||
}
|
||||
|
||||
function uses_quizfile($question, $relativefilepath) {
|
||||
// The default does only check whether the file is used as image:
|
||||
return $question->image == $relativefilepath;
|
||||
}
|
||||
|
||||
function save_question_options($question) {
|
||||
/// Given some question info and some data about the the answers
|
||||
/// this function parses, organises and saves the question
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
/// ABSTRACT SUPERCLASS FOR QUSTION TYPES THAT USE DATASETS ///
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
require_once($CFG->dirroot . '/files/mimetypes.php');
|
||||
|
||||
define("LITERAL", "1");
|
||||
define("FILE", "2");
|
||||
define("LINK", "3");
|
||||
@@ -19,6 +21,26 @@ class quiz_dataset_dependent_questiontype extends quiz_default_questiontype {
|
||||
function name() {
|
||||
return 'datasetdependent';
|
||||
}
|
||||
|
||||
function uses_quizfile($question, $relativefilepath) {
|
||||
// Check whether the specified file is available by any
|
||||
// dataset item on this question...
|
||||
global $CFG;
|
||||
if (get_record_sql(" SELECT *
|
||||
FROM {$CFG->prefix}quiz_dataset_items i,
|
||||
{$CFG->prefix}quiz_dataset_definitions d,
|
||||
{$CFG->prefix}quiz_question_datasets q
|
||||
WHERE i.value = '$relativefilepath'
|
||||
AND d.id = i.definition AND d.type = 2
|
||||
AND d.id = q.datasetdefinition
|
||||
AND q.question = $question->id ")) {
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// Make the check of the parent:
|
||||
return parent::uses_quizfile($question, $relativefilepath);
|
||||
}
|
||||
}
|
||||
|
||||
function create_virtual_qtype() {
|
||||
error("No vitrual question type for question type ".$this->name());
|
||||
@@ -339,8 +361,9 @@ class quiz_dataset_dependent_questiontype extends quiz_default_questiontype {
|
||||
$value = $item->value;
|
||||
|
||||
} else {
|
||||
$icon = '<IMG SRC="../../files/pix/'
|
||||
. mimeinfo('icon', $item->value) . '" />';
|
||||
$icon = "<IMG SRC=\"$CFG->wwwroot/pix/f/"
|
||||
. mimeinfo('icon', $item->value)
|
||||
. '" HEIGHT="16" WIDTH="16" BORDER="0" ALT="File" />';
|
||||
if (substr(strtolower($item->value), 0, 7)=='http://') {
|
||||
$link = $item->value;
|
||||
|
||||
@@ -348,16 +371,21 @@ class quiz_dataset_dependent_questiontype extends quiz_default_questiontype {
|
||||
global $quiz; // Try to reach this info globally
|
||||
if ($CFG->slasharguments) {
|
||||
// Use this method if possible for better caching
|
||||
$link = "$CFG->wwwroot/mod/quiz/quizfile.php/"
|
||||
. "$quiz->id/$question->id/$item->value";
|
||||
$link = "quizfile.php/$quiz->id/$question->id/$item->value";
|
||||
|
||||
} else {
|
||||
$link = "$CFG->wwwroot/mod/quiz/quizfile.php?file=/"
|
||||
. "$quiz->id/$question->id/$item->value";
|
||||
$link = "quizfile.php?file=/$quiz->id/$question->id/$item->value";
|
||||
}
|
||||
}
|
||||
|
||||
if ($datasetdef->type == FILE
|
||||
and ereg('/([^/]+)$', $item->value, $regs)) {
|
||||
$linktext = $regs[1];
|
||||
} else {
|
||||
$linktext = $item->value;
|
||||
}
|
||||
$value = '<a target="_blank" href="' . $link
|
||||
. "\" title=\"$datasetdef->name\">$icon$item->value</a>";
|
||||
. "\" title=\"$datasetdef->name\">$icon$linktext</a>";
|
||||
}
|
||||
|
||||
$datasetinput .= ';' . base64_encode($datasetdef->name)
|
||||
|
||||
@@ -79,8 +79,10 @@
|
||||
{
|
||||
error("Question category is not valid");
|
||||
}
|
||||
// For the moment - questions can reference datafiles through image only
|
||||
if (! ($question->image == $relativefilepath)) {
|
||||
|
||||
// Have the question check whether it uses this file or not
|
||||
if (!$QUIZ_QTYPES[$question->qtype]->uses_quizfile($question,
|
||||
$relativefilepath)) {
|
||||
error("The specified file path is not on the specified question");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user