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

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