To count the time a user has spent in a course, we have the Course dedication plugin, which has an associated annual cost.
Alternatively, we can extract the time a user has spent in a course without the need for plugins by using direct queries on the Open LMS database, although it should be understood that this value is not exact because, among other things, the time the student spends, for example, watching an embedded video or reading information at an external link would not be counted.
The query would be:
SELECT T.userid, CONCAT(u.firstname, ' ', u.lastname) AS fullname, FROM_UNIXTIME(MIN(T.timecreated)) AS initial, FROM_UNIXTIME(MAX(T.timecreated)) AS end, SUBSTRING(Sec_to_time(MAX(T.sumtime)), 1, 8) AS total FROM ( SELECT l.id, l.timecreated, l.userid, DATE_FORMAT(FROM_UNIXTIME(l.timecreated), '%d-%m-%Y') AS dTime, @prevtime := (SELECT timecreated FROM mdl_logstore_standard_log l2 WHERE l.userid = l2.userid AND l.courseid = l2.courseid AND l2.id < l.id ORDER BY l2.id DESC LIMIT 1) AS prev_time, IF (l.userid != @lastuser, @delta := 0, @lastuser) AS useract, l.timecreated - @prevtime AS diff, IF (l.timecreated - @prevtime < 7200, @delta := @delta + (l.timecreated - @prevtime ), @delta) AS sumtime, IF (l.userid != @lastuser, @lastuser := l.userid, @lastuser) AS useractual FROM mdl_logstore_standard_log AS l, (SELECT @delta := 0) AS s_init, (SELECT @lastuser := 0) AS s_lastuser WHERE 0 = 0 AND l.courseid = 2 ORDER BY l.userid ASC, l.id ASC ) T JOIN mdl_user u ON T.userid = u.id GROUP BY T.userid ORDER BY MAX(T.sumtime) DESC
Make sure to replace the "2" near the end with the course ID.
In this article, we explain how to use the SQL manager to run queries in Open LMS.
Queries are offered without any kind of guarantee. The code worked when we created this articule, but due to changes in a constantly evolving software, we cannot assure its accuracy at the moment in time when is tested in your system.
Comments
0 comments
Please sign in to leave a comment.