Group selection does not always work if student is in multiple groups in Database Activity Module

Description

The mdl_data_records table stores the group id of the student and this is used when a group selection is used to display specific records in the database. This means that if the student is a member of two groups and the wrong group is selected for display, the student's record will not show. Rather than relying on a groupid field in the data_records, it would be preferable to extract all records for each user who belongs to a specific group within a course using a sql selection procedure instead.

This can be effected in this way (in data/view.php)

Around line (360)

// if ($currentgroup) {
// $groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
// } else {
// $groupselect = ' ';
// }

if ($currentgroup) {
$courseid = $data->course;
$groupselect = " AND r.userid = m.userid AND (m.groupid = '$currentgroup' OR r.groupid = 0) AND g.courseid = '$courseid'";
} else {
$groupselect = ' ';
}

Around line 440

} else {
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(r.id) ';
// $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
$tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u, ' .$CFG->prefix.'groups_members m, ' .$CFG->prefix.'groups g ';
$where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
$sortorder = ' ORDER BY r.timecreated '.$order. ' ';
$searchselect = ' ';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
}

Around line 460
$totalcount = count_records_sql($sqlcount); //this no longer works. Using mysql_num_rows instead below.

Around line 510

$records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage);

$totalcount = mysql_num_rows($records);

NOTE that this is might not be a complete solution. I was only interested in display all records, without any search criteria. This does what I want it to do.

Testing Instructions

None

Automated test results

None

Pre-check results

None

Workaround

None

Activity

Michael de Raadt
6 February 2012 at 16:31

I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Michael de Raadt
5 January 2012 at 13:51

Thanks for reporting this issue.

We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

Michael d;

lqjjLKA0p6

Won't Fix

Details

Priority

Affects versions

Assignee

Reporter

Participants

Michael de Raadt
Moodle HQ
Thomas Robb

Clockify

Created 29 April 2008 at 21:47
Updated 6 February 2012 at 16:31
Resolved 6 February 2012 at 16:31