saylordotorg / moodle-local_discoursesso

A Moodle plugin that enables Moodle to act as a SSO provider for the Discourse discussion platform.
1 stars 1 forks source link

Sync cohorts as discourse groups? #10

Closed jazinheira closed 5 years ago

jazinheira commented 5 years ago

Would it be useful to be able to select Moodle cohorts to sync and add those cohorts/users to groups in Discourse?

theopen-institute commented 5 years ago

This would be extremely useful to me!

theopen-institute commented 5 years ago

I got it working with the following addition to sso.php, right after the $extraparams block:

// Send cohort membership as groups
$cohort_query = "SELECT idnumber FROM {cohort} INNER JOIN {cohort_members} ON {cohort}.id={cohort_members}.cohortid WHERE {cohort_members}.userid = ?";
$groups_list = $DB->get_fieldset_sql($cohort_query, [$USER->id]);
$extraparams['groups'] = implode(",",$groups_list);

Happy to make a pull request, but I'm new to both moodle and php so the code might be flawed/sloppy.

jazinheira commented 5 years ago

@theopen-institute I just released a new version with this feature! We've been running it for a couple months so it should be good, but let me know if you run into anything.

I added a way to select which cohorts to sync - since we're using an automatic cohort plugin, we've got thousands of cohorts!