From 79a44f05a9247908dc88014cc12a45e8baf80fc4 Mon Sep 17 00:00:00 2001 From: kaipe Date: Wed, 4 Aug 2004 23:35:18 +0000 Subject: [PATCH] Took care of some issues concerning the use of individual quiz files in datasetdependent questions --- mod/quiz/lib.php | 5 +++ .../datasetdependent/abstractqtype.php | 42 +++++++++++++++---- mod/quiz/quizfile.php | 6 ++- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index d4aaf13fbc..969e15728d 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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 diff --git a/mod/quiz/questiontypes/datasetdependent/abstractqtype.php b/mod/quiz/questiontypes/datasetdependent/abstractqtype.php index d3b4449dcb..413f04c9e7 100644 --- a/mod/quiz/questiontypes/datasetdependent/abstractqtype.php +++ b/mod/quiz/questiontypes/datasetdependent/abstractqtype.php @@ -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 = ''; + $icon = "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 = 'name\">$icon$item->value"; + . "\" title=\"$datasetdef->name\">$icon$linktext"; } $datasetinput .= ';' . base64_encode($datasetdef->name) diff --git a/mod/quiz/quizfile.php b/mod/quiz/quizfile.php index 28cc7cd0dd..74583a91c0 100644 --- a/mod/quiz/quizfile.php +++ b/mod/quiz/quizfile.php @@ -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"); } -- 2.39.5