Moodle 2 export participants with group information

A small script to export moodle 2 participants with their group information.

Drag the bookmarklet to your bookmarkbar: Moodle Group Export
You can then click it when you are on the moodle 2 > Users > Enrolled users page to get a csv file of the displayed table.

Limitation

  • Support for a maximum of 1 group by participant
  • Pop-up has to be enabled

Source Code

var script = document.createElement('script');
document.head.appendChild(script);
script.onload = function(){
var separator = ',';
var pattern = /id=(.*)&/;
var csv = [['userid', 'name','idnumber','email','group'].join(separator)];
$('table.userenrolment').find('tr').each(function(index, tr){
    var r = [];
    var $tr = $(tr);
    var a = $tr.find('a');
    var userid = pattern.exec(a[0])[1];
    r.push(userid);
    r.push($tr.find('.subfield_firstname').text());
    r.push($tr.find('.subfield_firstname').text());
    r.push($tr.find('.subfield_idnumber').text());
    r.push($tr.find('.subfield_email').text());
    r.push($tr.find('.group').text());
    csv.push(r.join(separator));
});
csv = csv.join("\r\n");
window.open("data:application/octet-stream;charset=utf-8," + encodeURIComponent(csv));
};
script.src = 'http://code.jquery.com/jquery-2.1.4.min.js';

1 thought on “Moodle 2 export participants with group information”

Leave a Comment

Your email address will not be published. Required fields are marked *