diff --git a/lang/en/question.php b/lang/en/question.php index 3dea4dddf7ea7..d7d58fe0fd9d3 100644 --- a/lang/en/question.php +++ b/lang/en/question.php @@ -421,6 +421,7 @@ $string['technicalinforightsummary'] = 'Right answer summary: {$a}'; $string['technicalinfostate'] = 'Question state: {$a}'; $string['unknownbehaviour'] = 'Unknown behaviour: {$a}.'; +$string['unknownorunhandledtype'] = 'Unknown or unhandled question type: {$a}'; $string['unknownquestion'] = 'Unknown question: {$a}.'; $string['unknownquestioncatregory'] = 'Unknown question category: {$a}.'; $string['unknownquestiontype'] = 'Unknown question type: {$a}.'; diff --git a/question/format/blackboard_six/formatqti.php b/question/format/blackboard_six/formatqti.php index 6b9eddafbbf7c..744456c472375 100644 --- a/question/format/blackboard_six/formatqti.php +++ b/question/format/blackboard_six/formatqti.php @@ -87,7 +87,7 @@ protected function readquestions($text) { $this->process_essay($question, $questions); break; default: - $this->error(get_string('unknownorunhandledtype', 'qformat_blackboard_six', $question->qtype)); + $this->error(get_string('unknownorunhandledtype', 'question', $question->qtype)); break; } } diff --git a/question/format/blackboard_six/lang/en/qformat_blackboard_six.php b/question/format/blackboard_six/lang/en/qformat_blackboard_six.php index c7c4746d6bb9f..c7c925e6ae476 100644 --- a/question/format/blackboard_six/lang/en/qformat_blackboard_six.php +++ b/question/format/blackboard_six/lang/en/qformat_blackboard_six.php @@ -31,4 +31,3 @@ $string['pluginname'] = 'Blackboard V6+'; $string['pluginname_help'] = 'Blackboard V6+ format enables questions saved in all Blackboard export formats to be imported via a dat or zip file. For zip files, images import is supported.'; $string['unhandledpresblock'] = 'Unhandled presentation block'; -$string['unknownorunhandledtype'] = 'Unknown or unhandled question type: {$a}'; diff --git a/question/format/examview/format.php b/question/format/examview/format.php index 21554012c4c6b..95f4e1cb2e4f0 100644 --- a/question/format/examview/format.php +++ b/question/format/examview/format.php @@ -184,6 +184,7 @@ public function readquestions($lines) { } public function readquestion($qrec) { + global $OUTPUT; $type = trim($qrec['@']['type']); $question = $this->defaultquestion(); @@ -224,7 +225,7 @@ public function readquestion($qrec) { break; break; default: - print("

Question type ".$type." import not supported for ".$question->questiontext."

"); + echo $OUTPUT->notification(get_string('unknownorunhandledtype', 'question', $type)); $question = null; } diff --git a/question/format/learnwise/format.php b/question/format/learnwise/format.php index 873da65adf5b1..8c36fc1611839 100644 --- a/question/format/learnwise/format.php +++ b/question/format/learnwise/format.php @@ -67,6 +67,8 @@ protected function readquestions($lines) { } protected function readquestion($lines) { + global $OUTPUT; + $text = implode(' ', $lines); $text = str_replace(array('\t','\n','\r'), array('','',''), $text); @@ -131,7 +133,7 @@ protected function readquestion($lines) { } } else { - echo "

I don't understand this question type (type = $type).

\n"; + echo $OUTPUT->notification(get_string('unknownorunhandledtype', 'question', $type)); } $question = $this->defaultquestion(); diff --git a/question/format/missingword/format.php b/question/format/missingword/format.php index c79998df2ee8c..e92fc54abd4ec 100644 --- a/question/format/missingword/format.php +++ b/question/format/missingword/format.php @@ -52,11 +52,11 @@ */ class qformat_missingword extends qformat_default { - function provide_import() { + public function provide_import() { return true; } - function readquestion($lines) { + public function readquestion($lines) { /// Given an array of lines known to define a question in /// this format, this function converts it into a question /// object suitable for processing and insertion into Moodle. @@ -70,28 +70,23 @@ function readquestion($lines) { $answerstart = strpos($text, "{"); if ($answerstart === false) { - if ($this->displayerrors) { - echo "

$text

Could not find a {"; - } + $this->error(get_string('beginanswernotfound', 'qformat_missingword'), $text); return false; } $answerfinish = strpos($text, "}"); if ($answerfinish === false) { - if ($this->displayerrors) { - echo "

$text

Could not find a }"; - } + $this->error(get_string('endanswernotfound', 'qformat_missingword'), $text); return false; } $answerlength = $answerfinish - $answerstart; $answertext = substr($text, $answerstart + 1, $answerlength - 1); - /// Save the new question text + // Save the new question text. $question->questiontext = substr_replace($text, "_____", $answerstart, $answerlength+1); $question->name = $this->create_default_question_name($question->questiontext, get_string('questionname', 'question')); - /// Parse the answers $answertext = str_replace("=", "~=", $answertext); $answers = explode("~", $answertext); @@ -105,10 +100,8 @@ function readquestion($lines) { $countanswers = count($answers); switch ($countanswers) { - case 0: // invalid question - if ($this->displayerrors) { - echo "

No answers found in $answertext"; - } + case 0: // Invalid question. + $this->error(get_string('noanswerfound', 'qformat_missingword'), $answertext); return false; case 1: @@ -120,12 +113,14 @@ function readquestion($lines) { } $question->answer[] = $answer; $question->fraction[] = 1; - $question->feedback[] = ""; + $question->feedback[] = array('text' => '', 'format' => FORMAT_HTML); return $question; default: $question->qtype = 'multichoice'; + $question = $this->add_blank_combined_feedback($question); + $question->single = 1; // Only one answer allowed. foreach ($answers as $key => $answer) { $answer = trim($answer); @@ -166,8 +161,8 @@ function readquestion($lines) { # $question->fraction[$key] = 0; $question->fraction[$key] = $answeight; } - $question->answer[$key] = $answer; - $question->feedback[$key] = $comment; + $question->answer[$key] = array('text' => $answer, 'format' => FORMAT_HTML); + $question->feedback[$key] = array('text' => $comment, 'format' => FORMAT_HTML); } return $question; diff --git a/question/format/missingword/lang/en/qformat_missingword.php b/question/format/missingword/lang/en/qformat_missingword.php index 0e190a3c0d437..e1fd498035260 100644 --- a/question/format/missingword/lang/en/qformat_missingword.php +++ b/question/format/missingword/lang/en/qformat_missingword.php @@ -26,3 +26,6 @@ $string['pluginname'] = 'Missing word format'; $string['pluginname_help'] = 'Missing word format enables questions to be imported via text file.'; $string['pluginname_link'] = 'Missing word format'; +$string['beginanswernotfound'] = 'Could not find a required "{" character in imported file content.'; +$string['endanswernotfound'] = 'Could not find a required "}" character in imported file content.'; +$string['noanswerfound'] = 'No answers found in question'; diff --git a/question/format/missingword/tests/fixtures/question.missingword1.txt b/question/format/missingword/tests/fixtures/question.missingword1.txt new file mode 100644 index 0000000000000..0580c40333e35 --- /dev/null +++ b/question/format/missingword/tests/fixtures/question.missingword1.txt @@ -0,0 +1,3 @@ +As soon as we begin to explore our body parts as infants +we become students of {=anatomy and physiology ~reflexology +~science ~experiment}, and in a sense we remain students for life. diff --git a/question/format/missingword/tests/fixtures/question.missingword2.txt b/question/format/missingword/tests/fixtures/question.missingword2.txt new file mode 100644 index 0000000000000..77b58de705934 --- /dev/null +++ b/question/format/missingword/tests/fixtures/question.missingword2.txt @@ -0,0 +1,2 @@ +You can use the missing word format to import questions +into both Moodle's Question bank and {=Lesson} activity. diff --git a/question/format/missingword/tests/fixtures/question.missingword3.txt b/question/format/missingword/tests/fixtures/question.missingword3.txt new file mode 100644 index 0000000000000..e202f824f4d56 --- /dev/null +++ b/question/format/missingword/tests/fixtures/question.missingword3.txt @@ -0,0 +1,2 @@ +This is {=the best answer#comment on the best answer ~75%a good +answer#comment on the good answer ~a wrong one#comment on the bad answer} diff --git a/question/format/xhtml/format.php b/question/format/xhtml/format.php index a8c9a97250f11..256db70534058 100644 --- a/question/format/xhtml/format.php +++ b/question/format/xhtml/format.php @@ -93,7 +93,7 @@ protected function writequestion($question) { } $expout .= "\n"; break; - case SHORTANSWER: + case 'shortanswer': $expout .= html_writer::start_tag('ul', array('class' => 'shortanswer')); $expout .= html_writer::start_tag('li'); $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); @@ -101,7 +101,7 @@ protected function writequestion($question) { $expout .= html_writer::end_tag('li'); $expout .= html_writer::end_tag('ul'); break; - case NUMERICAL: + case 'numerical': $expout .= html_writer::start_tag('ul', array('class' => 'numerical')); $expout .= html_writer::start_tag('li'); $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); @@ -109,7 +109,7 @@ protected function writequestion($question) { $expout .= html_writer::end_tag('li'); $expout .= html_writer::end_tag('ul'); break; - case MATCH: + case 'match': $expout .= html_writer::start_tag('ul', array('class' => 'match')); // build answer list @@ -140,11 +140,9 @@ protected function writequestion($question) { break; case 'description': break; - case 'multichoice': - $expout .= "\n"; - break; + case 'multianswer': default: - echo $OUTPUT->notification("No handler for qtype $question->qtype for GIFT export" ); + $expout .= "\n"; } // close off div $expout .= "\n\n\n";