Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 6466396f3834cd2917de1cc2a8bf22d0d21df628 1 parent 5b2313c
@damyon damyon authored samhemelryk committed
Showing with 83 additions and 23 deletions.
  1. +79 −21 mod/assign/locallib.php
  2. +4 −2 mod/assign/renderer.php
View
100 mod/assign/locallib.php
@@ -1138,16 +1138,30 @@ public function count_participants($currentgroup) {
public function count_submissions_need_grading() {
global $DB;
- $params = array($this->get_course_module()->instance, ASSIGN_SUBMISSION_STATUS_SUBMITTED);
+ if ($this->get_instance()->teamsubmission) {
+ // This does not make sense for group assignment because the submission is shared.
+ return 0;
+ }
+
+ $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;
+
+ $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("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);
+ return $DB->count_records_sql($sql, $params);
}
/**
@@ -1162,8 +1176,15 @@ public function count_grades() {
return 0;
}
- $sql = 'SELECT COUNT(id) FROM {assign_grades} WHERE assignment = ?';
- $params = array($this->get_course_module()->instance);
+ $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 COUNT(g.userid)
+ FROM {assign_grades} g
+ JOIN(' . $esql . ') AS e ON e.id = g.userid
+ WHERE g.assignment = :assignid';
return $DB->count_records_sql($sql, $params);
}
@@ -1180,14 +1201,33 @@ public function count_submissions() {
return 0;
}
- $sql = 'SELECT COUNT(id) FROM {assign_submission} WHERE assignment = ?';
- $params = array($this->get_course_module()->instance);
+ $params = array();
if ($this->get_instance()->teamsubmission) {
- // only look at team submissions
- $sql .= ' AND userid = ?';
- $params[] = 0;
+ // We cannot join on the enrolment tables for group submissions (no userid).
+ $sql = 'SELECT COUNT(s.groupid)
+ FROM {assign_submission} s
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL AND
+ s.userid = :groupuserid';
+
+ $params['assignid'] = $this->get_instance()->id;
+ $params['groupuserid'] = 0;
+ } else {
+ $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 COUNT(s.userid)
+ FROM {assign_submission} s
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL';
}
+
return $DB->count_records_sql($sql, $params);
}
@@ -1199,14 +1239,32 @@ public function count_submissions() {
*/
public function count_submissions_with_status($status) {
global $DB;
- $sql = 'SELECT COUNT(id) FROM {assign_submission} WHERE assignment = ? AND status = ?';
- $params = 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;
if ($this->get_instance()->teamsubmission) {
- // only look at team submissions
- $sql .= ' AND userid = ?';
- $params[] = 0;
+ $sql = 'SELECT COUNT(s.groupid)
+ FROM {assign_submission} s
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL AND
+ s.userid = :groupuserid AND
+ s.status = :submissionstatus';
+ $params['groupuserid'] = 0;
+ } else {
+ $sql = 'SELECT COUNT(s.userid)
+ FROM {assign_submission} s
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL AND
+ s.status = :submissionstatus';
}
+
return $DB->count_records_sql($sql, $params);
}
View
6 mod/assign/renderer.php
@@ -254,8 +254,10 @@ public function render_assign_grading_summary(assign_grading_summary $summary) {
if ($summary->submissionsenabled) {
$this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
$summary->submissionssubmittedcount);
- $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
- $summary->submissionsneedgradingcount);
+ if (!$summary->teamsubmission) {
+ $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
+ $summary->submissionsneedgradingcount);
+ }
}
$time = time();
Please sign in to comment.
Something went wrong with that request. Please try again.