Skip to content

Commit

Permalink
MDL-32772: Change SQL for mod_assign gradingtable to use named query …
Browse files Browse the repository at this point in the history
…parameters

This makes it consistent with the built in filtering in flexible_table.

Fix additional issue with SQL for grading table when there are no enrolled users

Change SQL for mod_assign grading table to use get_in_or_equal
As Suggested by Andrew Nicols in tracker
  • Loading branch information
Damyon Wiese committed May 7, 2012
1 parent e16e230 commit a3dbdc2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions mod/assign/gradingtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class assign_grading_table extends table_sql implements renderable {
* @param int $rowoffset For showing a subsequent page of results
*/
function __construct(assign $assignment, $perpage, $filter, $rowoffset=0) {
global $CFG, $PAGE;
global $CFG, $PAGE, $DB;
parent::__construct('mod_assign_grading');
$this->assignment = $assignment;
$this->perpage = $perpage;
Expand All @@ -81,22 +81,22 @@ function __construct(assign $assignment, $perpage, $filter, $rowoffset=0) {
}

$params = array();
$params[] = $this->assignment->get_instance()->id;
$params[] = $this->assignment->get_instance()->id;
$params['assignmentid1'] = (int)$this->assignment->get_instance()->id;
$params['assignmentid2'] = (int)$this->assignment->get_instance()->id;

$fields = user_picture::fields('u') . ', u.id as userid, u.firstname as firstname, u.lastname as lastname, ';
$fields .= 's.status as status, s.id as submissionid, s.timecreated as firstsubmission, s.timemodified as timesubmitted, ';
$fields .= 'g.id as gradeid, g.grade as grade, g.timemodified as timemarked, g.timecreated as firstmarked, g.mailed as mailed, g.locked as locked';
$from = '{user} u LEFT JOIN {assign_submission} s ON u.id = s.userid AND s.assignment = ?' .
' LEFT JOIN {assign_grades} g ON u.id = g.userid AND g.assignment = ?';
$from = '{user} u LEFT JOIN {assign_submission} s ON u.id = s.userid AND s.assignment = :assignmentid1' .
' LEFT JOIN {assign_grades} g ON u.id = g.userid AND g.assignment = :assignmentid2';

$userparams = array();
foreach ($users as $userid) {
$userparams[] = '?';
$params[] = $userid;
}
$userindex = 0;

list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user');
$where = 'u.id ' . $userwhere;
$params = array_merge($params, $userparams);

$where = 'u.id IN (' . implode(',', $userparams) . ')';
if ($filter == ASSIGN_FILTER_SUBMITTED) {
$where .= ' AND s.timecreated > 0 ';
}
Expand All @@ -105,8 +105,8 @@ function __construct(assign $assignment, $perpage, $filter, $rowoffset=0) {
}
if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) {
$userfilter = (int) array_pop(explode('=', $filter));
$where .= ' AND (u.id = ?)';
$params[] = $userfilter;
$where .= ' AND (u.id = :userid)';
$params['userid'] = $userfilter;
}
$this->set_sql($fields, $from, $where, $params);

Expand Down

0 comments on commit a3dbdc2

Please sign in to comment.