Skip to content
Browse files

multianswer question import MDL-11326 make a better question name.

Also fix coding style in this file.
  • Loading branch information...
1 parent b36082b commit f7046b25999a51a92421295da04279eb5c524438 @timhunt timhunt committed Aug 5, 2010
Showing with 21 additions and 14 deletions.
  1. +21 −14 question/format/multianswer/format.php
View
35 question/format/multianswer/format.php
@@ -19,25 +19,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();
- $thequestion= qtype_multianswer_extract_question(
- addslashes(implode('',$lines)));
- $thequestion->qtype = MULTIANSWER;
- $thequestion->course = $this->course;
-
- if (!empty($thequestion)) {
- $thequestion->name = addslashes($lines[0]);
-
- $questions[] = $thequestion;
+ $questions = array();
+
+ $question = qtype_multianswer_extract_question(
+ addslashes(implode('', $lines)));
+ $question->qtype = MULTIANSWER;
+ $question->course = $this->course;
+
+ if (!empty($question)) {
+ $name = html_to_text(implode(' ', $lines));
+ $name = preg_replace('/{[^}]*}/', '', $name);
+ $name = trim($name);
+
+ if ($name) {
+ $question->name = addslashes(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[] = $question;
}
return $questions;
}
}
-
-?>

0 comments on commit f7046b2

Please sign in to comment.
Something went wrong with that request. Please try again.