From 90455bb3abd5900c7479087f356d1533de7e241f Mon Sep 17 00:00:00 2001 From: mark-nielsen Date: Sun, 26 Mar 2006 00:10:39 +0000 Subject: [PATCH] [Fixed] Import. Updated code to work with /question instead of /mod/quiz. Lead to a few interal bug fixes. Also moved two hard coded strings to the lang file. --- mod/lesson/format.php | 32 ++++++++++++++++++++++++++------ mod/lesson/import.php | 10 +++++----- mod/lesson/locallib.php | 2 +- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/mod/lesson/format.php b/mod/lesson/format.php index e40dcebc23..c26aad2f85 100644 --- a/mod/lesson/format.php +++ b/mod/lesson/format.php @@ -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 "

$count. ".stripslashes($question->questiontext)."

"; $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 "

Unsupported question type ($question->qtype)!

"; + 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 diff --git a/mod/lesson/import.php b/mod/lesson/import.php index bbc3d25254..96eb0a3ff7 100644 --- a/mod/lesson/import.php +++ b/mod/lesson/import.php @@ -46,15 +46,15 @@ } 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.php - require("$CFG->dirroot/mod/quiz/format/$form->format/format.php"); + require("$CFG->libdir/questionlib.php"); // for the constants used in quiz/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'); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 79b31b7021..e7dfb4c683 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -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 "
"; exit; + $answertext = $question->subanswers[$key]; if (!empty($questiontext) and !empty($answertext)) { $answer = new stdClass; $answer->lessonid = $question->lessonid; -- 2.39.5