The current code goes through all the learning objects to look for the one with the largest allowed group size. This seems very inefficient as it creates a lot of extra queries for every page load. It would probably be a good idea to replace this by simply adding a "Students can form groups" boolean directly to the course instance model. This could be on by default, and if the teacher wants to hide the group forming functionality from students for the course instance, he/she could just uncheck a box in Edit course -> Course.
The current code goes through all the learning objects to look for the one with the largest allowed group size. This seems very inefficient as it creates a lot of extra queries for every page load. It would probably be a good idea to replace this by simply adding a "Students can form groups" boolean directly to the course instance model. This could be on by default, and if the teacher wants to hide the group forming functionality from students for the course instance, he/she could just uncheck a box in Edit course -> Course.