Permalink
Browse files

Took care of some issues concerning the use of

individual quiz files in datasetdependent questions
  • Loading branch information...
kaipe
kaipe committed Aug 4, 2004
1 parent bcaba84 commit 79a44f05a9247908dc88014cc12a45e8baf80fc4
Showing with 44 additions and 9 deletions.
  1. +5 −0 mod/quiz/lib.php
  2. +35 −7 mod/quiz/questiontypes/datasetdependent/abstractqtype.php
  3. +4 −2 mod/quiz/quizfile.php
View
@@ -53,6 +53,11 @@ function name() {
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,25 +361,31 @@ function create_response($question, $nameprefix, $questionsinuse) {
$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;
} else {
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)
View
@@ -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");
}

0 comments on commit 79a44f0

Please sign in to comment.