Index: course/report/participation/index.php =================================================================== --- course/report/participation/index.php (revision 517) +++ course/report/participation/index.php (working copy) @@ -170,26 +170,25 @@ switch ($action) { case 'view': - $actionsql = 'l.action IN (\''.implode('\',\'', $viewnames).'\' )'; + $actionsql = 'action IN (\''.implode('\',\'', $viewnames).'\' )'; break; case 'post': - $actionsql = 'l.action IN (\''.implode('\',\'', $postnames).'\' )'; + $actionsql = 'action IN (\''.implode('\',\'', $postnames).'\' )'; break; default: // some modules have stuff we want to hide, ie mail blocked etc so do actually need to limit here. - $actionsql = 'l.action IN (\''.implode('\',\'', array_merge($viewnames, $postnames)).'\' )'; + $actionsql = 'action IN (\''.implode('\',\'', array_merge($viewnames, $postnames)).'\' )'; } $relatedcontexts = get_related_contexts_string($context); $sql = "SELECT ra.userid, u.firstname, u.lastname, u.idnumber, COUNT(l.action) AS count - FROM {$CFG->prefix}role_assignments ra + FROM (SELECT * FROM {$CFG->prefix}role_assignments WHERE contextid $relatedcontexts AND roleid = $roleid) ra JOIN {$CFG->prefix}user u ON u.id = ra.userid - LEFT OUTER JOIN {$CFG->prefix}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"; + LEFT OUTER JOIN (SELECT * FROM {$CFG->prefix}log WHERE cmid = $instanceid AND time > $timefrom AND $actionsql) l ON l.userid = ra.userid"; if ($table->get_sql_where()) { - $sql .= ' AND '.$table->get_sql_where(); //initial bar + $sql .= ' WHERE '.$table->get_sql_where(); //initial bar } $sql .= " GROUP BY ra.userid, u.firstname, u.lastname, u.idnumber"; @@ -199,15 +198,13 @@ } $countsql = "SELECT COUNT(DISTINCT(ra.userid)) - FROM {$CFG->prefix}role_assignments ra - JOIN {$CFG->prefix}user u ON u.id = ra.userid - LEFT OUTER JOIN {$CFG->prefix}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"; + FROM (SELECT * FROM {$CFG->prefix}role_assignments WHERE contextid $relatedcontexts AND roleid = $roleid) ra + JOIN {$CFG->prefix}user u ON u.id = ra.userid"; $totalcount = count_records_sql($countsql); if ($table->get_sql_where()) { - $matchcount = count_records_sql($countsql.' AND '.$table->get_sql_where()); + $matchcount = count_records_sql($countsql.' WHERE '.$table->get_sql_where()); } else { $matchcount = $totalcount; }