diff --git a/question/format/multianswer/format.php b/question/format/multianswer/format.php index 531330c0db593..950f395f2c4db 100644 --- a/question/format/multianswer/format.php +++ b/question/format/multianswer/format.php @@ -1,16 +1,36 @@ . + +/** + * This defines the core classes of the Moodle question engine. + * + * @package qformat + * @subpackage qformat_multianswer + * @copyright 2003 Henrik Kaipe + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + /** - * @package questionbank - * @subpackage importexport + * Importer that imports a text file containing a single Multianswer question + * from a text file. + * + * @copyright 2003 Henrik Kaipe + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qformat_multianswer extends qformat_default { @@ -19,25 +39,32 @@ function provide_import() { } function readquestions($lines) { - // Parses an array of lines into an array of questions. // For this class the method has been simplified as // there can never be more than one question for a // multianswer import + $questions = array(); + + $question = qtype_multianswer_extract_question(implode('', $lines)); + $question->qtype = MULTIANSWER; + $question->generalfeedback = ''; + $question->course = $this->course; - $questions= array(); - $thequestion= qtype_multianswer_extract_question( - implode('',$lines)); - $thequestion->qtype = MULTIANSWER; - $thequestion->course = $this->course; + if (!empty($question)) { + $name = html_to_text(implode(' ', $lines)); + $name = preg_replace('/{[^}]*}/', '', $name); + $name = trim($name); - if (!empty($thequestion)) { - $thequestion->name = $lines[0]; + if ($name) { + $question->name = shorten_text($name, 45); + } else { + // We need some name, so use the current time, since that will be + // reasonably unique. + $question->name = userdate(time()); + } - $questions[] = $thequestion; + $questions[] = $question; } return $questions; } } - -