I have been recommending this for over a year, and at last, I eventually seem to have managed to get a modified version of John Ryan's hack going on a 1.6.2 moodle.
As N Hansen said, John Ryan's hack seemed to display the group specifications to students, and had other issues, so what follows is considerably changed.
However alas I released too late, the hack only effects the course page, so I would have to hack the activity pages (which give a list of the activities), and the recent activity block to prevent students from seeing the activities.
For the course page alone, here is the hack to make groups really seperate.
There are three changes all to course/lib.php
1) in function print_section
on about line 820
after
$mod = $mods[$modnumber];
add
//// John Ryan and Timothy Takemoto's hack for really seperate groups
$ret_array = array($mod->visible,urldecode($modinfo[$modnumber]->name));
if ($isteacher) { //is teacher so just get full of module name
$instancename = urldecode($modinfo[$modnumber]->name);
} elseif ($mod->visible) {
$ret_array = hideitem($course, $mod, urldecode($modinfo[$modnumber]->name));
$mod->visible = $ret_array[0];
$instancename = $ret_array[1];
}
$instancename = format_string($instancename, true, $course->id); //what?
// End of John Ryan and Timothy Takemoto's hack
2) In function print_section, comment out the lines begging with "instancename" on about line 840
// These two lines removed since students should not see them.
// $instancename = urldecode($modinfo[$modnumber]->name);
// $instancename = format_string($instancename, true, $course->id);
3) After print_section add the following function
// Function hideitem added by JLR and Timothy Takemoto Novemeber 9th 2006
// Only called if the instance (activity/resource) is visible and is a student
// Returns an array contaning new value of whether the instance is visible and
// Concatenates any mention of groups from the instance name.
function hideitem($course, $mod, $modname) {
$thisgroupids = mygroupid($course->id); //When John Ryan wrotes this there was only one group per user.
$thisgroupid = $thisgroupids[0]; //Students will probably only be in one group.
$test=explode("|",$modname,3); // separate into three sections at the | pipes
if ($test[0]=="") { // True if the first character in activity name is |
$modname = $test[2]; // The module name is from the second | onwards
if ($name = get_record('groups', 'id', $thisgroupid)) { //get group id
$gns = explode(",", $test[1]); // get all the groups specified
$ret_array= array(0,$modname); // if none match then invisible
foreach ($gns as $gn) { //for each group name specified
if (strcasecmp($gn, $name->name) == 0) { //matches!
$ret_array = array(1,$modname); //sending back 2 values: visible + concatenated name
}
}
}
// else {
// echo "Could not get group record of this user"; } //uncessary message
return $ret_array;
}
return array($mod->visible,$modname);
}
To use it then you put a comma seperated list of groups that you want to see the activity surround by the pipe character, "|", at the beginning of the activity name. If there no groups specified then the activity/resource is visible to everyone.
E.g.
1) An activity or resource with this title would be visible to groups with names "groupx", "groupy" and "groupz" but not to those students from other groups, or in no group:
|groupx,groupy,groupz|Activity or Resource title
2) An activity or resource with this title would be visible to the students in group with name "groupx" only:
|groupx|Activity or Resource title
3) An activity or resource with this title would be visible to everyone:
Activity or Resource title
Teachers can see the group specifications and the activities, unless they enter student mode when they can't see group specific activities at all.
If anyone checks this, or if I am lucky, then I may have a go at hacking the activity pages too.
At the moment my teachers are putting "This activity is ONLY for students in Mr. Smith's class: Title of activity" and some students have been doing the activity anyway.
Not guaranteed at all.
Timothy