]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12942 new extra credit option for simple mean agg; merged from MOODLE_19_STABLE
authorskodak <skodak>
Fri, 24 Apr 2009 16:24:49 +0000 (16:24 +0000)
committerskodak <skodak>
Fri, 24 Apr 2009 16:24:49 +0000 (16:24 +0000)
grade/edit/tree/category.php
grade/edit/tree/item.php
grade/edit/tree/lib.php
grade/edit/tree/outcomeitem_form.php
lib/grade/grade_category.php

index 1cb26efb59b8405105320bf970d7d5f36e8f2b06..a9f9a79e80aa0b0969a657207d672853e009d424 100644 (file)
@@ -58,7 +58,13 @@ if ($id) {
     // set parent
     $category->parentcategory = $grade_category->parent;
     $grade_item = $grade_category->load_grade_item();
-    foreach ($grade_item as $key => $value) {
+    // nomalize coef values if needed
+    if ($parent_category = $grade_category->get_parent_category()) {
+        if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
+            $grade_item->aggregationcoef = $grade_item->aggregationcoef == 0 ? 0 : 1;
+        }
+    }
+    foreach ($grade_item->get_record_data() as $key => $value) {
         $category->{"grade_item_$key"} = $value;
     }
 
index 6db142229b0a057e6b27783c59a3d11d3d489139..33d5ff7d11609d4f43132fc3830f43b76f0c0edd 100644 (file)
@@ -96,8 +96,8 @@ $item->plusfactor      = format_float($item->plusfactor, 4);
 
 if (empty($parent_category)) {
     $item->aggregationcoef = 0;
-} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
-    $item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
+} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
+    $item->aggregationcoef = $item->aggregationcoef == 0 ? 0 : 1;
 } else {
     $item->aggregationcoef = format_float($item->aggregationcoef, 4);
 }
index e64a2e3f2a5e46cea16d25db3ca26520ec8b254c..f49b831d9518526d75b121f5cb22c0f052a13463 100755 (executable)
@@ -575,7 +575,7 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
         }
 
         $script = "window.location='index.php?id={$params['id']}&amp;category={$category->id}&amp;aggregationtype='+this.value+'&amp;sesskey=" . sesskey()."';";
-        $aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true);
+        $aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, null, $script, 0, true);
 
         if ($this->forced) {
             $aggregation = $options[$category->aggregation];
index 3fbb0dbb8a133cf7663ff4d6eb2c93a698760d87..0cbea5b05e4002aed9159cd30964309087127e5f 100644 (file)
@@ -102,6 +102,9 @@ class edit_outcomeitem_form extends moodleform {
                 if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                     $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
 
+                } else if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
+                    $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';
+
                 } else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                     $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
 
@@ -201,6 +204,9 @@ class edit_outcomeitem_form extends moodleform {
                     if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                         $aggcoef = 'aggregationcoefweight';
 
+                    } else if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
+                        $aggcoef = 'aggregationcoefextrasum';
+
                     } else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                         $aggcoef = 'aggregationcoefextra';
 
index 4c7bc71fc087d7ae83934b3ed8598f03148fe10d..db7816258c71b833cd48e5c262ce02ea836a299d 100644 (file)
@@ -648,19 +648,23 @@ class grade_category extends grade_object {
                 }
                 break;
 
-            case GRADE_AGGREGATE_WEIGHTED_MEAN2: // Weighted average of all existing final grades, weight is the range of grade (ususally grademax)
+            case GRADE_AGGREGATE_WEIGHTED_MEAN2:
+                // Weighted average of all existing final grades with optional extra credit flag,
+                // weight is the range of grade (ususally grademax)
                 $weightsum = 0;
-                $sum       = 0;
+                $sum       = null;
                 foreach($grade_values as $itemid=>$grade_value) {
                     $weight = $items[$itemid]->grademax - $items[$itemid]->grademin;
                     if ($weight <= 0) {
                         continue;
                     }
-                    $weightsum += $weight;
-                    $sum       += $weight * $grade_value;
+                    if ($items[$itemid]->aggregationcoef == 0) {
+                        $weightsum += $weight;
+                    }
+                    $sum += $weight * $grade_value;
                 }
                 if ($weightsum == 0) {
-                    $agg_grade = null;
+                    $agg_grade = $sum; // only extra credits
                 } else {
                     $agg_grade = $sum / $weightsum;
                 }
@@ -668,7 +672,7 @@ class grade_category extends grade_object {
 
             case GRADE_AGGREGATE_EXTRACREDIT_MEAN: // special average
                 $num = 0;
-                $sum = 0;
+                $sum = null;
                 foreach($grade_values as $itemid=>$grade_value) {
                     if ($items[$itemid]->aggregationcoef == 0) {
                         $num += 1;
@@ -812,6 +816,7 @@ class grade_category extends grade_object {
      */
     public function is_aggregationcoef_used() {
         return ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN
+             or $this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2
              or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN
              or $this->aggregation == GRADE_AGGREGATE_SUM);
 
@@ -853,6 +858,8 @@ class grade_category extends grade_object {
         // No parent category is overriding this category's aggregation, return its string
         if ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
             $this->coefstring = 'aggregationcoefweight';
+        } else if ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
+            $this->coefstring = 'aggregationcoefextrasum';
         } else if ($this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
             $this->coefstring = 'aggregationcoefextra';
         } else if ($this->aggregation == GRADE_AGGREGATE_SUM) {