Permalink
Browse files

MDL-29733 grade: SQL and comment cleanup

  • Loading branch information...
1 parent c2539fc commit b7b04c2dfe467046cec4f2caf551b04d7bace9ea @andyjdavis andyjdavis committed Aug 24, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 lib/grade/grade_item.php
View
@@ -1727,6 +1727,7 @@ public function compute($userid=null) {
return true; // no need to recalculate locked items
}
+ // Precreate grades - we need them to exist
if ($userid) {
$missing = array();
if (!$DB->record_exists('grade_grades', array('itemid'=>$this->id, 'userid'=>$userid))) {
@@ -1735,14 +1736,14 @@ public function compute($userid=null) {
$missing[] = $m;
}
} else {
- // precreate grades - we need them to exist
- $params = array($this->courseid, $this->id);
- $sql = "SELECT go.userid
- FROM {grade_grades} go
+ // Find any users who have grades for some but not all grade items in this course
+ $params = array('gicourseid' => $this->courseid, 'ggitemid' => $this->id);
+ $sql = "SELECT gg.userid
+ FROM {grade_grades} gg
JOIN {grade_items} gi
- ON (gi.id = go.itemid AND gi.courseid = ?)
- GROUP BY go.userid
- HAVING SUM(go.itemid = ?) = 0";
+ ON (gi.id = gg.itemid AND gi.courseid = :gicourseid)
+ GROUP BY gg.userid
+ HAVING SUM(CASE WHEN gg.itemid = :ggitemid THEN 1 ELSE 0 END) = 0";
$missing = $DB->get_records_sql($sql, $params);
}

0 comments on commit b7b04c2

Please sign in to comment.