I need some ideas on a complex reporting problem. A client has this scenario:
- a user is given the url of a course (https://site.com/course/view.php?id=123) or the url of a module within that course (https://site.com/mod/page/view.php?id=456).
- They open the link and are not logged on. They log on. The course or page opens.
- They do stuff in the course, navigating, etc.
- They close, or log off, or visit other courses.
- In following days, weeks, they open the links again, follow the same process.
A report is needed that shows:
- the 'first' time the user logged on and opened either the course homepage OR that (known) url. The client sees 'logging on' to be the same as 'opening the course', rather than 'the logon event', which could simplify things.
- the 'most recent' time the user open the course (being either the home page, or the known url) after a logon event. So clicking around in the course, revisiting the home page multiple times wouldn't change the 'most recent' time. The user could have logged on, opened a different course, then opened THIS reporting course. It's the time of opening THIS course that is the date needed.
- a count being the number of times that the user opened this course.
What I'm doing to find the 'first time' open is to look at the standard logstore and find events like \core\event\course_viewed for the home page and taking the earliest of these. For the 'known url' I can use various columns to find the record in the logstore.
SELECT * FROM mdl_logstore_standard_log WHERE
(eventname = '\core\event\course_viewed' AND courseid=153 AND userid=11909)
OR (target = 'course_module' and contextinstanceid = 907 and userid=11909 and courseid=153)
ORDER BY timecreated
LIMIT 1
(eventname = '\core\event\course_viewed' AND courseid=153 AND userid=11909)
OR (target = 'course_module' and contextinstanceid = 907 and userid=11909 and courseid=153)
ORDER BY timecreated
LIMIT 1
For the 'latest time' its trickier. Do I
- look up all logon events and the for each one (starting at the newest and working backwards) see if there's a newer event recorded about 'opening' or 'viewing' the course?
- ball-park it using the user_lastaccess table, which will be the last time something happened with that user/course - pretty vague.
- use the user_lastaccess AND standard log table to guess when the course most recently opened?
- use some other value I haven't thought of for 'when the course or any of its content was opened'
For the number of times the course was opened, ... anyone got any ideas if this is even possible?