Seperate groups not showing

Re: Separate groups not showing

by John Williams -
Number of replies: 0

Hi,

We have this problem too but I think I have solved it - at least for our site !

There is an error in the sql statement in lib/accesslib.php.  I have only tested it where the role assigned to the members of the groups is the same as the default role for the site.  In this case the where statement refers to ra.userid ( from the mdl_role_assignments table ) but in this case the table does not appear in the SQL statement.  Hence the sql fails, nothing is returned and so the error statement appears.

I have only just put the fix into our system and am awaiting feedback from our users.  However it would be good if someone else could try it. 

We are on moodle version 1.9.4

In lib/accesslib.php change the get_users_by_capability function as below so that when the default role is in effect, the ra.userid is replaced by u.id :

    /// Groups
    if ($groups) {
        if (is_array($groups)) {
            $grouptest = 'gm.groupid IN (' . implode(',', $groups) . ')';
        } else {
            $grouptest = 'gm.groupid = ' . $groups;
        }
        if ($defaultroleinteresting) {
           $grouptest = 'u.id IN (SELECT userid FROM ' .
            $CFG->prefix . 'groups_members gm WHERE ' . $grouptest . ')';
        } else {
           $grouptest = 'ra.userid IN (SELECT userid FROM ' .
            $CFG->prefix . 'groups_members gm WHERE ' . $grouptest . ')';
        }

        if ($useviewallgroups) {
            $viewallgroupsusers = get_users_by_capability($context,
                    'moodle/site:accessallgroups', 'u.id, u.id', '', '', '', '', $exceptions);
            if ($defaultroleinteresting) {
               $wherecond['groups'] =  '('. $grouptest . ' OR u.id IN (' .
                                    implode(',', array_keys($viewallgroupsusers)) . '))';
            } else {
               $wherecond['groups'] =  '('. $grouptest . ' OR ra.userid IN (' .
                                    implode(',', array_keys($viewallgroupsusers)) . '))';
            }
        } else {
            $wherecond['groups'] =  '(' . $grouptest .')';
        }
    }

Any feedback most welcome

Average of ratings: Useful (1)