MDL-75727 question regrading: fix each attempt builds on last

This fixes a regression caused by MDL-74752. If you regraded
a subsequent quiz attempt in a quiz using the 'Each attempt
builds on last' option, then the student's response could get lost.
This commit is contained in:
Tim Hunt 2022-09-12 17:02:54 +01:00
parent e4c5a12a1c
commit 06c63f7aa1
6 changed files with 136 additions and 5 deletions

View file

@ -126,7 +126,7 @@ class qtype_match_question extends question_graded_automatically_with_countback
public function update_attempt_state_data_for_new_version(
question_attempt_step $oldstep, question_definition $otherversion) {
parent::update_attempt_state_data_for_new_version($oldstep, $otherversion);
$startdata = parent::update_attempt_state_data_for_new_version($oldstep, $otherversion);
// Process stems.
$mapping = array_combine(array_keys($otherversion->stems), array_keys($this->stems));
@ -135,6 +135,7 @@ class qtype_match_question extends question_graded_automatically_with_countback
foreach ($oldstemorder as $oldid) {
$newstemorder[] = $mapping[$oldid] ?? $oldid;
}
$startdata['_stemorder'] = implode(',', $newstemorder);
// Process choices.
$mapping = array_combine(array_keys($otherversion->choices), array_keys($this->choices));
@ -143,8 +144,9 @@ class qtype_match_question extends question_graded_automatically_with_countback
foreach ($oldchoiceorder as $oldid) {
$newchoiceorder[] = $mapping[$oldid] ?? $oldid;
}
$startdata['_choiceorder'] = implode(',', $newchoiceorder);
return ['_stemorder' => implode(',', $newstemorder), '_choiceorder' => implode(',', $newchoiceorder)];
return $startdata;
}
public function get_question_summary() {

View file

@ -274,7 +274,7 @@ class question_test extends \advanced_testcase {
$newm->validate_can_regrade_with_other_version($m));
}
public function test_update_attempt_state_date_from_old_version_bad() {
public function test_update_attempt_state_date_from_old_version_bad() {
$m = \test_question_maker::make_question('match');
$newm = clone($m);