Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Improving the Groups design in Moodle 1.9

Summary of problems:

  • Can not define groupings at site level
  • Groupings not implemented in modules
  • Concept of orphaned groups
  • Missing enrolment option
  • Not integrated into Moodle core
  • Unfinished and partially broken code

It would be very hard to improve current code without major refactoring and design changes. --Petr Škoda (škoďák) 02:37, 10 April 2007 (CDT)

Competing proposals

Change groups/groupings relationship

At present both groups and groupings may belong to course, you could use one group in several courses and groupings at the same time. This loose relationship of groups and groupings adds too much complexity and is a source of bugs in code. The loops in the db diagram clearly indicate potential problems.

Solution: Each group should be attached to exactly one grouping. The groups would not be shared in groupings anymore, instead the global groupings could be shared by courses. See attached db schema.

groupsdb.png

Benefits:

  • fewer tables
  • normalized
  • simpler SQL
  • faster
  • much easier backup/restore implementation

Global groupings x Course groupings

Separate global and course groupings, add global tag to grouping table. Each global grouping has world wide unique identifier. Benefits:

  • allows implementation of access control – local course groupings editable by course teachers, special capability in CONTEXT_SYSTEM for managing of global groupings
  • easier backup/restore implementation – local groupings (+groups) always backed up, global groupings handled differently
  • no need for orphan groups anymore - groups not attached to course directly (without any grouping)

This separation would make the coding much easier because the two parts would be independent - local grouping would not be breaking the course separation rule (anything outside of course breaks normal backup/restore), the global groupings could have special GUI with permissions/export/import/backup/restore.

Local groupings would be attached to exactly one course, global grouping could be used in many courses at the same time.

Enrolment synchronization

Global groupings can partially replace metacourses in some scenarios. They should support synchronization of enrolments based on group membership. Global groupings should allow:

  • automatic or manual sync of enrolments – reuse code from metacourses
  • setting of default sync role id with possible exception for teachers, tutors, etc.
  • import/export of grouping definitions
  • mapping of global groupings during course restore (course groupings always backed/restored)

Other code cleanup

Current group code does not follow Moodle coding guide, has several unfinished/broken/obsoleted parts, is not integrated into core, etc. To do:

  • integrate setup and upgrade into main lib/db/*.*
  • remove columns from groupings table that can be replaced by permissions
  • reduce the number of functions, rewrite or fix them, move them into lib/grouplib.php
  • split GUI in /group/ – global groupings definition form and course grouping setup
  • implement module and course groupings support, fix all mods to use it (course edit form, mod edit form, etc.)
  • fix legacy functions
  • documentation

Needed time

1 month for implementation and testing.