Permalink
Browse files

MDL-31276: Fixes for offline marking and team submissions

Filenames in zip of all submission now contains the team group name.
  • Loading branch information...
Damyon Wiese
Damyon Wiese committed Sep 3, 2012
1 parent df47b77 commit d0d4796b4a64774e30854afce18a6a559367e558
Showing with 55 additions and 38 deletions.
  1. +11 −6 mod/assign/feedback/file/importzipform.php
  2. +44 −32 mod/assign/locallib.php
@@ -88,12 +88,17 @@ function definition() {
$assignment->get_unique_id_for_user($user->id);
}
$grade = $assignment->get_user_grade($user->id, false);
- $exists = $fs->file_exists($contextid,
- 'assignfeedback_file',
- ASSIGNFEEDBACK_FILE_FILEAREA,
- $grade->id,
- '/',
- $filename);
+
+ $exists = false;
+ if ($grade) {
+ $exists = $fs->file_exists($contextid,
+ 'assignfeedback_file',
+ ASSIGNFEEDBACK_FILE_FILEAREA,
+ $grade->id,
+ '/',
+ $filename);
+ }
+
if (!$grade || !$exists) {
$updates[] = get_string('feedbackfileadded', 'assignfeedback_file',
array('filename'=>$filename, 'student'=>$userdesc));
View
@@ -247,6 +247,9 @@ public function has_submissions_or_grades() {
public function get_plugin_by_type($subtype, $type) {
$shortsubtype = substr($subtype, strlen('assign'));
$name = $shortsubtype . 'plugins';
+ if ($name != 'feedbackplugins' && $name != 'submissionplugins') {
+ return null;
+ }
$pluginlist = $this->$name;
foreach ($pluginlist as $plugin) {
if ($plugin->get_type() == $type) {
@@ -1776,63 +1779,72 @@ private function can_grade() {
private function download_submissions() {
global $CFG,$DB;
- // more efficient to load this here
+ // More efficient to load this here.
require_once($CFG->libdir.'/filelib.php');
- // load all submissions
- $submissions = $this->get_all_submissions('','');
-
- if (empty($submissions)) {
- print_error('errornosubmissions', 'assign');
- return;
- }
+ // Load all users with submit.
+ $students = get_enrolled_users($this->context, "mod/assign:submit");
- // build a list of files to zip
+ // Build a list of files to zip.
$filesforzipping = array();
$fs = get_file_storage();
$groupmode = groups_get_activity_groupmode($this->get_course_module());
- $groupid = 0; // All users
+ // All users.
+ $groupid = 0;
$groupname = '';
if ($groupmode) {
$groupid = groups_get_activity_group($this->get_course_module(), true);
$groupname = groups_get_group_name($groupid).'-';
}
- // construct the zip file name
- $filename = str_replace(' ', '_', clean_filename($this->get_course()->shortname.'-'.$this->get_instance()->name.'-'.$groupname.$this->get_course_module()->id.".zip")); //name of new zip file.
+ // Construct the zip file name.
+ $filename = clean_filename($this->get_course()->shortname.'-'.
+ $this->get_instance()->name.'-'.
+ $groupname.$this->get_course_module()->id.".zip");
- // get all the files for each submission
- foreach ($submissions as $submission) {
- $userid = $submission->userid; //get userid
- if ((groups_is_member($groupid,$userid) or !$groupmode or !$groupid)) {
- // get the plugins to add their own files to the zip
+ // Get all the files for each student.
+ foreach ($students as $student) {
+ $userid = $student->id;
- $user = $DB->get_record("user", array("id"=>$userid),'id,username,firstname,lastname', MUST_EXIST);
+ if ((groups_is_member($groupid,$userid) or !$groupmode or !$groupid)) {
+ // Get the plugins to add their own files to the zip.
+
+ $submissiongroup = false;
+ $groupname = '';
+ if ($this->get_instance()->teamsubmission) {
+ $submission = $this->get_group_submission($userid, 0, false);
+ $submissiongroup = $this->get_submission_group($userid);
+ $groupname = '-' . $submissiongroup->name;
+ } else {
+ $submission = $this->get_user_submission($userid, false);
+ }
if ($this->is_blind_marking()) {
- $prefix = clean_filename(get_string('participant', 'assign') . "_" . $this->get_uniqueid_for_user($userid) . "_");
+ $prefix = clean_filename(str_replace('_', ' ', get_string('participant', 'assign') . $groupname) .
+ "_" . $this->get_uniqueid_for_user($userid) . "_");
} else {
- $prefix = clean_filename(fullname($user) . "_" . $this->get_uniqueid_for_user($userid) . "_");
+ $prefix = clean_filename(str_replace('_', ' ', fullname($student) . $groupname) .
+ "_" . $this->get_uniqueid_for_user($userid) . "_");
}
- foreach ($this->submissionplugins as $plugin) {
- if ($plugin->is_enabled() && $plugin->is_visible()) {
- $pluginfiles = $plugin->get_files($submission);
-
-
- foreach ($pluginfiles as $zipfilename => $file) {
- $prefixedfilename = $prefix . $plugin->get_subtype() . '_' . $plugin->get_type() . '_' . $zipfilename;
- $filesforzipping[$prefixedfilename] = $file;
+ if ($submission) {
+ foreach ($this->submissionplugins as $plugin) {
+ if ($plugin->is_enabled() && $plugin->is_visible()) {
+ $pluginfiles = $plugin->get_files($submission);
+ foreach ($pluginfiles as $zipfilename => $file) {
+ $prefixedfilename = $prefix . $plugin->get_subtype() . '_' . $plugin->get_type() . '_' . $zipfilename;
+ $filesforzipping[$prefixedfilename] = $file;
+ }
}
}
}
-
}
- } // end of foreach loop
+ }
if ($zipfile = $this->pack_files($filesforzipping)) {
$this->add_to_log('download all submissions', get_string('downloadall', 'assign'));
- send_temp_file($zipfile, $filename); //send file and delete after sending.
+ // Send file and delete after sending.
+ send_temp_file($zipfile, $filename);
}
}
@@ -2447,7 +2459,7 @@ private function process_grading_batch_operation(& $mform) {
if ($data->operation == 'grantextension') {
return 'grantextension';
- } else if (strpos($prefix, $data->operation) == 0) {
+ } else if (strpos($data->operation, $prefix) === 0) {
$tail = substr($data->operation, strlen($prefix));
list($plugintype, $action) = explode('_', $tail, 2);

0 comments on commit d0d4796

Please sign in to comment.