MDL-47494 gapselect: Bug fixes: #2009

1. Automatic display of right answer did not work if question text
contained images.

2. A choice of '0' was rejected by the form validation.

3. Hard coded strings moved to lang strings.
This commit is contained in:
Tim Hunt
2011-11-24 16:43:12 +00:00
parent 0491945d58
commit a719f4d218
4 changed files with 28 additions and 13 deletions
+10 -10
View File
@@ -215,7 +215,7 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
private function validate_slots($questiontext, $choices) {
$error = 'Please check the Question text: ';
if (!$questiontext) {
return $error . 'The question text is empty!';
return get_string('errorquestiontextblank', 'qtype_gapselect');
}
$matches = array();
@@ -223,32 +223,32 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
$slots = $matches[0];
if (!$slots) {
return $error . 'The question text is not in the correct format!';
return get_string('errornoslots', 'qtype_gapselect');
}
$output = array();
$cleanedslots = array();
foreach ($slots as $slot) {
// The 2 is for'[[' and 4 is for '[[]]'.
$output[] = substr($slot, 2, (strlen($slot)-4));
$cleanedslots[] = substr($slot, 2, (strlen($slot)-4));
}
$slots = $cleanedslots;
$slots = $output;
$found = false;
foreach ($slots as $slot) {
$found = false;
foreach ($choices as $key => $choice) {
if ($slot == $key + 1) {
if (!$choice['answer']) {
return " Please check Choices: The choice <b>$slot</b> empty.";
if ($choice['answer'] === '') {
return get_string('errorblankchoice', 'qtype_gapselect',
html_writer::tag('b', $slot));
}
$found = true;
break;
}
}
if (!$found) {
return $error . '<b>' . $slot . '</b> was not found in Choices! ' .
'(only the choice numbers that exist in choices are allowed ' .
'to be used a place holders!';
return get_string('errormissingchoice', 'qtype_gapselect',
html_writer::tag('b', $slot));
}
}
return false;
@@ -30,6 +30,10 @@ $string['choices'] = 'Choices';
$string['choicex'] = 'Choice {no}';
$string['correctansweris'] = 'The correct answer is: {$a}';
$string['editinggapselect'] = 'Editing a select missing words question';
$string['errorblankchoice'] = 'Please check the Choices: Choice {$a} is empty.';
$string['errormissingchoice'] = 'Please check the Question text: {$a} was not found in Choices! Only the choice numbers that exist in choices are allowed to be used a place holders.';
$string['errornoslots'] = 'The question text must contain placeholders like [[1]] to show where the missing words go.';
$string['errorquestiontextblank'] = 'You must enter some question text.';
$string['gapselect'] = 'Select missing words';
$string['gapselect_help'] = 'Type in some question text like "The [[1]] jumped over the [[2]]", then enter the possible words to go in gaps 1 and 2 underneath.';
$string['gapselectsummary'] = 'Missing words in some text are filled in using dropdown menus.';
+11 -2
View File
@@ -119,8 +119,8 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
foreach ($this->places as $place => $group) {
if (array_key_exists($this->field($place), $response) &&
$response[$this->field($place)]) {
$choices[] = '{' . html_to_text($this->get_selected_choice(
$group, $response[$this->field($place)])->text, 0, false) . '}';
$choices[] = '{' . $this->summarise_choice(
$this->get_selected_choice($group, $response[$this->field($place)])) . '}';
$allblank = false;
} else {
$choices[] = '{}';
@@ -132,6 +132,15 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
return implode(' ', $choices);
}
/**
* Convert a choice to plain text.
* @param qtype_gapselect_choice $choice one of the choices for a place.
* @return a plain text summary of the choice.
*/
public function summarise_choice($choice) {
return $this->html_to_text($choice->text, FORMAT_PLAIN);
}
public function get_random_guess_score() {
$accum = 0;
+3 -1
View File
@@ -104,7 +104,9 @@ abstract class qtype_elements_embedded_in_question_text_renderer
}
if (!empty($correctanswer)) {
return get_string('correctansweris', 'qtype_gapselect', $correctanswer);
return get_string('correctansweris', 'qtype_gapselect',
$question->format_text($correctanswer, $question->questiontextformat,
$qa, 'question', 'questiontext', $question->id));
}
}
}