Skip to content

Commit

Permalink
MDL-31987 Assignment module: Assignment count submissions correctly.
Browse files Browse the repository at this point in the history
For advanced upload assignment, store file count of each submission
into assignment_submissions.numfiles

When counting submissions, if the assignment is open and tracking
drafts, only submissions which has send for marking are counted.
Otherwise, submissions which has numfiles > 0 are counted.

Also change a hardcoded 'submitted' to ASSIGNMENT_STATUS_SUBMITTED.

This patch was originally written by: Sunner Sun <sunner@gmail.com>.

I made some modifation to fixed count_real_submissions() query (ref: MDL-32207) in /mod/assignment/type/upload/assignment.class.php file
  • Loading branch information
Rossiani Wijaya committed Jul 2, 2012
1 parent 1494f20 commit 45353da
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
36 changes: 36 additions & 0 deletions mod/assignment/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,42 @@ function xmldb_assignment_upgrade($oldversion) {
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this

if ($oldversion < 2012062800) {
// Fixed/updated numfiles field in assignment_submissions table to count the actual
// number of files has been uploaded.
upgrade_set_timeout(600); // increase excution time for in large sites
$fs = get_file_storage();

$selectcount = 'SELECT COUNT(s.id), cm.id AS cmid';
$select = 'SELECT s.id, cm.id AS cmid';
$query = " FROM {assignment_submissions} s
INNER JOIN {course_modules} cm
ON s.assignment = cm.instance
JOIN {assignment} a
ON a.id = s.assignment
WHERE a.assignmenttype in ('upload', 'uploadsingle') AND
cm.module = (SELECT id
FROM {modules}
WHERE name = 'assignment')";

$countsubmissions = $DB->count_records_sql($selectcount. $query);
$submissions = $DB->get_recordset_sql($select. $query);

$pbar = new progress_bar('assignmentupgradenumfiles', 500, true);
$i = 0;
foreach ($submissions as $sub) {
$i++;
if ($context = context_module::instance($sub->cmid)) {
$sub->numfiles = count($fs->get_area_files($context->id, 'mod_assignment', 'submission', $sub->id, 'sortorder', false));
$DB->update_record('assignment_submissions', $sub);
}
$pbar->update($i, $countsubmissions, "Counting files of submissions ($i/$countsubmissions)");
}
$submissions->close();

// assignment savepoint reached
upgrade_mod_savepoint(true, 2012062800, 'assignment');
}

return true;
}
Expand Down
17 changes: 12 additions & 5 deletions mod/assignment/type/upload/assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ function process_feedback($formdata=null) {

/**
* Counts all complete (real) assignment submissions by enrolled students. This overrides assignment_base::count_real_submissions().
* This is necessary for advanced file uploads where we need to check that the data2 field is equal to "submitted" to determine
* if a submission is complete.
* This is necessary for tracked advanced file uploads where we need to check that the data2 field is equal to ASSIGNMENT_STATUS_SUBMITTED
* to determine if a submission is complete.
*
* @param int $groupid (optional) If nonzero then count is restricted to this group
* @return int The number of submissions
Expand All @@ -411,13 +411,19 @@ function count_real_submissions($groupid=0) {
list($enroledsql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $groupid);
$params['assignmentid'] = $this->cm->instance;

// Get ids of users enrolled in the given course.
$query = '';
if ($this->drafts_tracked() and $this->isopen()) {
$query = ' AND ' . $DB->sql_compare_text('s.data2') . " = '" . ASSIGNMENT_STATUS_SUBMITTED . "'";
} else {
// Count on submissions with files actually uploaded
$query = " AND s.numfiles > 0";
}
return $DB->count_records_sql("SELECT COUNT('x')
FROM {assignment_submissions} s
LEFT JOIN {assignment} a ON a.id = s.assignment
INNER JOIN ($enroledsql) u ON u.id = s.userid
WHERE s.assignment = :assignmentid AND
s.data2 = 'submitted'", $params);
WHERE s.assignment = :assignmentid" .
$query, $params);
}

function print_responsefiles($userid, $return=false) {
Expand Down Expand Up @@ -581,6 +587,7 @@ function upload_file($mform, $options) {
$formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id);
$updates = new stdClass();
$updates->id = $submission->id;
$updates->numfiles = count($fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, 'sortorder', false));
$updates->timemodified = time();
$DB->update_record('assignment_submissions', $updates);
add_to_log($this->course->id, 'assignment', 'upload',
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$module->version = 2012061700; // The current module version (Date: YYYYMMDDXX)
$module->version = 2012062800; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012061700; // Requires this Moodle version
$module->component = 'mod_assignment'; // Full name of the plugin (used for diagnostics)
$module->cron = 60;

0 comments on commit 45353da

Please sign in to comment.