Make realtimequiz compatible with 2.7 and fix CONTRIB-5369

Hello Davo, These are the changes me and Tony did in the last few months, most of them 2.7 related. It includes the fix for https://tracker.moodle.org/browse/CONTRIB-5369 (performance issues) as well.