Permalink
Browse files

[Fixed] Import. Updated code to work with /question instead of /mod/q…

…uiz. Lead to a few interal bug fixes. Also moved two hard coded strings to the lang file.
  • Loading branch information...
1 parent 6385df3 commit 90455bb3abd5900c7479087f356d1533de7e241f mark-nielsen committed Mar 26, 2006
Showing with 32 additions and 12 deletions.
  1. +26 −6 mod/lesson/format.php
  2. +5 −5 mod/lesson/import.php
  3. +1 −1 mod/lesson/locallib.php
View
@@ -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 @@ function importprocess($filename, $lesson, $pageid) {
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 @@ function importprocess($filename, $lesson, $pageid) {
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 @@ function importprocess($filename, $lesson, $pageid) {
// 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 @@ function importprocess($filename, $lesson, $pageid) {
break;
// the Bad ones
default :
- echo "<p>Unsupported question type ($question->qtype)!</p>";
+ notify(get_string('unsupportedqtype', 'lesson', $question->qtype));
}
}
@@ -204,6 +213,17 @@ function readquestion($lines) {
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
View
@@ -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>/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');
View
@@ -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;

0 comments on commit 90455bb

Please sign in to comment.