]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14008 various SUM aggregation bugfixes; merged from MOODLE_19_STABLE
authorskodak <skodak>
Sat, 22 Mar 2008 21:20:33 +0000 (21:20 +0000)
committerskodak <skodak>
Sat, 22 Mar 2008 21:20:33 +0000 (21:20 +0000)
grade/edit/tree/category_form.php
grade/edit/tree/item.php
grade/edit/tree/item_form.php
grade/edit/tree/outcomeitem.php
grade/edit/tree/outcomeitem_form.php

index b65f8cbec3e37ff37553c85d06e8fe28de6bbec9..7789be6141061746f734f9a2af81e69f1d641876 100644 (file)
@@ -65,7 +65,6 @@ class edit_category_form extends moodleform {
         } else {
             $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
             $mform->setHelpButton('aggregateoutcomes', array('aggregateoutcomes', get_string('aggregateoutcomes', 'grades'), 'grade'), true);
-            $mform->disabledIf('aggregateoutcomes', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
             if ((int)$CFG->grade_aggregateoutcomes_flag & 2) {
                 $mform->setAdvanced('aggregateoutcomes');
             }
@@ -235,6 +234,7 @@ class edit_category_form extends moodleform {
                         $mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
                     }
                 }
+                
             }
 
             if ($grade_item->is_calculated()) {
index d412179b170b4b1b50a5bb389393d975e4dff899..ce1bbc7aa66d04d69dbc624300f04c218a71f191 100644 (file)
@@ -58,6 +58,7 @@ if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
     $item = $grade_item->get_record_data();
 
     if ($grade_item->is_course_item()) {
+        $parent_category = null;
         $item->parentcategory = 0;
     } else if ($grade_item->is_category_item()) {
         $parent_category = $grade_item->get_parent_category();
@@ -90,7 +91,9 @@ $item->gradepass       = format_float($item->gradepass, $decimalpoints);
 $item->multfactor      = format_float($item->multfactor, 4);
 $item->plusfactor      = format_float($item->plusfactor, 4);
 
-if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
+if (empty($parent_category)) {
+    $item->aggregationcoef = 0;
+} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
     $item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
 } else {
     $item->aggregationcoef = format_float($item->aggregationcoef, 4);
index f43a707ef5bfd204fc96fddec52d5655613bccc5..1a65097de4b2c80f54e954871b57e4dbc151fa9c 100644 (file)
@@ -153,7 +153,7 @@ class edit_item_form extends moodleform {
                     $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
 
                 } else if ($cat->aggregation == GRADE_AGGREGATE_SUM) {
-                    $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';
+                    $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasump') ? 'aggregationcoefextrasum' : 'aggregationcoef';
 
                 } else {
                     $coefstring = 'aggregationcoef';
@@ -271,6 +271,7 @@ class edit_item_form extends moodleform {
                     $aggcoef = '';
                     if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                         $aggcoef = 'aggregationcoefweight';
+
                     } else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                         $aggcoef = 'aggregationcoefextra';
 
@@ -280,7 +281,7 @@ class edit_item_form extends moodleform {
 
                     if ($aggcoef !== '') {
                         $agg_el->setLabel(get_string($aggcoef, 'grades'));
-                        $mform->setHelpButton('aggregationcoef', array($aggcoef, get_string($aggcoef, 'grades'), 'grade'), true);
+                        $mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
                     }
                 }
             }
index 25a418977f72217c62e146b9394fd6980de599ab..1d7d5ef14a82d2da03491ec5a1d62a7a638f690a 100644 (file)
@@ -58,16 +58,8 @@ if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
     }
     $item = $grade_item->get_record_data();
 
-    if ($grade_item->is_course_item()) {
-        $item->parentcategory = 0;
-    } else if ($grade_item->is_category_item()) {
-        $parent_category = $grade_item->get_parent_category();
-        $parent_category = $parent_category->get_parent_category();
-        $item->parentcategory = $parent_category->id;
-    } else {
-        $parent_category = $grade_item->get_parent_category();
-        $item->parentcategory = $parent_category->id;
-    }
+    $parent_category = $grade_item->get_parent_category();
+    $item->parentcategory = $parent_category->id;
 
     if ($item->itemtype == 'mod') {
         $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
@@ -96,12 +88,24 @@ if ($item->hidden > 1) {
 $item->locked = !empty($item->locked);
 
 $item->gradepass       = format_float($item->gradepass, $decimalpoints);
-$item->aggregationcoef = format_float($item->aggregationcoef, 4);
+
+if (empty($parent_category)) {
+    $item->aggregationcoef = 0;
+} else 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;
+    }
+
     if (array_key_exists('calculation', $data)) {
         $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
     }
index 606ec1026424f172f1f00f47fec071e97f60f51a..8c99a5a6516e58152f39fc4121f5747e54095276 100644 (file)
@@ -103,6 +103,9 @@ class edit_outcomeitem_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';
                 }
@@ -117,8 +120,13 @@ class edit_outcomeitem_form extends moodleform {
         }
 
         if ($coefstring !== '') {
-            $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
-            $mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'));
+            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('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
         }
 
 /// hidden params
@@ -190,9 +198,14 @@ class edit_outcomeitem_form extends moodleform {
                     $aggcoef = '';
                     if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                         $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('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'));