From ef8dc8570b9114101d5ac78161ec46f148973d7b Mon Sep 17 00:00:00 2001 From: Rushikesh Date: Thu, 14 Jan 2016 21:16:11 +0530 Subject: [PATCH] MDL-33663 Grading methods: Appropriate error message for negative grades --- grade/grading/form/guide/guideeditor.php | 5 ++++- grade/grading/form/guide/lang/en/gradingform_guide.php | 4 +++- grade/grading/form/guide/lib.php | 9 +++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/grade/grading/form/guide/guideeditor.php b/grade/grading/form/guide/guideeditor.php index e044059c0d1..153a7705079 100644 --- a/grade/grading/form/guide/guideeditor.php +++ b/grade/grading/form/guide/guideeditor.php @@ -214,9 +214,12 @@ class moodlequickform_guideeditor extends HTML_QuickForm_input { if (!strlen(trim($criterion['maxscore']))) { $errors['err_nomaxscore'] = 1; $criterion['error_description'] = true; - } else if (!is_numeric($criterion['maxscore']) || $criterion['maxscore'] < 0) { + } else if (!is_numeric($criterion['maxscore'])) { $errors['err_maxscorenotnumeric'] = 1; $criterion['error_description'] = true; + } else if ($criterion['maxscore'] < 0) { + $errors['err_maxscoreisnegative'] = 1; + $criterion['error_description'] = true; } } if (array_key_exists('moveup', $criterion) || $lastaction == 'movedown') { diff --git a/grade/grading/form/guide/lang/en/gradingform_guide.php b/grade/grading/form/guide/lang/en/gradingform_guide.php index 87f7a110c00..71e2c5d9f97 100644 --- a/grade/grading/form/guide/lang/en/gradingform_guide.php +++ b/grade/grading/form/guide/lang/en/gradingform_guide.php @@ -50,6 +50,7 @@ $string['definemarkingguide'] = 'Define marking guide'; $string['description'] = 'Description'; $string['descriptionmarkers'] = 'Description for Markers'; $string['descriptionstudents'] = 'Description for Students'; +$string['err_maxscoreisnegative'] = 'The max score is not valid, negative values are not allowed'; $string['err_maxscorenotnumeric'] = 'Criterion max score must be numeric'; $string['err_nocomment'] = 'Comment can not be empty'; $string['err_nodescription'] = 'Student description can not be empty'; @@ -57,7 +58,8 @@ $string['err_nodescriptionmarkers'] = 'Marker description can not be empty'; $string['err_nomaxscore'] = 'Criterion max score can not be empty'; $string['err_noshortname'] = 'Criterion name can not be empty'; $string['err_shortnametoolong'] = 'Criterion name must be less than 256 characters'; -$string['err_scoreinvalid'] = 'The score given to {$a->criterianame} is not valid, the max score is: {$a->maxscore}'; +$string['err_scoreinvalid'] = 'The score given to \'{$a->criterianame}\' is not valid, the max score is: {$a->maxscore}'; +$string['err_scoreisnegative'] = 'The score given to \'{$a->criterianame}\' is not valid, negative values are not allowed'; $string['gradingof'] = '{$a} grading'; $string['guide'] = 'Marking guide'; $string['guidemappingexplained'] = 'WARNING: Your marking guide has a maximum grade of {$a->maxscore} points but the maximum grade set in your activity is {$a->modulegrade} The maximum score set in your marking guide will be scaled to the maximum grade in the module.
diff --git a/grade/grading/form/guide/lib.php b/grade/grading/form/guide/lib.php index a6c17eb4927..25c797e5083 100644 --- a/grade/grading/form/guide/lib.php +++ b/grade/grading/form/guide/lib.php @@ -795,7 +795,7 @@ class gradingform_guide_instance extends gradingform_instance { || $criterion['maxscore'] < $elementvalue['criteria'][$id]['score'] || !is_numeric($elementvalue['criteria'][$id]['score']) || $elementvalue['criteria'][$id]['score'] < 0) { - $this->validationerrors[$id]['score'] = $elementvalue['criteria'][$id]['score']; + $this->validationerrors[$id]['score'] = $elementvalue['criteria'][$id]['score']; } } if (!empty($this->validationerrors)) { @@ -943,8 +943,13 @@ class gradingform_guide_instance extends gradingform_instance { $a = new stdClass(); $a->criterianame = s($criteria[$id]['shortname']); $a->maxscore = $criteria[$id]['maxscore']; - $html .= html_writer::tag('div', get_string('err_scoreinvalid', 'gradingform_guide', $a), + if ($this->validationerrors[$id]['score'] < 0) { + $html .= html_writer::tag('div', get_string('err_scoreisnegative', 'gradingform_guide', $a), array('class' => 'gradingform_guide-error')); + } else { + $html .= html_writer::tag('div', get_string('err_scoreinvalid', 'gradingform_guide', $a), + array('class' => 'gradingform_guide-error')); + } } } }