]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12942 extra credit implemented in sum aggregation type; fixed sum aggregation...
authorskodak <skodak>
Mon, 18 Feb 2008 19:10:44 +0000 (19:10 +0000)
committerskodak <skodak>
Mon, 18 Feb 2008 19:10:44 +0000 (19:10 +0000)
grade/edit/tree/item.php
grade/edit/tree/item_form.php
grade/edit/tree/outcomeitem_form.php
lang/en_utf8/grades.php
lib/grade/grade_category.php
lib/grade/grade_grade.php

index 6db3b6c5a99a4e5a909622d79053780cf2587fce..d412179b170b4b1b50a5bb389393d975e4dff899 100644 (file)
@@ -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);
index ae9eeedcbd072b5b1da90087a752d37db2f74151..3a1e08815225d23479e2c511ca31aafc6eb6c20a 100644 (file)
@@ -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'),
index 899da193a82d30aefcdf6af4e42678914fd32e7d..2afb1888c995044910b801d2bc52e5dd3f5653d4 100644 (file)
@@ -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');
                     }
index 826878fd5359a2a159be50323c34bab83ddfeb22..47c0f8c1a61a4dbc28512e2fcd9de65487160c53 100644 (file)
@@ -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.';
index 0d916a683c932c33836e9c0ce97dd8dfcd94c41a..dc707f613b93ead1808f4c26341491cdb081ae3c 100644 (file)
@@ -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);
 
     }
 
index 3e08be1695fd91fe22273acea7a69acaf2a04d12..5bad00807bf74285d5281ef39f73a403fe96a285 100644 (file)
@@ -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;