Skip to content

Commit

Permalink
MDL-74752 qtype_match: implement regrading hooks
Browse files Browse the repository at this point in the history
As much as they can be before MDL-5560 is addressed.
  • Loading branch information
timhunt committed May 31, 2022
1 parent 5ad18a4 commit cc26212
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
6 changes: 4 additions & 2 deletions question/type/match/lang/en/qtype_match.php
Expand Up @@ -33,8 +33,6 @@
$string['nomatchinganswerforq'] = 'You must specify an answer for this question.';
$string['notenoughqsandas'] = 'You must supply at least {$a->q} questions and {$a->a} answers.';
$string['notenoughquestions'] = 'You must supply at least {$a} question and answer pairs.';
$string['shuffle'] = 'Shuffle';
$string['shuffle_help'] = 'If enabled, the order of the questions is randomly shuffled for each attempt, provided that "Shuffle within questions" in the activity settings is also enabled. In a matching question, only the questions are affected by this parameter. The answer choices will always be shuffled.';
$string['pleaseananswerallparts'] = 'Please answer all parts of the question.';
$string['pluginname'] = 'Matching';
$string['pluginname_help'] = 'Matching questions require the respondent to correctly match a list of names or statements (questions) to another list of names or statements (answers).';
Expand All @@ -46,3 +44,7 @@
$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.';
$string['privacy:preference:penalty'] = 'The penalty for each incorrect try when questions are run using the \'Interactive with multiple tries\' or \'Adaptive mode\' behaviour.';
$string['privacy:preference:shuffleanswers'] = 'Whether the answers should be automatically shuffled.';
$string['regradeissuenumchoiceschanged'] = 'The number of choices has changed.';
$string['regradeissuenumstemschanged'] = 'The number of sub-questions has changed.';
$string['shuffle'] = 'Shuffle';
$string['shuffle_help'] = 'If enabled, the order of the questions is randomly shuffled for each attempt, provided that "Shuffle within questions" in the activity settings is also enabled. In a matching question, only the questions are affected by this parameter. The answer choices will always be shuffled.';
17 changes: 17 additions & 0 deletions question/type/match/question.php
Expand Up @@ -107,6 +107,23 @@ protected function set_choiceorder($choiceorder) {
}
}

public function validate_can_regrade_with_other_version(question_definition $otherversion): ?string {
$basemessage = parent::validate_can_regrade_with_other_version($otherversion);
if ($basemessage) {
return $basemessage;
}

if (count($this->stems) != count($otherversion->stems)) {
return get_string('regradeissuenumstemschanged', 'qtype_match');
}

if (count($this->choices) != count($otherversion->choices)) {
return get_string('regradeissuenumchoiceschanged', 'qtype_match');
}

return null;
}

public function get_question_summary() {
$question = $this->html_to_text($this->questiontext, $this->questiontextformat);
$stems = array();
Expand Down
29 changes: 29 additions & 0 deletions question/type/match/tests/question_test.php
Expand Up @@ -33,6 +33,7 @@
* @package qtype_match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \qtype_match_question
*/
class question_test extends \advanced_testcase {

Expand Down Expand Up @@ -244,4 +245,32 @@ public function test_get_question_definition_for_external_rendering() {
$options = $question->get_question_definition_for_external_rendering($qa, $displayoptions);
$this->assertEquals(1, $options['shufflestems']);
}

public function test_validate_can_regrade_with_other_version_ok() {
$m = \test_question_maker::make_question('match');

$newm = clone($m);

$this->assertNull($newm->validate_can_regrade_with_other_version($m));
}

public function test_validate_can_regrade_with_other_version_bad_stems() {
$m = \test_question_maker::make_question('match');

$newm = clone($m);
unset($newm->stems[4]);

$this->assertEquals(get_string('regradeissuenumstemschanged', 'qtype_match'),
$newm->validate_can_regrade_with_other_version($m));
}

public function test_validate_can_regrade_with_other_version_bad_choices() {
$m = \test_question_maker::make_question('match');

$newm = clone($m);
unset($newm->choices[3]);

$this->assertEquals(get_string('regradeissuenumchoiceschanged', 'qtype_match'),
$newm->validate_can_regrade_with_other_version($m));
}
}

0 comments on commit cc26212

Please sign in to comment.