diff --git a/course/report/participation/index.php b/course/report/participation/index.php index f2600d69358..c0d9fe80493 100644 --- a/course/report/participation/index.php +++ b/course/report/participation/index.php @@ -189,35 +189,32 @@ } list($actionsql, $params) = $DB->get_in_or_equal($actions, SQL_PARAMS_NAMED, 'action0'); - $actionsql = "l.action $actionsql"; + $actionsql = "action $actionsql"; $relatedcontexts = get_related_contexts_string($context); - $sql = "SELECT ra.userid, u.firstname, u.lastname, u.idnumber, COUNT(l.action) AS count - FROM {role_assignments} ra - JOIN {user} u ON u.id = ra.userid - LEFT JOIN {log} l ON (l.userid = ra.userid AND l.cmid = :instanceid AND l.time > :timefrom AND $actionsql) - WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid"; + $sql = "SELECT ra.userid, u.firstname, u.lastname, u.idnumber, l.actioncount AS count + FROM (SELECT * FROM {role_assignments} WHERE contextid $relatedcontexts AND roleid = :roleid ) ra + JOIN {user} u ON u.id = ra.userid + LEFT JOIN ( + SELECT userid, COUNT(action) actioncount FROM {log} WHERE cmid = :instanceid AND time > :timefrom AND $actionsql GROUP BY userid + ) l ON (l.userid = ra.userid)"; $params['roleid'] = $roleid; $params['instanceid'] = $instanceid; $params['timefrom'] = $timefrom; list($twhere, $tparams) = $table->get_sql_where(); if ($twhere) { - $sql .= ' AND '.$twhere; //initial bar + $sql .= ' WHERE '.$twhere; //initial bar $params = array_merge($params, $tparams); } - $sql .= " GROUP BY ra.userid, u.firstname, u.lastname, u.idnumber"; - if ($table->get_sql_sort()) { $sql .= ' ORDER BY '.$table->get_sql_sort(); } $countsql = "SELECT COUNT(DISTINCT(ra.userid)) FROM {role_assignments} ra - JOIN {user} u ON u.id = ra.userid - LEFT OUTER JOIN {log} l ON (l.userid = ra.userid AND l.cmid = :instanceid AND l.time > :timefrom AND $actionsql) WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid"; $totalcount = $DB->count_records_sql($countsql, $params);