This might do the trick if you can adjust the Moodle code..:
https://tracker.moodle.org/browse/MDL-41924?focusedCommentId=792644&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-792644
https://tracker.moodle.org/browse/MDL-41924?focusedCommentId=792644&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-792644