Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-36263 Assignment: Do not count submissions of unenrolled users

  • Loading branch information...
commit 40c1230f1ffbe75b06a1a7bcbb3f92d9162fb6ee 1 parent 46c678a
@damyon damyon authored
Showing with 57 additions and 24 deletions.
  1. +57 −24 mod/assign/locallib.php
View
81 mod/assign/locallib.php
@@ -1055,16 +1055,25 @@ public function count_participants($currentgroup) {
public function count_submissions_need_grading() {
global $DB;
- $params = array($this->get_course_module()->instance, ASSIGN_SUBMISSION_STATUS_SUBMITTED);
+ $currentgroup = groups_get_activity_group($this->get_course_module(), true);
+ list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, false);
+
+ $params['assignid'] = $this->get_instance()->id;
+ $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
- return $DB->count_records_sql("SELECT COUNT('x')
- FROM {assign_submission} s
- LEFT JOIN {assign_grades} g ON s.assignment = g.assignment AND s.userid = g.userid
- WHERE s.assignment = ?
- AND s.timemodified IS NOT NULL
- AND (s.timemodified > g.timemodified OR g.timemodified IS NULL)
- AND s.status = ?",
- $params);
+ $sql = 'SELECT COUNT(s.userid)
+ FROM {assign_submission} s
+ LEFT JOIN {assign_grades} g ON
+ s.assignment = g.assignment AND
+ s.userid = g.userid
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL AND
+ s.status = :submitted AND
+ (s.timemodified > g.timemodified OR g.timemodified IS NULL)';
+
+ return $DB->count_records_sql($sql, $params);
}
/**
@@ -1075,10 +1084,26 @@ public function count_submissions_need_grading() {
*/
public function count_submissions_with_status($status) {
global $DB;
- return $DB->count_records_sql("SELECT COUNT('x')
- FROM {assign_submission}
- WHERE assignment = ? AND
- status = ?", array($this->get_course_module()->instance, $status));
+
+ $currentgroup = groups_get_activity_group($this->get_course_module(), true);
+ list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, false);
+
+ $params['assignid'] = $this->get_instance()->id;
+ $params['submissionstatus'] = $status;
+
+ $sql = 'SELECT COUNT(s.userid)
+ FROM {assign_submission} s
+ LEFT JOIN {assign_grades} g ON
+ s.assignment = g.assignment AND
+ s.userid = g.userid
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL AND
+ s.status = :submissionstatus AND
+ (s.timemodified > g.timemodified OR g.timemodified IS NULL)';
+
+ return $DB->count_records_sql($sql, $params);
}
/**
@@ -1131,22 +1156,32 @@ private function get_userid_for_row($num, $last){
* @return array The submission objects indexed by id
*/
private function get_all_submissions( $sort="", $dir="DESC") {
- global $CFG, $DB;
+ global $DB;
+
+ $currentgroup = groups_get_activity_group($this->get_course_module(), true);
+ list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, false);
+
+ $params['assignid'] = $this->get_instance()->id;
+
+ $sql = 'SELECT s.*, u.lastname, u.firstname, u.username
+ FROM {assign_submission} s
+ JOIN {user} u ON s.userid = u.id
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL';
if ($sort == "lastname" or $sort == "firstname") {
$sort = "u.$sort $dir";
} else if (empty($sort)) {
- $sort = "a.timemodified DESC";
+ $sort = "s.timemodified DESC";
} else {
- $sort = "a.$sort $dir";
+ $sort = "s.$sort $dir";
}
- return $DB->get_records_sql("SELECT a.*
- FROM {assign_submission} a, {user} u
- WHERE u.id = a.userid
- AND a.assignment = ?
- ORDER BY $sort", array($this->get_instance()->id));
+ $sql .= ' ORDER BY ' . $sort;
+ return $DB->get_records_sql($sql, $params);
}
/**
@@ -1535,9 +1570,7 @@ private function download_submissions() {
if ((groups_is_member($groupid,$userid) or !$groupmode or !$groupid)) {
// get the plugins to add their own files to the zip
- $user = $DB->get_record("user", array("id"=>$userid),'id,username,firstname,lastname', MUST_EXIST);
-
- $prefix = clean_filename(fullname($user) . "_" .$userid . "_");
+ $prefix = clean_filename(fullname($submission) . "_" .$userid . "_");
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
Please sign in to comment.
Something went wrong with that request. Please try again.