From: nicolasconnault Date: Thu, 8 Jan 2009 16:02:11 +0000 (+0000) Subject: MDL-17825 Converting float grades to string when counting values using the Mode of... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0198929cdbdb56b561b35ae6d9adc5c9c8168b71;p=moodle.git MDL-17825 Converting float grades to string when counting values using the Mode of Grades aggregation. Merging from MOODLE_19_STABLE --- diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 2c17322723..deb0f356f8 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -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)