diff --git a/report/stats/locallib.php b/report/stats/locallib.php index 0a0b6f1e41402..1a671c2072375 100644 --- a/report/stats/locallib.php +++ b/report/stats/locallib.php @@ -111,7 +111,8 @@ function report_stats_report($course, $report, $mode, $user, $roleid, $time) { list($sort, $moreparams) = users_order_by_sql('u'); $moreparams['courseid'] = $course->id; - $sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, u.idnumber + $fields = user_picture::fields('u', array('idnumber')); + $sql = "SELECT DISTINCT $fields FROM {stats_user_{$param->table}} s JOIN {user} u ON u.id = s.userid WHERE courseid = :courseid"; @@ -128,9 +129,8 @@ function report_stats_report($course, $report, $mode, $user, $roleid, $time) { if (!$us = $DB->get_records_sql($sql, array_merge($param->params, $moreparams))) { print_error('nousers'); } - foreach ($us as $u) { - $users[$u->userid] = fullname($u, true); + $users[$u->id] = fullname($u, true); } $table->align = array('left','left','left','left','left','left','left','left');