Skip to content
Browse files

Merge branch 'MDL-35127-24' of git://github.com/damyon/moodle into MO…

…ODLE_24_STABLE
  • Loading branch information...
2 parents 653c7d4 + 7364606 commit fb2ac5029c39a9a2de794b9c08a74a9396f774de Sam Hemelryk committed Mar 4, 2013
Showing with 40 additions and 34 deletions.
  1. +40 −34 mod/assign/lib.php
View
74 mod/assign/lib.php
@@ -329,38 +329,8 @@ function assign_print_overview($courses, &$htmlarray) {
// NOTE: we do all possible database work here *outside* of the loop to ensure this scales
//
list($sqlassignmentids, $assignmentidparams) = $DB->get_in_or_equal($assignmentids);
-
- // Build up and array of unmarked submissions indexed by assignment id/ userid
- // for use where the user has grading rights on assignment.
- $dbparams = array_merge(array(ASSIGN_SUBMISSION_STATUS_SUBMITTED), $assignmentidparams);
- $rs = $DB->get_recordset_sql('SELECT
- s.assignment as assignment,
- s.userid as userid,
- s.id as id,
- s.status as status,
- g.timemodified as timegraded
- FROM {assign_submission} s
- LEFT JOIN {assign_grades} g ON
- s.userid = g.userid AND
- s.assignment = g.assignment
- WHERE
- ( g.timemodified is NULL OR
- s.timemodified > g.timemodified ) AND
- s.timemodified IS NOT NULL AND
- s.status = ? AND
- s.assignment ' . $sqlassignmentids, $dbparams);
-
- $unmarkedsubmissions = array();
- foreach ($rs as $rd) {
- $unmarkedsubmissions[$rd->assignment][$rd->userid] = $rd->id;
- }
- $rs->close();
-
-
- // get all user submissions, indexed by assignment id
- $mysubmissions = $DB->get_records_sql("SELECT a.id AS assignment, a.nosubmissions AS nosubmissions, g.timemodified AS timemarked, g.grader AS grader, g.grade AS grade, s.status AS status
- FROM {assign} a LEFT JOIN {assign_grades} g ON g.assignment = a.id AND g.userid = ? LEFT JOIN {assign_submission} s ON s.assignment = a.id AND s.userid = ?
- WHERE a.id $sqlassignmentids", array_merge(array($USER->id, $USER->id), $assignmentidparams));
+ $mysubmissions = null;
+ $unmarkedsubmissions = null;
foreach ($assignments as $assignment) {
// Do not show assignments that are not open
@@ -386,7 +356,33 @@ function assign_print_overview($courses, &$htmlarray) {
}
$context = context_module::instance($assignment->coursemodule);
if (has_capability('mod/assign:grade', $context)) {
-
+ if (!isset($unmarkedsubmissions)) {
+ // Build up and array of unmarked submissions indexed by assignment id/ userid
+ // for use where the user has grading rights on assignment.
+ $dbparams = array_merge(array(ASSIGN_SUBMISSION_STATUS_SUBMITTED), $assignmentidparams);
+ $rs = $DB->get_recordset_sql('SELECT
+ s.assignment as assignment,
+ s.userid as userid,
+ s.id as id,
+ s.status as status,
+ g.timemodified as timegraded
+ FROM {assign_submission} s
+ LEFT JOIN {assign_grades} g ON
+ s.userid = g.userid AND
+ s.assignment = g.assignment
+ WHERE
+ ( g.timemodified is NULL OR
+ s.timemodified > g.timemodified ) AND
+ s.timemodified IS NOT NULL AND
+ s.status = ? AND
+ s.assignment ' . $sqlassignmentids, $dbparams);
+
+ $unmarkedsubmissions = array();
+ foreach ($rs as $rd) {
+ $unmarkedsubmissions[$rd->assignment][$rd->userid] = $rd->id;
+ }
+ $rs->close();
+ }
// count how many people can submit
$submissions = 0; // init
if ($students = get_enrolled_users($context, 'mod/assign:view', 0, 'u.id')) {
@@ -401,7 +397,17 @@ function assign_print_overview($courses, &$htmlarray) {
$link = new moodle_url('/mod/assign/view.php', array('id'=>$assignment->coursemodule, 'action'=>'grading'));
$str .= '<div class="details"><a href="'.$link.'">'.get_string('submissionsnotgraded', 'assign', $submissions).'</a></div>';
}
- } if (has_capability('mod/assign:submit', $context)) {
+ }
+ if (has_capability('mod/assign:submit', $context)) {
+ if (!isset($mysubmissions)) {
+ // get all user submissions, indexed by assignment id
+ $mysubmissions = $DB->get_records_sql("SELECT a.id AS assignment, a.nosubmissions AS nosubmissions, g.timemodified
+ AS timemarked, g.grader AS grader, g.grade AS grade, s.status AS status
+ FROM {assign} a LEFT JOIN {assign_grades} g ON g.assignment = a.id AND
+ g.userid = ? LEFT JOIN {assign_submission} s ON s.assignment = a.id AND
+ s.userid = ? WHERE a.id $sqlassignmentids",
+ array_merge(array($USER->id, $USER->id), $assignmentidparams));
+ }
$str .= '<div class="details">';
$str .= get_string('mysubmission', 'assign');
$submission = $mysubmissions[$assignment->id];

0 comments on commit fb2ac50

Please sign in to comment.
Something went wrong with that request. Please try again.