/**
- * Definition class for embedded element in question text question. Parent of drag and drop and select from
- * drop down list and ?others? *
+ * Definition class for embedded element in question text question. Parent of
+ * gap-select, drag and drop and possibly others.
*
* @package qtype
* @subpackage gapselect
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class qtype_gapselect_question_base extends question_graded_automatically_with_countback {
+abstract class qtype_gapselect_question_base extends question_graded_automatically_with_countback {
/** @var boolean Whether the question stems should be shuffled. */
public $shufflechoices;
}
public function get_question_summary() {
- $question = html_to_text($this->format_questiontext(), 0, false);
+ $question = $this->html_to_text($this->questiontext);
$groups = array();
foreach ($this->choices as $group => $choices) {
$cs = array();
foreach ($choices as $choice) {
- $cs[] = html_to_text($this->format_text($choice->text), 0, false);
+ $cs[] = $this->html_to_text($choice->text);
}
$groups[] = '[[' . $group . ']] -> {' . implode(' / ', $cs) . '}';
}
foreach ($this->places as $place => $group) {
if (array_key_exists($this->field($place), $response) &&
$response[$this->field($place)]) {
- $choices[] = '{' . html_to_text($this->format_text($this->get_selected_choice(
- $group, $response[$this->field($place)])->text), 0, false) . '}';
+ $choices[] = '{' . $this->html_to_text($this->get_selected_choice(
+ $group, $response[$this->field($place)])->text) . '}';
$allblank = false;
} else {
$choices[] = '{}';
$choiceno = $this->choiceorder[$group][$response[$fieldname]];
$choice = $this->choices[$group][$choiceno];
$parts[$place] = new question_classified_response(
- $choiceno, html_to_text($this->format_text($choice->text), 0, false),
+ $choiceno, $this->html_to_text($choice->text),
$this->get_right_choice_for($place) == $response[$fieldname]);
}
return $parts;
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class qtype_gapselect_base extends question_type {
+abstract class qtype_gapselect_base extends question_type {
/**
* Choices are stored in the question_answers table, and any options need to
* be put into the feedback field somehow. This method is responsible for
}
$update = true;
- $options = get_record('question_'.$this->name(), 'questionid', $question->id);
+ $options = get_record('question_' . $this->name(), 'questionid', $question->id);
if (!$options) {
$update = false;
$options = new stdClass;
$question->shufflechoices = $questiondata->options->shuffleanswers;
- $question->correctfeedback = $questiondata->options->correctfeedback;
- $question->partiallycorrectfeedback = $questiondata->options->partiallycorrectfeedback;
- $question->incorrectfeedback = $questiondata->options->incorrectfeedback;
- $question->shownumcorrect = $questiondata->options->shownumcorrect;
+ $this->initialise_combined_feedback($question, $questiondata, true);
$question->choices = array();
$choiceindexmap= array();
return $answers;
}
- /* This method gets the choices (answers) and sort them by groups
+ /**
+ * This method gets the choices (answers) and sort them by groups
* in a 2 dimentional array.
*
* @param object $question
protected function get_array_of_groups($question, $state) {
$answers = $this->get_array_of_choices($question);
$arr = array();
- for($group=1;$group<count($answers);$group++) {
- $players = $this->get_group_of_players ($question, $state, $answers, $group);
- if($players) {
- $arr [$group]= $players;
+ for ($group=1; $group < count($answers); $group++) {
+ $players = $this->get_group_of_players($question, $state, $answers, $group);
+ if ($players) {
+ $arr[$group]= $players;
}
}
return $arr;
foreach ($question->choices[$group] as $i => $choice) {
$choices[$i] = new question_possible_response(
- html_to_text($question->format_text($choice->text), 0, false),
+ $question->html_to_text($choice->text),
$question->rightchoices[$place] == $i);
}
$choices[null] = question_possible_response::no_response();
class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base {
+ public function test_interactive_behaviour() {
+ // Create a gapselect question.
+ $q = qtype_gapselect_test_helper::make_a_gapselect_question();
+ $q->hints = array(
+ new question_hint_with_parts('This is the first hint.', false, false),
+ new question_hint_with_parts('This is the second hint.', true, true),
+ );
+ $ql->shufflechoices = false;
+ $this->start_attempt_at_question($q, 'interactive', 3);
+ // Check the initial state.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_select_expectation('p1',
+ array('' => ' ', '1' => 'quick', '2' => 'slow'), null, true),
+ $this->get_contains_select_expectation('p2',
+ array('' => ' ', '1' => 'fox', '2' => 'dog'), null, true),
+ $this->get_contains_select_expectation('p3',
+ array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), null, true),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_feedback_expectation(),
+ $this->get_tries_remaining_expectation(3),
+ $this->get_no_hint_visible_expectation());
+
+ // Save the wrong answer.
+ $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2'));
+
+ // Verify.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_select_expectation('p1',
+ array('' => ' ', '1' => 'quick', '2' => 'slow'), 2, true),
+ $this->get_contains_select_expectation('p2',
+ array('' => ' ', '1' => 'fox', '2' => 'dog'), 2, true),
+ $this->get_contains_select_expectation('p3',
+ array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 2, true),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_does_not_contain_feedback_expectation(),
+ $this->get_tries_remaining_expectation(3),
+ $this->get_no_hint_visible_expectation());
+
+ // Submit the wrong answer.
+ $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1));
+
+ // Verify.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_select_expectation('p1',
+ array('' => ' ', '1' => 'quick', '2' => 'slow'), 2, false),
+ $this->get_contains_select_expectation('p2',
+ array('' => ' ', '1' => 'fox', '2' => 'dog'), 2, false),
+ $this->get_contains_select_expectation('p3',
+ array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 2, false),
+ $this->get_contains_submit_button_expectation(false),
+ $this->get_contains_try_again_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ new PatternExpectation('/' . preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
+ $this->get_contains_hint_expectation('This is the first hint'));
+
+ // Do try again.
+ $this->process_submission(array('-tryagain' => 1));
+
+ // Verify.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_select_expectation('p1',
+ array('' => ' ', '1' => 'quick', '2' => 'slow'), 2, true),
+ $this->get_contains_select_expectation('p2',
+ array('' => ' ', '1' => 'fox', '2' => 'dog'), 2, true),
+ $this->get_contains_select_expectation('p3',
+ array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 2, true),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_does_not_contain_feedback_expectation(),
+ $this->get_tries_remaining_expectation(2),
+ $this->get_no_hint_visible_expectation());
+
+ // Submit the right answer.
+ $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1));
+
+ // Verify.
+ $this->check_current_state(question_state::$gradedright);
+ $this->check_current_mark(2);
+ $this->check_current_output(
+ $this->get_contains_select_expectation('p1',
+ array('' => ' ', '1' => 'quick', '2' => 'slow'), 1, false),
+ $this->get_contains_select_expectation('p2',
+ array('' => ' ', '1' => 'fox', '2' => 'dog'), 1, false),
+ $this->get_contains_select_expectation('p3',
+ array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 1, false),
+ $this->get_contains_submit_button_expectation(false),
+ $this->get_contains_correct_expectation(),
+ $this->get_no_hint_visible_expectation());
+
+ // Check regrading does not mess anything up.
+ $this->quba->regrade_all_questions();
+
+ // Verify.
+ $this->check_current_state(question_state::$gradedright);
+ $this->check_current_mark(2);
+ }
}