From c2ff6d502841ce9dbe08a3b5b264496ffda9e0b3 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 7 Jul 2009 01:52:41 +0000 Subject: [PATCH] MDL-19429 Validating 0 values for grademin, grademax and gradepass for the edit category form. Also checking for grademax < grademin case. --- grade/edit/tree/category.php | 20 ++++++++++++++++---- grade/edit/tree/category_form.php | 8 ++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/grade/edit/tree/category.php b/grade/edit/tree/category.php index 90a9b37eba3..c1ab3eb6938 100644 --- a/grade/edit/tree/category.php +++ b/grade/edit/tree/category.php @@ -126,6 +126,18 @@ if ($mform->is_cancelled()) { if (!isset($itemdata->aggregationcoef)) { $itemdata->aggregationcoef = 0; } + + if (!isset($itemdata->gradepass) || $itemdata->gradepass == '') { + $itemdata->gradepass = 0; + } + + if (!isset($itemdata->grademax) || $itemdata->grademax == '') { + $itemdata->grademax = 0; + } + + if (!isset($itemdata->grademin) || $itemdata->grademin == '') { + $itemdata->grademin = 0; + } $hidden = empty($itemdata->hidden) ? 0: $itemdata->hidden; $hiddenuntil = empty($itemdata->hiddenuntil) ? 0: $itemdata->hiddenuntil; @@ -154,16 +166,16 @@ if ($mform->is_cancelled()) { if (empty($grade_item->id)) { $grade_item->id = $grade_item_copy->id; } - if (empty($grade_item->grademax)) { + if (empty($grade_item->grademax) && $grade_item->grademax != '0') { $grade_item->grademax = $grade_item_copy->grademax; } - if (empty($grade_item->grademin)) { + if (empty($grade_item->grademin) && $grade_item->grademin != '0') { $grade_item->grademin = $grade_item_copy->grademin; } - if (empty($grade_item->gradepass)) { + if (empty($grade_item->gradepass) && $grade_item->gradepass != '0') { $grade_item->gradepass = $grade_item_copy->gradepass; } - if (empty($grade_item->aggregationcoef)) { + if (empty($grade_item->aggregationcoef) && $grade_item->aggregationcoef != '0') { $grade_item->aggregationcoef = $grade_item_copy->aggregationcoef; } diff --git a/grade/edit/tree/category_form.php b/grade/edit/tree/category_form.php index 96d797512fa..5bc8806d1db 100644 --- a/grade/edit/tree/category_form.php +++ b/grade/edit/tree/category_form.php @@ -461,6 +461,14 @@ class edit_category_form extends moodleform { $errors['grade_item_scaleid'] = get_string('missingscale', 'grades'); } } + if (array_key_exists('grade_item_grademin', $data) and array_key_exists('grade_item_grademax', $data)) { + if (($data['grade_item_grademax'] != 0 OR $data['grade_item_grademin'] != 0) AND + ($data['grade_item_grademax'] == $data['grade_item_grademin'] OR + $data['grade_item_grademax'] < $data['grade_item_grademin'])) { + $errors['grade_item_grademin'] = get_string('incorrectminmax', 'grades'); + $errors['grade_item_grademax'] = get_string('incorrectminmax', 'grades'); + } + } return $errors; }