From a39eb49fc2f554d81e78075bfb5e72cb2371b937 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 22 Sep 2011 05:17:44 +0200 Subject: [PATCH] MDL-29336 Saving grade mapping table in the Workshop The Workshop module using the "Number of errors" grading strategy did not save all items in the grade mapping table. If some assessment form fields have weight > 1, the number of possible errors is greater that the number of the assessment form fields. The previous code deleted all mappings where the number of errors was greater than the number of fields. In this patch, the maximum number of possible errors is calculated as a sum of weights of all fields. Only mappings over this maximum are deleted now. --- mod/workshop/form/numerrors/lib.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mod/workshop/form/numerrors/lib.php b/mod/workshop/form/numerrors/lib.php index 9fae313a55b..f1acce27b0a 100644 --- a/mod/workshop/form/numerrors/lib.php +++ b/mod/workshop/form/numerrors/lib.php @@ -164,6 +164,7 @@ class workshop_numerrors_strategy implements workshop_strategy { $records = $data->numerrors; // data to be saved into {workshopform_numerrors} $mappings = $data->mappings; // data to be saved into {workshopform_numerrors_map} $todelete = array(); // dimension ids to be deleted + $maxnonegative = 0; // maximum number of (weighted) negative responses for ($i=0; $i < $norepeats; $i++) { $record = $records[$i]; @@ -181,6 +182,7 @@ class workshop_numerrors_strategy implements workshop_strategy { // exiting field $DB->update_record('workshopform_numerrors', $record); } + $maxnonegative += $record->weight; // re-save with correct path to embeded media files $record = file_postupdate_standard_editor($record, 'description', $this->descriptionopts, $PAGE->context, 'workshopform_numerrors', 'description', $record->id); @@ -212,8 +214,8 @@ class workshop_numerrors_strategy implements workshop_strategy { $insql = ''; } $sql = "DELETE FROM {workshopform_numerrors_map} - WHERE (($insql nonegative > :nodimensions) AND (workshopid = :workshopid))"; - $params['nodimensions'] = $norepeats; + WHERE (($insql nonegative > :maxnonegative) AND (workshopid = :workshopid))"; + $params['maxnonegative'] = $maxnonegative; $params['workshopid'] = $this->workshop->id; $DB->execute($sql, $params); }