Working with Cohorts

I am sure we will all agree, Cohorts are pretty handy. Recently a new client of mine asked me to do a bulk upload of about 100 users. Once uploaded, the client asked me to add them to a Cohort. No problem. There was only about 110 users on the site, so picking the 100 I needed was easy.

A few days later, I got a similar request. Upload a bunch of users, and then add them to a new Cohort. Suddenly it wasn’t as much fun. Finding and adding them proved to be a little trickier than the first time.

So I decided to tinker about with some code and see what I could come up with.


Cohorts in Moodle 2.7


The users in my course that are members of the Peanuts Cohort

My Cohort Management plugin

My Cohort Management plugin.

The screen above shows the following:

  1. The top left block shows a list of all the Cohorts on the site, as well as the number of Users in each Cohort.
  2. Below that is a list of Cohorts that have been added to course categories.
  3. On the bottom right we have all the Cohorts and the courses they have been added to.

Lastly, the screen also has a drop-down list of all the Cohorts. Selecting a Cohort from the list, loads a second screen. On this screen Users can be added or removed.

Add or remove users from the selected Cohort

Add or remove users from the selected Cohort

I wanted to do a few things on the second Cohort Management screen. The most important function was to filter out the Users that had to be added to the Cohort. Ironically, that’s the one part I have not yet completed.

Below are two animations showing how the adding and removing of Users is done.


Adding Users to a Cohort


Removing users from a Cohort

The image below shows the relationship between the different tables

Cohort tables

Cohort tables


Leave a Reply

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