]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17825 Converting float grades to string when counting values using the Mode of...
authornicolasconnault <nicolasconnault>
Thu, 8 Jan 2009 16:02:11 +0000 (16:02 +0000)
committernicolasconnault <nicolasconnault>
Thu, 8 Jan 2009 16:02:11 +0000 (16:02 +0000)
lib/grade/grade_category.php

index 2c17322723e23c545523016b381a8f1cca409f96..deb0f356f81ca7320e4bf60452f5810ff89ea260 100644 (file)
@@ -607,7 +607,18 @@ class grade_category extends grade_object {
                 break;
 
             case GRADE_AGGREGATE_MODE:       // the most common value, average used if multimode
-                $freq = array_count_values($grade_values);
+                // array_count_values only counts INT and STRING, so if grades are floats we must convert them to string
+                $converted_grade_values = array();
+
+                foreach ($grade_values as $k => $gv) {
+                    if (!is_int($gv) && !is_string($gv)) {
+                        $converted_grade_values[$k] = (string) $gv;
+                    } else {
+                        $converted_grade_values[$k] = $gv;
+                    }
+                }
+
+                $freq = array_count_values($converted_grade_values);
                 arsort($freq);                      // sort by frequency keeping keys
                 $top = reset($freq);               // highest frequency count
                 $modes = array_keys($freq, $top);  // search for all modes (have the same highest count)