Problem: some Moodle users, such as large organisations with many departments, would like to have one Moodle but set it up so that each user only sees the courses from their own department, and with a theme that matches their department.
A simple solution:
Use cohorts to represent the departments, and allow each cohort to be mapped to one course category and one theme.
Then, once a user has logged in, we know which cohorts they are in, and this which categories they are allowed in, and then we restrict the entire course tree to just show those categories (and anything inside them). If there is just one category then we could further refine this by leaving out the name of the category and putting the contents of it at the top level.
There don't have to be any further changes in enrolments, and if the user is also enrolled in any courses outside this category then these courses will simply appear in the list of My courses at the top level.
Additionally, if they are in just ONE cohort (or all their cohorts have the same theme) we also set the theme to match (this cohort theme setting overrides all other theme settings).
Cohort themes landed in Moodle 3.5 (
(Thanks to Andrea Bicciolo at Mediatouch for the idea - he estimated it would be suitable for 80% of his clients who want "multi-tenancy" in Moodle)