]> git.mjollnir.org Git - moodle.git/commitdiff
Took care of some issues concerning the use of
authorkaipe <kaipe>
Wed, 4 Aug 2004 23:35:18 +0000 (23:35 +0000)
committerkaipe <kaipe>
Wed, 4 Aug 2004 23:35:18 +0000 (23:35 +0000)
individual quiz files in datasetdependent questions

mod/quiz/lib.php
mod/quiz/questiontypes/datasetdependent/abstractqtype.php
mod/quiz/quizfile.php

index d4aaf13fbc3ce98bdbecfbf10ef7c96a68119a3f..969e15728ddc0f5d96ea5417e5fa4f4d200fd0a2 100644 (file)
@@ -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
index d3b4449dcbed38c35832460bacb0d5c983cfd417..413f04c9e7aab6b5fe51877bcd93838af7fb1af6 100644 (file)
@@ -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)
index 28cc7cd0dde3a4e9a4c56a38d53437741f936df8..74583a91c056e9555fb419f183d83a8147ca2914 100644 (file)
     {
         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");
     }