From 6f4f7f51d3ac634deebb3b15c697ec8f6ce64445 Mon Sep 17 00:00:00 2001 From: Kordan Date: Sun, 18 Feb 2024 20:13:47 +0100 Subject: [PATCH] Added DISTINCT to submission id too. Please merge this PR to MOODLE_m401|m402|m403_STABLE too. Thanks. --- classes/submissions_list.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/submissions_list.php b/classes/submissions_list.php index d698a6c34dc..121fa605561 100644 --- a/classes/submissions_list.php +++ b/classes/submissions_list.php @@ -400,7 +400,8 @@ public function get_counter($table) { $whereparams = []; - $sql = 'SELECT s.status, COUNT(s.id) submissions, COUNT(DISTINCT(u.id)) users'; + $sqlselectstart = 's.status, COUNT(DISTINCT(s.id)) submissions, '; + $sql = 'SELECT '.$sqlselectstart.'COUNT(DISTINCT(u.id)) users'; $sql .= ' FROM {surveypro_submission} s JOIN {user} u ON u.id = s.userid'; @@ -462,7 +463,8 @@ public function get_counter($table) { $whereparams = $whereparams + $wherefilterparams; } - $sql .= ' GROUP BY s.status'; + $sqlgroupby = ' GROUP BY s.status'; + $sql .= $sqlgroupby; if (!$canviewhiddenactivities) { $whereparams = array_merge($whereparams, $eparams); @@ -487,8 +489,7 @@ public function get_counter($table) { $counter['closedusers'] = 0; } - $sql = str_replace('s.status, COUNT(s.id) submissions, ', '', $sql); - $sql = str_replace(' GROUP BY s.status', '', $sql); + $sql = str_replace([$sqlselectstart, $sqlgroupby], '', $sql); $counters = $DB->get_record_sql($sql, $whereparams); $counter['allusers'] = (int) $counters->users;