# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/course/report/participation/index.php
--- moodle/course/report/participation/index.php Base (1.56)
+++ moodle/course/report/participation/index.php Locally Modified (Based On 1.56)
@@ -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);
