Permalink
Browse files

gradebook MDL-25769 Fixed SQL syntax formatting

  • Loading branch information...
1 parent f2491a1 commit 25081b95f955bb804860fc49c5e55ca16c8b8507 Sam Hemelryk committed Jan 18, 2011
Showing with 52 additions and 35 deletions.
  1. +15 −13 grade/import/lib.php
  2. +30 −18 grade/report/grader/lib.php
  3. +7 −4 grade/report/lib.php
View
@@ -171,19 +171,21 @@ function get_unenrolled_users_in_import($importcode, $courseid) {
list($enrolledsql, $enrolledparams) = get_enrolled_sql($context);
$sql = "SELECT giv.id, u.firstname, u.lastname, u.idnumber AS useridnumber,
- COALESCE(gi.idnumber, gin.itemname) AS gradeidnumber
- FROM
- {grade_import_values} giv
- JOIN {user} u ON giv.userid = u.id
- LEFT JOIN {grade_items} gi ON gi.id = giv.itemid
- LEFT JOIN {grade_import_newitem} gin ON gin.id = giv.newgradeitem
- LEFT JOIN ($enrolledsql) je ON je.id = u.id
- LEFT JOIN {role_assignments} ra ON (giv.userid = ra.userid AND
- ra.roleid $gradebookrolessql AND
- ra.contextid $relatedctxcondition)
- WHERE giv.importcode = :importcode
- AND (ra.id IS NULL OR je.id IS NULL)
- ORDER BY gradeidnumber, u.lastname, u.firstname";
+ COALESCE(gi.idnumber, gin.itemname) AS gradeidnumber
+ FROM {grade_import_values} giv
+ JOIN {user} u
+ ON giv.userid = u.id
+ LEFT JOIN {grade_items} gi
+ ON gi.id = giv.itemid
+ LEFT JOIN {grade_import_newitem} gin
+ ON gin.id = giv.newgradeitem
+ LEFT JOIN ($enrolledsql) je
+ ON je.id = u.id
+ LEFT JOIN {role_assignments} ra
+ ON (giv.userid = ra.userid AND ra.roleid $gradebookrolessql AND ra.contextid $relatedctxcondition)
+ WHERE giv.importcode = :importcode
+ AND (ra.id IS NULL OR je.id IS NULL)
+ ORDER BY gradeidnumber, u.lastname, u.firstname";
$params = array_merge($gradebookrolesparams, $enrolledparams);
$params['importcode'] = $importcode;
@@ -340,7 +340,7 @@ public function load_users() {
list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context);
//fields we need from the user table
- $userfields = user_picture::fields('u', array('idnumber'));
+ $userfields = user_picture::fields('u', array('idnumber'));
//if the user has clicked one of the sort asc/desc arrows
if (is_numeric($this->sortitemid)) {
@@ -350,10 +350,13 @@ public function load_users() {
$sql = "SELECT $userfields
FROM {user} u
- JOIN ($enrolledsql) je ON je.id = u.id
- JOIN {role_assignments} ra ON ra.userid = u.id
- $this->groupsql
- LEFT JOIN {grade_grades} g ON (g.userid = u.id AND g.itemid = :gitemid)
+ JOIN ($enrolledsql) je
+ ON je.id = u.id
+ JOIN {role_assignments} ra
+ ON ra.userid = u.id
+ $this->groupsql
+ LEFT JOIN {grade_grades} g
+ ON (g.userid = u.id AND g.itemid = :gitemid)
WHERE ra.roleid $gradebookrolessql
AND u.deleted = 0
AND ra.contextid ".get_related_contexts_string($this->context)."
@@ -376,10 +379,12 @@ public function load_users() {
$sql = "SELECT DISTINCT $userfields
FROM {user} u
- JOIN ($enrolledsql) je ON je.id = u.id
- JOIN {role_assignments} ra ON u.id = ra.userid
+ JOIN ($enrolledsql) je
+ ON je.id = u.id
+ JOIN {role_assignments} ra
+ ON u.id = ra.userid
$this->groupsql
- WHERE ra.roleid $gradebookrolessql
+ WHERE ra.roleid $gradebookrolessql
AND u.deleted = 0
AND ra.contextid ".get_related_contexts_string($this->context)."
$this->groupwheresql
@@ -1291,11 +1296,15 @@ public function get_right_avg_row($rows=array(), $grouponly=false) {
// find sums of all grade items in course
$SQL = "SELECT g.itemid, SUM(g.finalgrade) AS sum
FROM {grade_items} gi
- JOIN {grade_grades} g ON g.itemid = gi.id
- JOIN {user} u ON u.id = g.userid
- JOIN ($enrolledsql) je ON je.id = u.id
- JOIN {role_assignments} ra ON ra.userid = u.id
- $groupsql
+ JOIN {grade_grades} g
+ ON g.itemid = gi.id
+ JOIN {user} u
+ ON u.id = g.userid
+ JOIN ($enrolledsql) je
+ ON je.id = u.id
+ JOIN {role_assignments} ra
+ ON ra.userid = u.id
+ $groupsql
WHERE gi.courseid = :courseid
AND ra.roleid $gradebookrolessql
AND ra.contextid ".get_related_contexts_string($this->context)."
@@ -1313,11 +1322,14 @@ public function get_right_avg_row($rows=array(), $grouponly=false) {
// This query returns a count of ungraded grades (NULL finalgrade OR no matching record in grade_grades table)
$SQL = "SELECT gi.id, COUNT(u.id) AS count
FROM {grade_items} gi
- CROSS JOIN {user} u
- JOIN ($enrolledsql) je ON je.id = u.id
- JOIN {role_assignments} ra ON ra.userid = u.id
- LEFT OUTER JOIN {grade_grades} g ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
- $groupsql
+ CROSS JOIN {user} u
+ JOIN ($enrolledsql) je
+ ON je.id = u.id
+ JOIN {role_assignments} ra
+ ON ra.userid = u.id
+ LEFT OUTER JOIN {grade_grades} g
+ ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
+ $groupsql
WHERE gi.courseid = :courseid
AND ra.roleid $gradebookrolessql
AND ra.contextid ".get_related_contexts_string($this->context)."
View
@@ -291,10 +291,13 @@ public function get_numusers($groups=true) {
$countsql = "SELECT COUNT(DISTINCT u.id)
FROM {user} u
- JOIN ($enrolledsql) je ON je.id = u.id
- JOIN {role_assignments} ra ON u.id = ra.userid
- $groupsql
- WHERE ra.roleid $gradebookrolessql AND u.deleted = 0
+ JOIN ($enrolledsql) je
+ ON je.id = u.id
+ JOIN {role_assignments} ra
+ ON u.id = ra.userid
+ $groupsql
+ WHERE ra.roleid $gradebookrolessql
+ AND u.deleted = 0
$groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context);
return $DB->count_records_sql($countsql, $params);

0 comments on commit 25081b9

Please sign in to comment.