Merge branch 'MDL-64325-main' of https://github.com/kevpercy/moodle

This commit is contained in:
Jun Pataleta 2024-06-12 16:36:30 +08:00
commit 1db19bc5bf
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
2 changed files with 8 additions and 17 deletions

View File

@ -511,28 +511,23 @@ class grade_category extends grade_object {
}
}
$grade_inst = new grade_grade();
$fields = 'g.'.implode(',g.', $grade_inst->required_fields);
$gradeinst = new grade_grade();
$fields = implode(',', $gradeinst->required_fields);
// where to look for final grades - include grade of this item too, we will store the results there
$gis = array_merge($depends_on, array($this->grade_item->id));
list($usql, $params) = $DB->get_in_or_equal($gis);
if ($userid) {
$usersql = "AND g.userid=?";
$usersql = "AND userid=?";
$params[] = $userid;
} else {
$usersql = "";
}
$sql = "SELECT $fields
FROM {grade_grades} g, {grade_items} gi
WHERE gi.id = g.itemid AND gi.id $usql $usersql
ORDER BY g.userid";
// group the results by userid and aggregate the grades for this user
$rs = $DB->get_recordset_sql($sql, $params);
$rs = $DB->get_recordset_select('grade_grades', "itemid $usql $usersql", $params, 'userid', $fields);
if ($rs->valid()) {
$prevuser = 0;
$grade_values = array();

View File

@ -2211,25 +2211,21 @@ class grade_item extends grade_object {
list($usql, $params) = $DB->get_in_or_equal($gis);
if ($userid) {
$usersql = "AND g.userid=?";
$usersql = "AND userid=?";
$params[] = $userid;
} else {
$usersql = "";
}
$grade_inst = new grade_grade();
$fields = 'g.'.implode(',g.', $grade_inst->required_fields);
$gradeinst = new grade_grade();
$fields = implode(',', $gradeinst->required_fields);
$params[] = $this->courseid;
$sql = "SELECT $fields
FROM {grade_grades} g, {grade_items} gi
WHERE gi.id = g.itemid AND gi.id $usql $usersql AND gi.courseid=?
ORDER BY g.userid";
$return = true;
// group the grades by userid and use formula on the group
$rs = $DB->get_recordset_sql($sql, $params);
$rs = $DB->get_recordset_select('grade_grades', "itemid $usql $usersql", $params, 'userid', $fields);
if ($rs->valid()) {
$prevuser = 0;
$grade_records = array();