MDL-74752 qtypes gapselect & ddwtos: implement regrading hooks

This commit is contained in:
Tim Hunt
2022-05-31 09:22:22 +01:00
parent 823b5bb740
commit 8ca7e3b74c
3 changed files with 51 additions and 0 deletions
@@ -45,6 +45,8 @@ $string['privacy:metadata'] = 'Select missing words question type plugin allows
$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 in group {$a} changed.';
$string['regradeissuenumgroupsschanged'] = 'The number of groups of choices has changed.';
$string['shuffle'] = 'Shuffle';
$string['tagsnotallowed'] = '{$a->tag} is not allowed. (Only {$a->allowed} are permitted.)';
$string['tagsnotallowedatall'] = '{$a->tag} is not allowed. (No HTML is allowed here.)';
+19
View File
@@ -112,6 +112,25 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
}
}
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->choices) != count($otherversion->choices)) {
return get_string('regradeissuenumgroupsschanged', 'qtype_gapselect');
}
foreach ($this->choices as $group => $choices) {
if (count($this->choices[$group]) != count($otherversion->choices[$group])) {
return get_string('regradeissuenumchoiceschanged', 'qtype_gapselect', $group);
}
}
return null;
}
public function get_question_summary() {
$question = $this->html_to_text($this->questiontext, $this->questiontextformat);
$groups = array();
@@ -34,6 +34,8 @@ require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
* @package qtype_gapselect
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \qtype_gapselect_question_base
* @covers \qtype_gapselect_question
*/
class question_test extends \basic_testcase {
@@ -258,4 +260,32 @@ class question_test extends \basic_testcase {
$options = $question->get_question_definition_for_external_rendering($qa, $displayoptions);
$this->assertEquals(1, $options['shufflechoices']);
}
public function test_validate_can_regrade_with_other_version_ok() {
$question = \test_question_maker::make_question('gapselect');
$newquestion = clone($question);
$this->assertNull($newquestion->validate_can_regrade_with_other_version($question));
}
public function test_validate_can_regrade_with_other_version_bad_groups() {
$question = \test_question_maker::make_question('gapselect');
$newquestion = clone($question);
unset($newquestion->choices[3]);
$this->assertEquals(get_string('regradeissuenumgroupsschanged', 'qtype_gapselect'),
$newquestion->validate_can_regrade_with_other_version($question));
}
public function test_validate_can_regrade_with_other_version_bad_choices() {
$question = \test_question_maker::make_question('gapselect');
$newquestion = clone($question);
unset($newquestion->choices[2][2]);
$this->assertEquals(get_string('regradeissuenumchoiceschanged', 'qtype_gapselect', 2),
$newquestion->validate_can_regrade_with_other_version($question));
}
}