]> git.mjollnir.org Git - moodle.git/commitdiff
[Fixed] Import. Updated code to work with /question instead of /mod/quiz. Lead...
authormark-nielsen <mark-nielsen>
Sun, 26 Mar 2006 00:10:39 +0000 (00:10 +0000)
committermark-nielsen <mark-nielsen>
Sun, 26 Mar 2006 00:10:39 +0000 (00:10 +0000)
mod/lesson/format.php
mod/lesson/import.php
mod/lesson/locallib.php

index e40dcebc233b54255cf3eb864b787a4f81933934..c26aad2f855dede1187562c324758c45c42bdd43 100644 (file)
@@ -8,11 +8,17 @@
 
 // Included by import.php
 
-class quiz_default_format {
+class qformat_default {
 
     var $displayerrors = true;
     var $category = NULL;
     var $questionids = array();
+    var $qtypeconvert = array(NUMERICAL   => LESSON_NUMERICAL,
+                              MULTICHOICE => LESSON_MULTICHOICE,
+                              TRUEFALSE   => LESSON_TRUEFALSE,
+                              SHORTANSWER => LESSON_SHORTANSWER,
+                              MATCH       => LESSON_MATCHING
+                              );
 
 /// Importing functions
 
@@ -35,8 +41,8 @@ class quiz_default_format {
             notify("There are no questions in this file!");
             return false;
         }
-
-        notify("Importing ".count($questions)." questions");
+        
+        notify(get_string('importcount', 'lesson', sizeof($questions)));
 
         $count = 0;
 
@@ -53,10 +59,12 @@ class quiz_default_format {
                     echo "<hr><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
                     $newpage = new stdClass;
                     $newpage->lessonid = $lesson->id;
-                    $newpage->qtype = $question->qtype;
+                    $newpage->qtype = $this->qtypeconvert[$question->qtype];
                     switch ($question->qtype) {
                         case SHORTANSWER :
-                            $newpage->qoption = $question->usecase;
+                            if (isset($question->usecase)) {
+                                $newpage->qoption = $question->usecase;
+                            }
                             break;
                         case MULTICHOICE :
                             if (isset($question->single)) {
@@ -123,6 +131,7 @@ class quiz_default_format {
                     // Now to save all the answers and type-specific options
 
                     $question->lessonid = $lesson->id; // needed for foreign key
+                    $question->qtype = $this->qtypeconvert[$question->qtype];
                     $result = lesson_save_question_options($question);
 
                     if (!empty($result->error)) {
@@ -137,7 +146,7 @@ class quiz_default_format {
                     break;
             // the Bad ones
                 default :
-                    echo "<p>Unsupported question type ($question->qtype)!</p>";
+                    notify(get_string('unsupportedqtype', 'lesson', $question->qtype));
             }
  
         }
@@ -204,6 +213,17 @@ class quiz_default_format {
         return NULL;
     }
 
+    function defaultquestion() {
+    // returns an "empty" question
+    // Somewhere to specify question parameters that are not handled
+    // by import but are required db fields.
+    // This should not be overridden. 
+        $question = new stdClass();
+        $question->qoption = 0;
+        $question->layout = 1;
+        
+        return $question;
+    }
 
     function importpostprocess() {
     /// Does any post-processing that may be desired
index bbc3d2525400af83df95c08829e7a137c883daa6..96eb0a3ff73e12c2f06147a9b48934e78097776a 100644 (file)
 
         } else {  // Valid file is found
 
-            if (! is_readable("../quiz/format/$form->format/format.php")) {
+            if (! is_readable("$CFG->dirroot/question/format/$form->format/format.php")) {
                 error("Format not known ($form->format)");
             }
 
             require("format.php");  // Parent class
-            require("$CFG->dirroot/mod/quiz/locallib.php"); // for the constants used in quiz/format/<format>/format.php
-            require("$CFG->dirroot/mod/quiz/format/$form->format/format.php");
+            require("$CFG->libdir/questionlib.php"); // for the constants used in quiz/format/<format>/format.php
+            require("$CFG->dirroot/question/format/$form->format/format.php");
 
-            $classname = "quiz_format_$form->format";
+            $classname = "qformat_$form->format";
             $format = new $classname();
 
             if (! $format->importpreprocess()) {             // Do anything before that we need to
@@ -78,7 +78,7 @@
 
     /// Print upload form
 
-    $fileformats = get_list_of_plugins("mod/quiz/format");
+    $fileformats = get_list_of_plugins('question/format');
     $fileformatnames = array();
     foreach ($fileformats as $key => $fileformat) {
         $formatname = get_string($fileformat, 'lesson');
index 79b31b702156af6d41d8d2f65fd2c1a94563dc55..e7dfb4c6838c991082f5105f966f8354d22e0b99 100644 (file)
@@ -413,7 +413,7 @@ function lesson_save_question_options($question) {
             $i = 0;
             // Insert all the new question+answer pairs
             foreach ($question->subquestions as $key => $questiontext) {
-                $answertext = $question->subanswers[$key]; echo $answertext; echo "<br>"; exit;
+                $answertext = $question->subanswers[$key];
                 if (!empty($questiontext) and !empty($answertext)) {
                     $answer = new stdClass;
                     $answer->lessonid   = $question->lessonid;