]> git.mjollnir.org Git - moodle.git/commitdiff
Added 'virtual' method for writequestion
authorthepurpleblob <thepurpleblob>
Wed, 30 Jun 2004 10:16:14 +0000 (10:16 +0000)
committerthepurpleblob <thepurpleblob>
Wed, 30 Jun 2004 10:16:14 +0000 (10:16 +0000)
mod/quiz/format.php

index 2af24e200cafdb7548cb7fd83b3ce4b7ed895fcd..e1cb9e3501bf5676a1199f27fc3c72c05328a0f4 100644 (file)
@@ -6,7 +6,7 @@
 /// Doesn't do everything on it's own -- it needs to be extended. //
 ////////////////////////////////////////////////////////////////////
 
-// Included by import.php
+// Included by import.php and export.php
 
 class quiz_default_format {
 
@@ -142,6 +142,80 @@ class quiz_default_format {
         return true;
     }
 
+// Export functions
+
+
+    function exportpreprocess($category) {
+    /// Does any pre-processing that may be desired
+
+        $this->category = $category;  // Important
+
+        return true;
+    }
+
+    function exportprocess($filename) {
+    /// Exports a given category.  There's probably little need to change this
+
+        global $CFG;
+
+        // create a directory for the exports (if not already existing)
+        $dirname = get_string("exportfilename","quiz");
+        $courseid = $this->category->course;
+        $path = $CFG->dataroot.'/'.$courseid.'/'.$dirname;
+        if (!is_dir($path)) {
+            if (!mkdir($path, $CFG->directorypermissions)) {
+              error("Cannot create path: $path");
+            }
+        }
+
+        // get the questions (from database) in this category
+        // $questions = get_records("quiz_questions","category",$this->category->id);
+        $questions = get_questions_category( $this->category );
+
+        notify("Exporting ".count($questions)." questions.");
+        $count = 0;
+
+        // results are first written into string (and then to a file)
+        // so create/initialize the string here
+        $expout = "";
+
+        // iterate through questions
+        foreach($questions as $question) {
+          $count++;
+          echo "<hr><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
+          $expout .= $this->writequestion( $question );
+          }
+
+        // write file
+        $filepath = $path."/".$filename;
+        if (!$fh=fopen($filepath,"w")) {
+            error("Cannot open for writing: $filepath");
+        }
+        if (!fwrite($fh, $expout)) {
+            error("Cannot write exported questions to $filepath");
+        }
+        fclose($fh);
+
+        return true;
+    }
+
+    function exportpostprocess() {
+    /// Does any post-processing that may be desired
+    /// Argument is a simple array of question ids that 
+    /// have just been added.
+
+        return true;
+    }
+
+    function writequestion($question) {
+    /// Turns a question object into textual output in the given format 
+    /// must be overidden
+
+        echo "<p>This quiz format has not yet been completed!</p>";
+
+        return NULL;
+    }
+
 }
 
 ?>