Skip to content
Permalink
Browse files

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

  • Loading branch information...
damyon committed Nov 30, 2012
1 parent 7a9fd6d commit 8f7e1c05af1c73efce1131435b2f573166cff500
Showing with 83 additions and 23 deletions.
  1. +79 −21 mod/assign/locallib.php
  2. +4 −2 mod/assign/renderer.php
@@ -1130,16 +1130,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);
}
/**
@@ -1154,8 +1168,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);
}
@@ -1172,14 +1193,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);
}
@@ -1191,14 +1231,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);
}
@@ -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();

0 comments on commit 8f7e1c0

Please sign in to comment.
You can’t perform that action at this time.