MDL-33663 Grading methods: Appropriate error message for negative grades

This commit is contained in:
Rushikesh 2016-01-14 21:16:11 +05:30
parent 2f45a11ac4
commit ef8dc8570b
3 changed files with 14 additions and 4 deletions

View File

@ -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') {

View File

@ -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 <b>{$a->maxscore} points</b> 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.<br />

View File

@ -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'));
}
}
}
}