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();
$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;
$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.';
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[] = '{}';
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;
}
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));
}
}
}