Closed frederikmillingpytlick closed 3 years ago
@frederikmillingpytlick Thanks for the report, I'll look into it.
Ok, for me 'groupmember' is an empty array. What version of Moodle are you using please?
Moodle v3.9.3 (2020061503)
Thanks. Ok, have you disabled the calendar / not showing the calendar / upcoming events on that course page?
The calender block isn't added to the course page, neither is the upcoming events block
Thanks. Ok 'groupmember' is populated by 'get_complete_user_data()' which has 'This is a special hack to speedup calendar display.' and the SQL it uses is different to 'groups_get_user_groups()' need to think.
Ok, given that 'get_complete_user_data()' has:
$sql = "SELECT g.id, g.courseid
FROM {groups} g, {groups_members} gm
WHERE gm.groupid=g.id AND gm.userid=?";
// This is a special hack to speedup calendar display.
$user->groupmember = array();
if (!isguestuser($user)) {
if ($groups = $DB->get_records_sql($sql, array($user->id))) {
foreach ($groups as $group) {
if (!array_key_exists($group->courseid, $user->groupmember)) {
$user->groupmember[$group->courseid] = array();
}
$user->groupmember[$group->courseid][$group->id] = $group->id;
}
}
}
then I think this:
foreach ($USER->groupmember as $grouparray) {
foreach ($grouparray as $group) {
$usergroups[] = $group;
}
}
$theresults = array();
foreach ($results as $r) {
if (!empty($r->userid)) { // User id of 0 means that there should be a groupid.
if ($r->userid == $USER->id) { // This record is for us.
$theresults[$r->assignment] = $r;
}
} else if (!empty($r->groupid)) {
if (in_array($r->groupid, $usergroups)) { // This record is in one of our groups.
$theresults[$r->assignment] = $r;
}
}
}
is wrong as the activity.php code is looking at $usergroups as a single array and not the array of arrays with groups that it is.
@frederikmillingpytlick Please test https://github.com/gjb2048/moodle-format_topcoll/commit/21f3dc0144eb38075c758f26cc33014e990f049c - easiest way is to simply take a copy of the entire activity.php as a drop in replacement.
@gjb2048 Tested OK, thanks ;)
PHP message:
Line: https://github.com/gjb2048/moodle-format_topcoll/blob/18c95d48d65e563f775d2e98e12fe6c0625a6dfa/classes/activity.php#L650
You should be able to fix the issue by using:
groups_get_user_groups($course_id, $user_id); //It defaults to use $USER's id if nothing is specified