From 2e0d37fe418788d943ef4a9818eac9ff2c24ddbf Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 18 Feb 2008 19:10:44 +0000 Subject: [PATCH] MDL-12942 extra credit implemented in sum aggregation type; fixed sum aggregation; fixed division by zero in item grade min==max; merged from MOODLE_19_STABLE --- grade/edit/tree/item.php | 11 ++++++++++- grade/edit/tree/item_form.php | 16 ++++++++++++++-- grade/edit/tree/outcomeitem_form.php | 2 +- lang/en_utf8/grades.php | 2 ++ lib/grade/grade_category.php | 11 +++++++++-- lib/grade/grade_grade.php | 5 +++++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php index 6db3b6c5a9..d412179b17 100644 --- a/grade/edit/tree/item.php +++ b/grade/edit/tree/item.php @@ -89,12 +89,21 @@ $item->grademin = format_float($item->grademin, $decimalpoints); $item->gradepass = format_float($item->gradepass, $decimalpoints); $item->multfactor = format_float($item->multfactor, 4); $item->plusfactor = format_float($item->plusfactor, 4); -$item->aggregationcoef = format_float($item->aggregationcoef, 4); + +if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) { + $item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0; +} else { + $item->aggregationcoef = format_float($item->aggregationcoef, 4); +} $mform->set_data($item); if ($data = $mform->get_data(false)) { + if (!isset($data->aggregationcoef)) { + $data->aggregationcoef = 0; + } + $hidden = empty($data->hidden) ? 0: $data->hidden; $hiddenuntil = empty($data->hiddenuntil) ? 0: $data->hiddenuntil; unset($data->hidden); diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php index ae9eeedcbd..3a1e088152 100644 --- a/grade/edit/tree/item_form.php +++ b/grade/edit/tree/item_form.php @@ -129,7 +129,7 @@ class edit_item_form extends moodleform { } /// hiding - /// advcheckbox is not compatible with disabledIf !! + // advcheckbox is not compatible with disabledIf! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true)); @@ -164,6 +164,9 @@ class edit_item_form extends moodleform { } else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) { $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef'; + } else if ($cat->aggregation == GRADE_AGGREGATE_SUM) { + $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasump') ? 'aggregationcoefextrasum' : 'aggregationcoef'; + } else { $coefstring = 'aggregationcoef'; } @@ -177,7 +180,12 @@ class edit_item_form extends moodleform { } if ($coefstring !== '') { - $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades')); + if ($coefstring == 'aggregationcoefextrasum') { + // advcheckbox is not compatible with disabledIf! + $mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades')); + } else { + $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades')); + } $mform->setHelpButton('aggregationcoef', array(false, get_string($coefstring, 'grades'), false, true, false, get_string($coefstring.'help', 'grades'))); } @@ -278,7 +286,11 @@ class edit_item_form extends moodleform { $aggcoef = 'aggregationcoefweight'; } else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) { $aggcoef = 'aggregationcoefextra'; + + } else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) { + $aggcoef = 'aggregationcoefextrasum'; } + if ($aggcoef !== '') { $agg_el->setLabel(get_string($aggcoef, 'grades')); $mform->setHelpButton('aggregationcoef', array(false, get_string($aggcoef, 'grades'), diff --git a/grade/edit/tree/outcomeitem_form.php b/grade/edit/tree/outcomeitem_form.php index 899da193a8..2afb1888c9 100644 --- a/grade/edit/tree/outcomeitem_form.php +++ b/grade/edit/tree/outcomeitem_form.php @@ -185,7 +185,7 @@ class edit_outcomeitem_form extends moodleform { $parent_category->apply_forced_settings(); - if (!$parent_category->is_aggregationcoef_used()) { + if (!$parent_category->is_aggregationcoef_used() or $parent_category->aggregation == GRADE_AGGREGATE_SUM) { if ($mform->elementExists('aggregationcoef')) { $mform->removeElement('aggregationcoef'); } diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index 826878fd53..47c0f8c1a6 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -31,6 +31,8 @@ $string['aggregation'] = 'Aggregation'; $string['aggregationcoef'] = 'Aggregation coefficient'; $string['aggregationcoefextra'] = 'Extra credit'; $string['aggregationcoefextrahelp'] = 'Extra credit for this grade item during aggregation.'; +$string['aggregationcoefextrasum'] = 'Extra credit'; +$string['aggregationcoefextrasumhelp'] = 'Extra credit for this grade item during aggregation.'; $string['aggregationcoefweight'] = 'Item weight'; $string['aggregationcoefweighthelp'] = 'Weight applied to all grades in this grade item during aggregation with other grade items.'; $string['aggregationhelp'] = 'Strategy used to aggregate grades across all students in a course.'; diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 0d916a683c..dc707f613b 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -689,7 +689,13 @@ class grade_category extends grade_object { //find max grade foreach ($items as $item) { if ($item->gradetype != GRADE_TYPE_VALUE) { - continue; // sum only items with value grades, no scales and outcomes! + // sum only items with value grades, no scales and outcomes! + unset($grade_values[$item->id]); + continue; + } + if ($item->aggregationcoef > 0) { + // extra credit from this activity - does not affect total + continue; } $max += $item->grademax; } @@ -740,7 +746,8 @@ class grade_category extends grade_object { */ function is_aggregationcoef_used() { return ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN - or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN); + or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN + or $this->aggregation == GRADE_AGGREGATE_SUM); } diff --git a/lib/grade/grade_grade.php b/lib/grade/grade_grade.php index 3e08be1695..5bad00807b 100644 --- a/lib/grade/grade_grade.php +++ b/lib/grade/grade_grade.php @@ -535,6 +535,11 @@ class grade_grade extends grade_object { return null; } + if ($source_max == $source_min or $target_min == $target_max) { + // prevent division by 0 + return $target_max; + } + $factor = ($rawgrade - $source_min) / ($source_max - $source_min); $diff = $target_max - $target_min; $standardised_value = $factor * $diff + $target_min; -- 2.39.5