MDL-50586 gradingform_rubric: warn about missing 0-points levels

This commit is contained in:
Marina Glancy 2016-08-10 14:21:32 +08:00
parent 6f302b17b9
commit 3d91ad9946
3 changed files with 17 additions and 2 deletions

View File

@ -44,6 +44,7 @@ $string['err_mintwolevels'] = 'Each criterion must have at least two levels';
$string['err_nocriteria'] = 'Rubric must contain at least one criterion';
$string['err_nodefinition'] = 'Level definition can not be empty';
$string['err_nodescription'] = 'Criterion description can not be empty';
$string['err_novariations'] = 'Criterion levels cannot all be worth the same number of points';
$string['err_scoreformat'] = 'Number of points for each level must be a valid non-negative number';
$string['err_totalscore'] = 'Maximum number of points possible when graded by the rubric must be more than zero';
$string['gradingof'] = '{$a} grading';
@ -82,4 +83,6 @@ $string['showscorestudent'] = 'Display points for each level to those being grad
$string['showscoreteacher'] = 'Display points for each level during evaluation';
$string['sortlevelsasc'] = 'Sort order for levels:';
$string['sortlevelsasc0'] = 'Descending by number of points';
$string['sortlevelsasc1'] = 'Ascending by number of points';
$string['sortlevelsasc1'] = 'Ascending by number of points';
$string['zerolevelsabsent'] = 'Warning: The minimum possible score for this rubric is not 0; this can result in unexpected grades for the activity. To avoid this, each criterion should have a level with 0 points.<br>
This warning may be ignored if a scale is used for grading, and the minimum levels in the rubric correspond to the minimum value of the scale.';

View File

@ -633,6 +633,9 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
if (!$scores) {
return $html;
}
if ($scores['minscore'] <> 0) {
$html .= $this->output->notification(get_string('zerolevelsabsent', 'gradingform_rubric'), 'error');
}
$html .= $this->box(
html_writer::tag('h4', get_string('rubricmapping', 'gradingform_rubric')).
html_writer::tag('div', get_string('rubricmappingexplained', 'gradingform_rubric', (object)$scores))

View File

@ -197,6 +197,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
// iterate through criteria
$lastaction = null;
$lastid = null;
$overallminscore = $overallmaxscore = 0;
foreach ($value['criteria'] as $id => $criterion) {
if ($id == 'addcriterion') {
$id = $this->get_next_id(array_keys($value['criteria']));
@ -221,7 +222,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
$this->nonjsbuttonpressed = true;
}
$levels = array();
$maxscore = null;
$minscore = $maxscore = null;
if (array_key_exists('levels', $criterion)) {
foreach ($criterion['levels'] as $levelid => $level) {
if ($levelid == 'addlevel') {
@ -249,6 +250,9 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
}
}
$levels[$levelid] = $level;
if ($minscore === null || (float)$level['score'] < $minscore) {
$minscore = (float)$level['score'];
}
if ($maxscore === null || (float)$level['score'] > $maxscore) {
$maxscore = (float)$level['score'];
}
@ -268,6 +272,8 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
$errors['err_nodescription'] = 1;
$criterion['error_description'] = true;
}
$overallmaxscore += $maxscore;
$overallminscore += $minscore;
}
if (array_key_exists('moveup', $criterion) || $lastaction == 'movedown') {
unset($criterion['moveup']);
@ -307,6 +313,9 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
// create validation error string (if needed)
if ($withvalidation) {
if ($overallminscore == $overallmaxscore) {
$errors['err_novariations'] = 1;
}
if (count($errors)) {
$rv = array();
foreach ($errors as $error => $v) {