Skip to content

Commit

Permalink
Added DISTINCT to submission id too.
Browse files Browse the repository at this point in the history
Please merge this PR to MOODLE_m401|m402|m403_STABLE too.
Thanks.
  • Loading branch information
kordan authored and stronk7 committed Feb 27, 2024
1 parent 134a70d commit 6f4f7f5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions classes/submissions_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 6f4f7f5

Please sign in to comment.