I created a report that gets the times of the first access logged for a user in a course and the last grade recorded in that course, and uses the difference to estimate the time spent in the course. However, someone noted that one user isn't showing up in the report, and the more I investigate why, the more confused I get.
The user in question has ID 98, and the course has ID 79. If I go to a gradebook page, like
on my site, the user definitely has a grade recorded for the course (a single activity course based on a SCORM object, in case that matters).
However, I can't find any evidence of this anywhere in the database. There are no entries in the grade_grades table for that user and course (though there are entries for the user in other courses, and for the course with other users), nor can I even find anything in the logs table for that user in that course, even though I should have records going back for years.
The one thing I can think of is that this user has a custom system role assigned, which is derived from the Manager role, and something in the back of my brain is telling me there's some setting somewhere that causes such users' activities to not be logged? Or maybe I'm completely mis-remembering that. If there is such a setting, I can't find it, and anyway it doesn't explain why he has logs for other courses (unless maybe they're from before he was assigned the role?)
Anyway, I'm grasping at straws here. It seems that if user X has a grade in course Y's gradebook, then it there *should* be an entry for that user/course combo in the grade_grades table... right? Before I start digging into the source code, I figured I'd ask here in case I'm just missing something obvious.
Thanks to anyone who can help!
Here are examples of some of the queries I've tried. Both of these return no results as-written, but if you remove the user or course restrictions, then they do.
select itemname, g.rawgrade from mdl_grade_items i join mdl_grade_grades g on i.id = g.itemid and g.userid=98 and courseid=79;
select u.username, c.fullname, action, min(time) first from mdl_log l join mdl_user u on l.userid = u.id and u.id = 98 and course=79 join mdl_course c on l.course = c.id group by username,fullname,action