Skip to content

Commit

Permalink
gradebook MDL-25769 Fixed SQL syntax formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Jan 18, 2011
1 parent f2491a1 commit 25081b9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 35 deletions.
28 changes: 15 additions & 13 deletions grade/import/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
48 changes: 30 additions & 18 deletions grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)."
Expand All @@ -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
Expand Down Expand Up @@ -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)."
Expand All @@ -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)."
Expand Down
11 changes: 7 additions & 4 deletions grade/report/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 25081b9

Please sign in to comment.