From 08fb23840ebdb531a05bed3c8fae2691c595659f Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Sun, 30 Oct 2011 20:05:27 +0100 Subject: [PATCH] MDL-30006 Workshop / Number of errors grading: force graders to actually answer the form QuickForms do not distinguish non-checked radio from the checked radio with the value "0". So we map the database grade value "0" to a value "-1" when displaying the form and vice versa when saving the form. This allowed us to have none radios checked by default and force the grader to actually answer the form themselves, using the 'required' rule. --- mod/workshop/form/numerrors/assessment_form.php | 8 +++++--- mod/workshop/form/numerrors/lib.php | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mod/workshop/form/numerrors/assessment_form.php b/mod/workshop/form/numerrors/assessment_form.php index 37babb8a4d9..90ec66f66e2 100644 --- a/mod/workshop/form/numerrors/assessment_form.php +++ b/mod/workshop/form/numerrors/assessment_form.php @@ -71,9 +71,11 @@ class workshop_numerrors_assessment_form extends workshop_assessment_form { // evaluation of the assertion $label = get_string('dimensiongrade', 'workshopform_numerrors'); - $mform->addElement('radio', 'grade__idx_' . $i, get_string('yourassessment', 'workshop'), $fields->{'grade0__idx_'.$i}, 0); - $mform->addElement('radio', 'grade__idx_' . $i, '', $fields->{'grade1__idx_'.$i}, 1); - $mform->setDefault('grade__idx_' . $i, 0); + $mform->addGroup(array( + $mform->createElement('radio', 'grade__idx_' . $i, '', $fields->{'grade0__idx_'.$i}, -1), + $mform->createElement('radio', 'grade__idx_' . $i, '', $fields->{'grade1__idx_'.$i}, 1), + ), 'group_grade__idx_' . $i, get_string('yourassessment', 'workshop'), '
', false); + $mform->addRule('group_grade__idx_' . $i, get_string('required'), 'required'); // comment $label = get_string('dimensioncomment', 'workshopform_numerrors'); diff --git a/mod/workshop/form/numerrors/lib.php b/mod/workshop/form/numerrors/lib.php index f1acce27b0a..8abe992086c 100644 --- a/mod/workshop/form/numerrors/lib.php +++ b/mod/workshop/form/numerrors/lib.php @@ -252,7 +252,7 @@ class workshop_numerrors_strategy implements workshop_strategy { $dimid = $fields->{'dimensionid__idx_'.$i}; if (isset($grades[$dimid])) { $current->{'gradeid__idx_'.$i} = $grades[$dimid]->id; - $current->{'grade__idx_'.$i} = $grades[$dimid]->grade; + $current->{'grade__idx_'.$i} = ($grades[$dimid]->grade == 0 ? -1 : 1); $current->{'peercomment__idx_'.$i} = $grades[$dimid]->peercomment; } } @@ -294,7 +294,7 @@ class workshop_numerrors_strategy implements workshop_strategy { $grade->assessmentid = $assessment->id; $grade->strategy = 'numerrors'; $grade->dimensionid = $data->{'dimensionid__idx_' . $i}; - $grade->grade = $data->{'grade__idx_' . $i}; + $grade->grade = ($data->{'grade__idx_' . $i} <= 0 ? 0 : 1); $grade->peercomment = $data->{'peercomment__idx_' . $i}; $grade->peercommentformat = FORMAT_HTML; if (empty($grade->id)) {