From 6200f70c5ecc4d5b88f94c674507ef5acac9788c Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 26 Jul 2012 18:47:57 +0100 Subject: [PATCH] MDL-34589 quiz report graphs: PHP5.4 issue with unset($array[$float]). Thanks to Matthew Davidson for diagnosing the problem. --- mod/quiz/report/overview/overviewgraph.php | 4 +++- mod/quiz/report/reportlib.php | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mod/quiz/report/overview/overviewgraph.php b/mod/quiz/report/overview/overviewgraph.php index c450615d001..6583ef95708 100644 --- a/mod/quiz/report/overview/overviewgraph.php +++ b/mod/quiz/report/overview/overviewgraph.php @@ -89,7 +89,9 @@ while ($bands > 20 || $bands <= 10) { } } -$bands = ceil($bands); +// See MDL-34589. Using doubles as array keys causes problems in PHP 5.4, +// hence the explicit cast to int. +$bands = (int) ceil($bands); $bandwidth = $quiz->grade / $bands; $bandlabels = array(); for ($i = 1; $i <= $bands; $i++) { diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index d3e4e998d14..344513e5afe 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -191,6 +191,11 @@ function quiz_report_qm_filter_select($quiz, $quizattemptsalias = 'quiza') { */ function quiz_report_grade_bands($bandwidth, $bands, $quizid, $userids = array()) { global $DB; + if (!is_int($bands)) { + debugging('$bands passed to quiz_report_grade_bands must be an integer. (' . + gettype($bands) . ' passed.)', DEBUG_DEVELOPER); + $bands = (int) $bands; + } if ($userids) { list($usql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'u'); @@ -220,7 +225,7 @@ ORDER BY $data = $DB->get_records_sql_menu($sql, $params); // We need to create array elements with values 0 at indexes where there is no element. - $data = $data + array_fill(0, $bands+1, 0); + $data = $data + array_fill(0, $bands + 1, 0); ksort($data); // Place the maximum (prefect grade) into the last band i.e. make last