// 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
notify("There are no questions in this file!");
return false;
}
-
- notify("Importing ".count($questions)." questions");
+
+ notify(get_string('importcount', 'lesson', sizeof($questions)));
$count = 0;
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)) {
// 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)) {
break;
// the Bad ones
default :
- echo "<p>Unsupported question type ($question->qtype)!</p>";
+ notify(get_string('unsupportedqtype', 'lesson', $question->qtype));
}
}
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
} 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
/// 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');