From 9a16044c219a4a80d64fbaab48756aaaeae07531 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 16 May 2016 23:14:22 +0100 Subject: [PATCH] MDL-54605 quiz regrading: incorrect DB query There were two issues. With groups, the $params array was wrong due to PHP + vs array_merge sillyness. Also, the first column in the SQL was not necessarily unique, so we need to use a recordset rather than get_records. --- mod/quiz/report/overview/report.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 5cb1145d55c..e2d1df2865a 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -445,23 +445,25 @@ class quiz_overview_report extends quiz_attempts_report { if ($groupstudents) { list($usql, $uparams) = $DB->get_in_or_equal($groupstudents); $where .= " AND quiza.userid $usql"; - $params += $uparams; + $params = array_merge($params, $uparams); } - $toregrade = $DB->get_records_sql(" + $toregrade = $DB->get_recordset_sql(" SELECT quiza.uniqueid, qqr.slot FROM {quiz_attempts} quiza JOIN {quiz_overview_regrades} qqr ON qqr.questionusageid = quiza.uniqueid WHERE $where", $params); - if (!$toregrade) { - return; - } - $attemptquestions = array(); foreach ($toregrade as $row) { $attemptquestions[$row->uniqueid][] = $row->slot; } + $toregrade->close(); + + if (!$attemptquestions) { + return; + } + $attempts = $DB->get_records_list('quiz_attempts', 'uniqueid', array_keys($attemptquestions));