Stats roles 1.7
Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable. |
Statistics and reports need to be upgraded to use the new roles in 1.7 rather than user_students and user_teachers.
Penny (penny@catalyst.net.nz) is going to be working on this the week of 18 September. Here's the plan:
step 1. new database structure and migration
mdl_stats_user_* doesn't need changing structurally, although roleid needs to migrate to the id of the role to match the legacy role - first out of the returned array by:
- get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW) and
- get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)
mdl_stats_* needs changing to:
- id
- courseid
- roleid
- timeend
- stattype
- stat1
- stat2
the existing structure will migrate to:
- students/teachers/activestudents/activeteachers:
two rows: (stattype = 'enrolments')
- roleid - student (legacy), student = statreads, activestudents = statwrites
- roleid - teacher (legacy), teacher = statreads, activeteachers = statwrites
- studentreads/studentwrites/teacherreads/teacherwrites
two rows: (stattype = 'activity')
- roleid - student (legacy), studentreads = statreads, studentwrites = statwrites
- roleid - teacher (legacy), teacherreads = statreads, teacherwrites = statwrites
- logins/uniquelogins
one row: (stattype = 'logins')
- roleid - 0 (n/a) logins = statreads, uniquelogins = statwrites
step 2. new processing at cron
add in an extra loop in the stats_cron_* functions: loop through roles used in context (course in this case) get_roles_used_in_context, rather than join mdl_log on mdl_user_students and/or mdl_user_teachers, do something more like:
SELECT COUNT(l.id) FROM mdl_log l JOIN mdl_role_assignments ra ON l.userid = ra.userid JOIN mdl_context c ON ra.contextid = c.id WHERE l.course = $course AND c.instanceid = $course AND c.aggregatelevel = CONTEXT_COURSE AND ra.roleid = $roleid AND $logfilterstuff
the calls to stats_do_<timeperiod>_user_cron just need to be changed to use the roles that we got from get_roles_used_in_context rather than 1 for student and 2 for teacher.
step 3. reports
some of these will need to change as we are currently just expecting ONE row returned, where now we will have many rows (one per role) for the same stattype.
- STATS_MODE_GENERAL
- STATS_REPORT_ACTIVITY - all reads vs all writes - add up for all roles (currently studentreads+studentwrites vs teacherreads+teacherwrites)
- STATS_REPORT_STUDENTACTIVITY - \
- STATS_REPORT_TEACHERACTIVITY - / these two get dropped and replaced by STATS_REPORT_BYROLE ($roleid)
- STATS_REPORT_READS - graph all roles as lines instead of student vs teacher
- STATS_REPORT_WRITES - graph all roles as lines instead of student vs teachers
- STATS_REPORT_LOGINS - doesn't need to change, roleid is already 0
- STATS_MODE_DETAILED - these don't need to change sql, but the ui will need to change. perhaps the best way to go is: select course /select role / select user, select time period, GO!
- STATS_REPORT_USER_ACTIVITY
- STATS_REPORT_USER_ALLACTIVITY
- STATS_REPORT_USER_LOGINS
- STATS_REPORT_USER_VIEW - this one is fine, it's not dynamic (user profile stats)
- STATS_MODE_RANKED - these all need to change to add up for all roles and deal with group/aggregate rather than just getting a list of fields to return.
- STATS_REPORT_ACTIVE_COURSES
- STATS_REPORT_ACTIVE_COURSES_WEIGHTED
- STATS_REPORT_PARTICIPATORY_COURSES
- STATS_REPORT_PARTICIPATORY_COURSES_RW