mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-46171 assign: And here is the benefit of the new column - simplify the SQL
This commit is contained in:
parent
1523f9e0fb
commit
ad030ab4a5
@ -129,23 +129,25 @@ class mod_assign_external extends external_api {
|
|||||||
if (count ($requestedassignmentids) > 0) {
|
if (count ($requestedassignmentids) > 0) {
|
||||||
$placeholders = array();
|
$placeholders = array();
|
||||||
list($inorequalsql, $placeholders) = $DB->get_in_or_equal($requestedassignmentids, SQL_PARAMS_NAMED);
|
list($inorequalsql, $placeholders) = $DB->get_in_or_equal($requestedassignmentids, SQL_PARAMS_NAMED);
|
||||||
list($inorequalsql2, $placeholders2) = $DB->get_in_or_equal($requestedassignmentids, SQL_PARAMS_NAMED);
|
|
||||||
|
|
||||||
$grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
|
$sql = "SELECT ag.id,
|
||||||
FROM {assign_grades} mxg
|
ag.assignment,
|
||||||
WHERE mxg.assignment ' . $inorequalsql2 . ' GROUP BY mxg.userid';
|
ag.userid,
|
||||||
|
ag.timecreated,
|
||||||
|
ag.timemodified,
|
||||||
|
ag.grader,
|
||||||
|
ag.grade,
|
||||||
|
ag.attemptnumber
|
||||||
|
FROM {assign_grades} ag, {assign_submission} as
|
||||||
|
WHERE as.assignment $inorequalsql
|
||||||
|
AND as.userid = ag.userid
|
||||||
|
AND as.latest = 1
|
||||||
|
AND as.attemptnumber = ag.attemptnumber
|
||||||
|
AND ag.timemodified >= :since
|
||||||
|
AND ag.assignment = as.assignment
|
||||||
|
ORDER BY ag.assignment, ag.id";
|
||||||
|
|
||||||
$sql = "SELECT ag.id,ag.assignment,ag.userid,ag.timecreated,ag.timemodified,".
|
|
||||||
"ag.grader,ag.grade,ag.attemptnumber ".
|
|
||||||
"FROM {assign_grades} ag ".
|
|
||||||
"JOIN ( " . $grademaxattempt . " ) gmx ON ag.userid = gmx.userid".
|
|
||||||
" WHERE ag.assignment ".$inorequalsql.
|
|
||||||
" AND ag.timemodified >= :since".
|
|
||||||
" AND ag.attemptnumber = gmx.maxattempt" .
|
|
||||||
" ORDER BY ag.assignment, ag.id";
|
|
||||||
$placeholders['since'] = $params['since'];
|
$placeholders['since'] = $params['since'];
|
||||||
// Combine the parameters.
|
|
||||||
$placeholders += $placeholders2;
|
|
||||||
$rs = $DB->get_recordset_sql($sql, $placeholders);
|
$rs = $DB->get_recordset_sql($sql, $placeholders);
|
||||||
$currentassignmentid = null;
|
$currentassignmentid = null;
|
||||||
$assignment = null;
|
$assignment = null;
|
||||||
|
@ -129,8 +129,6 @@ class assign_grading_table extends table_sql implements renderable {
|
|||||||
$params['assignmentid1'] = (int)$this->assignment->get_instance()->id;
|
$params['assignmentid1'] = (int)$this->assignment->get_instance()->id;
|
||||||
$params['assignmentid2'] = (int)$this->assignment->get_instance()->id;
|
$params['assignmentid2'] = (int)$this->assignment->get_instance()->id;
|
||||||
$params['assignmentid3'] = (int)$this->assignment->get_instance()->id;
|
$params['assignmentid3'] = (int)$this->assignment->get_instance()->id;
|
||||||
$params['assignmentid4'] = (int)$this->assignment->get_instance()->id;
|
|
||||||
$params['assignmentid5'] = (int)$this->assignment->get_instance()->id;
|
|
||||||
|
|
||||||
$extrauserfields = get_extra_user_fields($this->assignment->get_context());
|
$extrauserfields = get_extra_user_fields($this->assignment->get_context());
|
||||||
|
|
||||||
@ -151,23 +149,15 @@ class assign_grading_table extends table_sql implements renderable {
|
|||||||
$fields .= 'uf.workflowstate as workflowstate, ';
|
$fields .= 'uf.workflowstate as workflowstate, ';
|
||||||
$fields .= 'uf.allocatedmarker as allocatedmarker ';
|
$fields .= 'uf.allocatedmarker as allocatedmarker ';
|
||||||
|
|
||||||
$submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt
|
|
||||||
FROM {assign_submission} mxs
|
|
||||||
WHERE mxs.assignment = :assignmentid4 GROUP BY mxs.userid';
|
|
||||||
$grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
|
|
||||||
FROM {assign_grades} mxg
|
|
||||||
WHERE mxg.assignment = :assignmentid5 GROUP BY mxg.userid';
|
|
||||||
$from = '{user} u
|
$from = '{user} u
|
||||||
LEFT JOIN ( ' . $submissionmaxattempt . ' ) smx ON u.id = smx.userid
|
|
||||||
LEFT JOIN ( ' . $grademaxattempt . ' ) gmx ON u.id = gmx.userid
|
|
||||||
LEFT JOIN {assign_submission} s ON
|
LEFT JOIN {assign_submission} s ON
|
||||||
u.id = s.userid AND
|
u.id = s.userid AND
|
||||||
s.assignment = :assignmentid1 AND
|
s.assignment = :assignmentid1 AND
|
||||||
s.attemptnumber = smx.maxattempt
|
s.latest = 1
|
||||||
LEFT JOIN {assign_grades} g ON
|
LEFT JOIN {assign_grades} g ON
|
||||||
u.id = g.userid AND
|
u.id = g.userid AND
|
||||||
g.assignment = :assignmentid2 AND
|
g.assignment = :assignmentid2 AND
|
||||||
g.attemptnumber = gmx.maxattempt
|
g.attemptnumber = s.attemptnumber
|
||||||
LEFT JOIN {assign_user_flags} uf ON u.id = uf.userid AND uf.assignment = :assignmentid3';
|
LEFT JOIN {assign_user_flags} uf ON u.id = uf.userid AND uf.assignment = :assignmentid3';
|
||||||
|
|
||||||
$userparams = array();
|
$userparams = array();
|
||||||
|
@ -388,11 +388,6 @@ function assign_print_overview($courses, &$htmlarray) {
|
|||||||
$context = context_module::instance($assignment->coursemodule);
|
$context = context_module::instance($assignment->coursemodule);
|
||||||
if (has_capability('mod/assign:grade', $context)) {
|
if (has_capability('mod/assign:grade', $context)) {
|
||||||
if (!isset($unmarkedsubmissions)) {
|
if (!isset($unmarkedsubmissions)) {
|
||||||
$submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt, mxs.assignment
|
|
||||||
FROM {assign_submission} mxs
|
|
||||||
WHERE mxs.assignment ' . $sqlassignmentids . '
|
|
||||||
GROUP BY mxs.userid, mxs.assignment';
|
|
||||||
|
|
||||||
// Build up and array of unmarked submissions indexed by assignment id/ userid
|
// Build up and array of unmarked submissions indexed by assignment id/ userid
|
||||||
// for use where the user has grading rights on assignment.
|
// for use where the user has grading rights on assignment.
|
||||||
$dbparams = array_merge($assignmentidparams, array(ASSIGN_SUBMISSION_STATUS_SUBMITTED), $assignmentidparams);
|
$dbparams = array_merge($assignmentidparams, array(ASSIGN_SUBMISSION_STATUS_SUBMITTED), $assignmentidparams);
|
||||||
@ -403,19 +398,16 @@ function assign_print_overview($courses, &$htmlarray) {
|
|||||||
s.status as status,
|
s.status as status,
|
||||||
g.timemodified as timegraded
|
g.timemodified as timegraded
|
||||||
FROM {assign_submission} s
|
FROM {assign_submission} s
|
||||||
LEFT JOIN ( ' . $submissionmaxattempt . ' ) smx ON
|
|
||||||
smx.userid = s.userid AND
|
|
||||||
smx.assignment = s.id
|
|
||||||
LEFT JOIN {assign_grades} g ON
|
LEFT JOIN {assign_grades} g ON
|
||||||
s.userid = g.userid AND
|
s.userid = g.userid AND
|
||||||
s.assignment = g.assignment AND
|
s.assignment = g.assignment AND
|
||||||
g.attemptnumber = smx.maxattempt
|
g.attemptnumber = s.attemptnumber
|
||||||
WHERE
|
WHERE
|
||||||
( g.timemodified is NULL OR
|
( g.timemodified is NULL OR
|
||||||
s.timemodified > g.timemodified ) AND
|
s.timemodified > g.timemodified ) AND
|
||||||
s.timemodified IS NOT NULL AND
|
s.timemodified IS NOT NULL AND
|
||||||
s.status = ? AND
|
s.status = ? AND
|
||||||
s.attemptnumber = smx.maxattempt AND
|
s.latest = 1 AND
|
||||||
s.assignment ' . $sqlassignmentids, $dbparams);
|
s.assignment ' . $sqlassignmentids, $dbparams);
|
||||||
|
|
||||||
$unmarkedsubmissions = array();
|
$unmarkedsubmissions = array();
|
||||||
@ -447,15 +439,8 @@ function assign_print_overview($courses, &$htmlarray) {
|
|||||||
if (has_capability('mod/assign:submit', $context)) {
|
if (has_capability('mod/assign:submit', $context)) {
|
||||||
if (!isset($mysubmissions)) {
|
if (!isset($mysubmissions)) {
|
||||||
|
|
||||||
// This is nasty because we only want the last attempt.
|
|
||||||
$submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt, mxs.assignment
|
|
||||||
FROM {assign_submission} mxs
|
|
||||||
WHERE mxs.assignment ' . $sqlassignmentids . '
|
|
||||||
AND mxs.userid = ?
|
|
||||||
GROUP BY mxs.userid, mxs.assignment';
|
|
||||||
|
|
||||||
// Get all user submissions, indexed by assignment id.
|
// Get all user submissions, indexed by assignment id.
|
||||||
$dbparams = array_merge($assignmentidparams, array($USER->id, $USER->id, $USER->id), $assignmentidparams);
|
$dbparams = array_merge(array($USER->id, $USER->id), $assignmentidparams);
|
||||||
$mysubmissions = $DB->get_records_sql('SELECT
|
$mysubmissions = $DB->get_records_sql('SELECT
|
||||||
a.id AS assignment,
|
a.id AS assignment,
|
||||||
a.nosubmissions AS nosubmissions,
|
a.nosubmissions AS nosubmissions,
|
||||||
@ -464,14 +449,12 @@ function assign_print_overview($courses, &$htmlarray) {
|
|||||||
g.grade AS grade,
|
g.grade AS grade,
|
||||||
s.status AS status
|
s.status AS status
|
||||||
FROM {assign} a
|
FROM {assign} a
|
||||||
LEFT JOIN ( ' . $submissionmaxattempt . ' ) smx ON
|
|
||||||
smx.assignment = a.id
|
|
||||||
LEFT JOIN {assign_grades} g ON
|
LEFT JOIN {assign_grades} g ON
|
||||||
g.assignment = a.id AND
|
g.assignment = a.id AND
|
||||||
g.userid = ? AND
|
g.userid = ? AND
|
||||||
g.attemptnumber = smx.maxattempt
|
g.attemptnumber = s.attemptnumber
|
||||||
LEFT JOIN {assign_submission} s ON
|
LEFT JOIN {assign_submission} s ON
|
||||||
s.attemptnumber = smx.maxattempt AND
|
s.latest = 1 AND
|
||||||
s.assignment = a.id AND
|
s.assignment = a.id AND
|
||||||
s.userid = ?
|
s.userid = ?
|
||||||
WHERE a.id ' . $sqlassignmentids, $dbparams);
|
WHERE a.id ' . $sqlassignmentids, $dbparams);
|
||||||
@ -530,6 +513,7 @@ function assign_print_recent_activity($course, $viewfullnames, $timestart) {
|
|||||||
JOIN {modules} md ON md.id = cm.module
|
JOIN {modules} md ON md.id = cm.module
|
||||||
JOIN {user} u ON u.id = asb.userid
|
JOIN {user} u ON u.id = asb.userid
|
||||||
WHERE asb.timemodified > ? AND
|
WHERE asb.timemodified > ? AND
|
||||||
|
asb.latest = 1 AND
|
||||||
a.course = ? AND
|
a.course = ? AND
|
||||||
md.name = ?
|
md.name = ?
|
||||||
ORDER BY asb.timemodified ASC", $dbparams)) {
|
ORDER BY asb.timemodified ASC", $dbparams)) {
|
||||||
|
@ -1447,29 +1447,18 @@ class assign {
|
|||||||
$currentgroup = groups_get_activity_group($this->get_course_module(), true);
|
$currentgroup = groups_get_activity_group($this->get_course_module(), true);
|
||||||
list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, true);
|
list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, true);
|
||||||
|
|
||||||
$submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt
|
|
||||||
FROM {assign_submission} mxs
|
|
||||||
WHERE mxs.assignment = :assignid2 GROUP BY mxs.userid';
|
|
||||||
$grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
|
|
||||||
FROM {assign_grades} mxg
|
|
||||||
WHERE mxg.assignment = :assignid3 GROUP BY mxg.userid';
|
|
||||||
|
|
||||||
$params['assignid'] = $this->get_instance()->id;
|
$params['assignid'] = $this->get_instance()->id;
|
||||||
$params['assignid2'] = $this->get_instance()->id;
|
|
||||||
$params['assignid3'] = $this->get_instance()->id;
|
|
||||||
$params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
|
$params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(s.userid)
|
$sql = 'SELECT COUNT(s.userid)
|
||||||
FROM {assign_submission} s
|
FROM {assign_submission} s
|
||||||
LEFT JOIN ( ' . $submissionmaxattempt . ' ) smx ON s.userid = smx.userid
|
|
||||||
LEFT JOIN ( ' . $grademaxattempt . ' ) gmx ON s.userid = gmx.userid
|
|
||||||
LEFT JOIN {assign_grades} g ON
|
LEFT JOIN {assign_grades} g ON
|
||||||
s.assignment = g.assignment AND
|
s.assignment = g.assignment AND
|
||||||
s.userid = g.userid AND
|
s.userid = g.userid AND
|
||||||
g.attemptnumber = gmx.maxattempt
|
g.attemptnumber = s.attemptnumber
|
||||||
JOIN(' . $esql . ') e ON e.id = s.userid
|
JOIN(' . $esql . ') e ON e.id = s.userid
|
||||||
WHERE
|
WHERE
|
||||||
s.attemptnumber = smx.maxattempt AND
|
s.latest = 1 AND
|
||||||
s.assignment = :assignid AND
|
s.assignment = :assignid AND
|
||||||
s.timemodified IS NOT NULL AND
|
s.timemodified IS NOT NULL AND
|
||||||
s.status = :submitted AND
|
s.status = :submitted AND
|
||||||
@ -1563,15 +1552,10 @@ class assign {
|
|||||||
$params['submissionstatus'] = $status;
|
$params['submissionstatus'] = $status;
|
||||||
|
|
||||||
if ($this->get_instance()->teamsubmission) {
|
if ($this->get_instance()->teamsubmission) {
|
||||||
$maxattemptsql = 'SELECT mxs.groupid, MAX(mxs.attemptnumber) AS maxattempt
|
|
||||||
FROM {assign_submission} mxs
|
|
||||||
WHERE mxs.assignment = :assignid2 GROUP BY mxs.groupid';
|
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(s.groupid)
|
$sql = 'SELECT COUNT(s.groupid)
|
||||||
FROM {assign_submission} s
|
FROM {assign_submission} s
|
||||||
JOIN(' . $maxattemptsql . ') smx ON s.groupid = smx.groupid
|
|
||||||
WHERE
|
WHERE
|
||||||
s.attemptnumber = smx.maxattempt AND
|
s.latest = 1 AND
|
||||||
s.assignment = :assignid AND
|
s.assignment = :assignid AND
|
||||||
s.timemodified IS NOT NULL AND
|
s.timemodified IS NOT NULL AND
|
||||||
s.userid = :groupuserid AND
|
s.userid = :groupuserid AND
|
||||||
@ -1585,9 +1569,8 @@ class assign {
|
|||||||
$sql = 'SELECT COUNT(s.userid)
|
$sql = 'SELECT COUNT(s.userid)
|
||||||
FROM {assign_submission} s
|
FROM {assign_submission} s
|
||||||
JOIN(' . $esql . ') e ON e.id = s.userid
|
JOIN(' . $esql . ') e ON e.id = s.userid
|
||||||
JOIN(' . $maxattemptsql . ') smx ON s.userid = smx.userid
|
|
||||||
WHERE
|
WHERE
|
||||||
s.attemptnumber = smx.maxattempt AND
|
s.latest = 1 AND
|
||||||
s.assignment = :assignid AND
|
s.assignment = :assignid AND
|
||||||
s.timemodified IS NOT NULL AND
|
s.timemodified IS NOT NULL AND
|
||||||
s.status = :submissionstatus';
|
s.status = :submissionstatus';
|
||||||
@ -6944,18 +6927,9 @@ class assign {
|
|||||||
$where = ' WHERE u.id != :userid ';
|
$where = ' WHERE u.id != :userid ';
|
||||||
}
|
}
|
||||||
|
|
||||||
$submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt
|
|
||||||
FROM {assign_submission} mxs
|
|
||||||
WHERE mxs.assignment = :assignid1 GROUP BY mxs.userid';
|
|
||||||
$grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
|
|
||||||
FROM {assign_grades} mxg
|
|
||||||
WHERE mxg.assignment = :assignid2 GROUP BY mxg.userid';
|
|
||||||
|
|
||||||
// When the gradebook asks us for grades - only return the last attempt for each user.
|
// When the gradebook asks us for grades - only return the last attempt for each user.
|
||||||
$params = array('assignid1'=>$assignmentid,
|
$params = array('assignid1'=>$assignmentid,
|
||||||
'assignid2'=>$assignmentid,
|
'assignid2'=>$assignmentid,
|
||||||
'assignid3'=>$assignmentid,
|
|
||||||
'assignid4'=>$assignmentid,
|
|
||||||
'userid'=>$userid);
|
'userid'=>$userid);
|
||||||
$graderesults = $DB->get_recordset_sql('SELECT
|
$graderesults = $DB->get_recordset_sql('SELECT
|
||||||
u.id as userid,
|
u.id as userid,
|
||||||
@ -6964,14 +6938,12 @@ class assign {
|
|||||||
g.timemodified as dategraded,
|
g.timemodified as dategraded,
|
||||||
g.grader as usermodified
|
g.grader as usermodified
|
||||||
FROM {user} u
|
FROM {user} u
|
||||||
LEFT JOIN ( ' . $submissionmaxattempt . ' ) smx ON u.id = smx.userid
|
|
||||||
LEFT JOIN ( ' . $grademaxattempt . ' ) gmx ON u.id = gmx.userid
|
|
||||||
LEFT JOIN {assign_submission} s
|
LEFT JOIN {assign_submission} s
|
||||||
ON u.id = s.userid and s.assignment = :assignid3 AND
|
ON u.id = s.userid and s.assignment = :assignid1 AND
|
||||||
s.attemptnumber = smx.maxattempt
|
s.latest = 1
|
||||||
JOIN {assign_grades} g
|
JOIN {assign_grades} g
|
||||||
ON u.id = g.userid and g.assignment = :assignid4 AND
|
ON u.id = g.userid and g.assignment = :assignid2 AND
|
||||||
g.attemptnumber = gmx.maxattempt' .
|
g.attemptnumber = s.attemptnumber' .
|
||||||
$where, $params);
|
$where, $params);
|
||||||
|
|
||||||
foreach ($graderesults as $result) {
|
foreach ($graderesults as $result) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user