Issue Details (XML | Word | Printable)

Key: MDL-7206
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Dan Marsden
Reporter: dhiraj bhartu
Votes: 35
Watchers: 30
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Can not download all submitted assignment at once compressed in one single zip file

Created: 25/Oct/06 05:42 AM   Updated: 13/Aug/09 05:35 AM
Return to search
Component/s: Assignment
Affects Version/s: 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.6, 1.6.1, 1.6.2, 1.6.3
Fix Version/s: 2.0

File Attachments: 1. GZip Archive assign-1.9.2.tar.gz (50 kB)
2. Text File assignment.patch (11 kB)
3. Zip Archive assignment.zip (36 kB)
4. Zip Archive assignment.zip (36 kB)
5. Text File assignment_zip19.patch (10 kB)
6. File assignment_zip19.tgz (35 kB)
7. Text File download_all_assignments_HEAD.patch (12 kB)
8. Text File download_all_assignments_HEAD.patch (12 kB)
9. Text File download_all_assignments_HEAD.patch (11 kB)
10. Text File download_all_submitted_assignments.patch (12 kB)

Image Attachments:

1. screenshot-1.jpg
(641 kB)

Database: Any
Participants: chris dennison, Chris Fryer, Dan Marsden, dhiraj bhartu, farah ahmad, Jason Howe, Julian Ridden, Mark Drechsler, Mark Pearson, Martin Dougiamas, Paul Ortman, Thomas Robb and William Yeung
Security Level: None
Affected Branches: MOODLE_15_STABLE, MOODLE_16_STABLE
Fixed Branches: MOODLE_20_STABLE


 Description  « Hide
In webct there is a feature where when students submit assisgnment we can download all assignment into one zip file. in moodle there is not a feature like that at the moment. if we could have a button at the buttom of the submitted assignment page when clicked can download all assignments into a zip file.

At the moment i'm using firefox's download them all tool to download all assisgnment.

Thanks.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Dan Marsden added a comment - 28/Mar/07 08:16 AM
have a look in the forums - I've posted some code there somewhere which does the trick!

Dan


Dan Marsden added a comment - 08/Jun/07 06:18 AM
attached patch for 1.8/1.9 that allows this.

Dan Marsden added a comment - 08/Jun/07 06:43 AM
cleaner patch

Dan Marsden added a comment - 08/Jun/07 06:45 AM
attaching diff patch.

Dan Marsden added a comment - 08/Jun/07 06:51 AM
looking at that patch again - I think there's a better way of sending the file to the user - I'm pretty sure there's a moodle function in the lib - I'll find it, test and provide the patch.....

Martin Dougiamas added a comment - 08/Jun/07 11:26 AM
OK, let us know when it settles down

Dan Marsden added a comment - 06/Sep/07 09:44 AM
no time to do this for 1.9 - will aim for 2.0 (as long as family don't get sick again!)

William Yeung added a comment - 01/Nov/07 05:24 PM
I think this is quite important- we have been using WebCT and are quite tired of it. Implementing this feature make the system functions in par with WebCT on assignment submission.

Dan Marsden added a comment - 02/Nov/07 04:44 AM - edited
thanks for the encouragement William - It's definately on my list of things to do! - unfortunately it hasn't made 1.9 - (currently in a "freeze" - only bug patches can be applied. But I will try my best to get this into 2.0!)

thanks.

Dan

P.S. - you can take the patch as given here and apply it to your moodle install to get the feature in the meantime!


Chris Fryer added a comment - 02/Apr/08 12:20 AM
Dan

I've found a bug, I'm afraid. In your member function download_submissions(), you use the name of the assignment as a prefix for a temporary filename:

//create prefix of new filename
$filenewname = $this->assignment->name. "_";

Someone recently created an assignment that had a forward slash in its name, e.g. "Essay/Project". On *nix, this is interpreted as a directory separator, which of course causes an error. I suspect a backslash would cause the same problem on Windows, but I haven't checked.

I guess you could either change the line above to

$filenewname = clean_filename($this->assignment->name. "_");

or you could change

//get files new name.
$filesforzip = $desttemp . $a_user->username . "" . $filenewname . "" . $file;

to

$filesforzip = clean_filename($desttemp . $a_user->username . "" . $filenewname . "" . $file);

Chris


Chris Fryer added a comment - 02/Apr/08 12:34 AM
Sorry to comment again so soon, but of course only the first of my proposed solutions will actually work. So

$filenewname = $this->assignment->name. "_";

should become

$filenewname = clean_filename($this->assignment->name. "_");


Dan Marsden added a comment - 02/Apr/08 02:43 AM
thanks Chris,

I keep meaning to tidy this up and get it in Core - maybe 2.0?

Dan


Mark Pearson added a comment - 17/Jul/08 05:03 AM
Dan Marsden's assignment ZIP download patch modified for use with Moodle 1.9.2

Mark Pearson added a comment - 17/Jul/08 05:06 AM
Note that if the teacher has uploaded a response file (with advanced uploading of files) the script fails:
eg /var/moodledata19/4/moddata/assignment/25/temp/ronw_Avoiding underwater ghoulies__responses/els_screenshot.png
/var/moodledata19/4/moddata/assignment/25/34/responses/els_screenshot.png

Dan Marsden added a comment - 17/Jul/08 05:34 AM
Thanks Mark, I keep meaning to put this in Core sometime....

Dan


Mark Pearson added a comment - 17/Jul/08 10:19 PM
Here's a tgz file with all the patches files sussed for Moodle version 1.9.2. I have not done anything to fix the problem when the ZIP and download is run in the presence of response files (it fails) nor have I fixed the issue raised above with slashes in filenames – sorry! I don't understand how faculty can survive without this patch when there are large classes with uploaded assignments!

Jason Howe added a comment - 23/Sep/08 06:06 AM
In addition to the "/" issue mentioned above, we've also run into a "?" issue with assignment names. I think the zip function is choking on the ? and writing out an invalid file.

In this situation, windows blocks the unzip and is unable to interpret the file.
7zip also gives this error.


Chris Fryer added a comment - 23/Sep/08 07:33 PM
Jason

This is the same problem, with the same fix. You need to change

$filenewname = $this->assignment->name. "_";

to

$filenewname = clean_filename($this->assignment->name. "_");

in /mod/assignment/type/upload/assignment.class.php and /mod/assignment/type/uploadsingle/assignment.class.php

This will ensure any characters that are not valid in a filename are removed/replaced.

"Online" assignments are unaffected, because they always create a file called "online_assignment.zip"

Chris


chris dennison added a comment - 14/Oct/08 10:20 PM
Hi folks - ref previous forum comments on online assignments.
I originally wrote the code that gave the downloaded file a .html extension - because it mainly is html. However for my teachers to open the downloaded, unzipped file with Microsoft Word I added start and end html tags:-

$submission = "<html>" . $submission . "</html>"

Would be really nice if using groups to limit download to current group.

Chris


chris dennison added a comment - 22/Oct/08 05:17 PM
I've rediscovered another bug. If the moodle course uses online assignments only, then the moodledata folder is not created. The attempt to create the temp file for zipping fails and moodle dies.

Modify the download function in online:

if (!file_exists($desttemp)) { //create temp dir if it doesn't already exist.
mkdir($desttemp,0777,true); //can create a tree .........


chris dennison added a comment - 24/Oct/08 09:27 PM
I am running 1.9.2+ Build 20080820. I have downloaded Mark Pearsons files and modified them to:
. include the fixes mentioned above
. only include submissions from group members when grouping is used
. includes response files

There are differences in the released code in my build from the build that Mark used.

What is the best way to submit the changes for you guys to test out?


Mark Pearson added a comment - 28/Oct/08 07:01 AM
Chris,
Could you upload your fixes back here. I'll try rebuilding into the 1.9.3 code over the next month or so ...
Mark

chris dennison added a comment - 28/Oct/08 07:26 PM
Assignment files from 1.9.2

chris dennison added a comment - 28/Oct/08 09:40 PM
I am using two calls in /lib/deprecatedlib.php :- set_current_group and get_current_group. I've just realised that the following line needs to be added to the code creating the zip button in lib.php.

$status = set_current_group($course->id,$currentgroup);

This stores the current group in the session cookie so the download function can pick it up.

Maybe a better way would be to store it in the button code along with the 'zip' option.


chris dennison added a comment - 28/Oct/08 09:48 PM
There needs to be some code to prevent/warn two teachers downloading the same stuff at the same time.

Paul Ortman added a comment - 07/Nov/08 06:42 AM
I've taken the zip of files from Chris Dennison and generated a patch against current MOODLE_19_STABLE CVS. A number of changes I've left out as they don't seem to be functional, but cosmetic from the original. I'd note that the patch seems to have a variety of white-space differences than the code around it, but that's all I've noticed.

A possible future enhancement I could see includes only printing the download button when there is something viable to download. I attempted to try to figure out the code using PHP's is_callable($this->assignment, 'download_submissions'); function, but clearly I'm not understanding the object model/code in the submissions.php file.

Anyway, thanks for this code and perhaps my patch will help get it merged back to 1.9 stable


Paul Ortman added a comment - 07/Nov/08 06:44 AM
Patch against MOODLE_19_STABLE on Nov 6, 2008

Dan Marsden added a comment - 07/Nov/08 08:23 AM
thanks Paul - I'd like to finally get round to putting this patch in! - any chance you could create a patch for 2.0 and make sure it works with the new file api?

thanks!

Dan


Julian Ridden added a comment - 18/Nov/08 11:15 AM
The code is working ini that the zip seems to be generated. However ater than prompting for download it is rendering the zip on the screen. See attached image.

Any ideas?


Julian Ridden added a comment - 18/Nov/08 01:35 PM
Issue resolved. Was my stupidity. Although it did lead to the following comment from Dan. This works on my install.

That patch should really use the function send_file()

find this:

header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header ("Content-Type: application/octet-stream");
header ("Content-Length: " . filesize($desttemp.$filename));
header ("Content-Disposition: attachment; filename=$filename");
readfile($desttemp.$filename);

replace it with this:

send_file($desttemp.$filename, $filename, 'default',0,false,true);


Dan Marsden added a comment - 09/Jan/09 10:25 AM
finally got round to writing a patch for this for HEAD - I haven't tested any of the groups stuff in this, but it appears to be working! - I'd like to get this in HEAD soon, but it would be good if there were a few other people who could test it first!

Dan Marsden added a comment - 09/Jan/09 07:22 PM
uploading slight change to patch.

Also there are some inconsistencies in the naming convention used for the file attachments

the on-line assignment html files are saved using the name "firstname_lastname.html"
where as the upload assignment files are saved using the convention "username_assignmentname_originalfilename"

We have a few clients using a similar patch and they use the convention "idnumber_assignmentname_originalfilename"

I'm thinking that people may want to customise this per-site? - Long term I'd like to see a bulk upload function to allow teachers to bulk download then make notes in-line on files, zip them back up, then upload the zip back into the site to allow students to receive the new version including notes from their teacher. - This means we need to uniquely Identify the files - using something like their username but in some cases, the username may not be all that useful to teachers wanting to identify a file. - There are a few watchers on this bug - what are peoples thoughts?


Dan Marsden added a comment - 13/Jan/09 12:26 PM
slight improvement to structure of patch - also uses consistent naming.

chris dennison added a comment - 22/Jan/09 08:09 PM
Naming files:

The on-line assignment doesn't have the concept of filename, so I used firstname\lastname to identify the files to the teacher. Including username would make them unique.

Some folk manufacture usernames to indicate things like cohort. Maybe pre-pending the username would be the best action to allow sorting.

I personally would like to see at least lastname being used in all asignment types as part of the name so the teacher can readily identify the author.


Thomas Robb added a comment - 05/Feb/09 08:10 AM
Concerning the naming of files, I don't think that a one-size fits all solution is going to work. I suggest that, as with other modules preferences be settable at both the site level (site admin/activities/modules) and within individual instances of activities.

There are two separate issues here, the naming of the .zip file and the naming of the individual student files. For the .zip file these are possible components:

  • The word "assignment" or "assmt" or the word or abbreviationin other languages as defined in the lang kit,
  • The shortname for the course or course id,
  • The fullname of the assmt, a truncated part (eg, the first 10 letters) or the id of the assmt.
  • The group name, a truncated version of the group name or the group I'd (automatically ignored when there are no groups)

Similarly, with the individual student files, Fullname, lastname or idnumber or user i'd are possibilities. At my school fullname is not an option because it includes both the kanji and alphabet versions of the name and is this very long!!


Dan Marsden added a comment - 05/Feb/09 08:32 AM
I think I'll probably push through the initial version into core without the ability to modify the naming - that can come later with a new tracker issue.....

at the moment, I'm tending towards your suggestions here:
http://moodle.org/mod/forum/discuss.php?d=31899#p503549

so the naming of the original zip:
'assignment'.'course shortname'.'. 'groupname (if exists)'.'' 'internal id number of the assignment'.'.zip'

and the naming of the individual files:
username+uploaded file name+userid+assignmentid.fileextn
notice the userid and assignmentid at the end of the string - I'll use this as the unique identifier for the re-uploading script that comes later - that way the initial prefix can be configured via an interface to something like idnumber or username, or firstname lastname etc etc.


Mark Drechsler added a comment - 08/Apr/09 08:30 AM
From what I can see this only works on an 'upload a single file' assignment type - any plans to expand to 'Advanced upload' as well, or am I missing something?

Dan Marsden added a comment - 08/Apr/09 08:46 AM
works in single/advanced and online assignment types

Dan


Mark Drechsler added a comment - 08/Apr/09 08:54 AM
Duh - I must have been looking at an older version or something - thanks mate, love your work.

Dan Marsden added a comment - 08/Apr/09 08:58 AM
thanks! - I keep meaning to push this into HEAD and then 19Stable....just need to find the time to do it!

farah ahmad added a comment - 09/Apr/09 03:00 AM
hey, how would i change the link available on the the webpage to a button called 'download all'?

Martin Dougiamas added a comment - 22/May/09 10:22 PM
Would love to see this in core, my +1 for it in 2.0 !

Julian Ridden added a comment - 22/May/09 10:25 PM
Great to see MartinD's comment.

Can I also push you Dan to commit this to the 2.0?

Come on! You know you want to do it

Julian


Mark Pearson added a comment - 10/Jul/09 06:35 AM
With regard to naming conventions some of my teachers rejoice in horrendously long filenames for assignments. For example : "Senior_research_paper_due_ TUESDAY_at-7-00_am-do_not_be_late_Final_Paper-_Yazdan_edited.doc" When concatenated with the other required strings such a name will often break the filename length limit. Is there a check that could be added for total length of filename such that the user is warned that the process cannot continue because the assignment name is too long? Thanks for all the efforts here.

Mark


Mark Pearson added a comment - 13/Aug/09 04:24 AM
I tried applying download_all_assignments_HEAD.patch to a bog standard 1.9.5 installation. Several problems emerged:
1. in /mod/assignment/lib.php there was inserted a php terminator (?>) on line 3085 preventing the remaining two functions in the library from executing.
2. in /mod/assignment/type/upload the patch totally borked assignment.class.php so that all the code ended up in the .rej file and assignment.class.php had 0 bytes. I don't understand what went wrong there.
3. Even after I tidied things up by hand and did an experimental trial when I clicked on [[downloadall]] a blank page ensued. Switching full debugging on from the Admin interface revealed the following error message:

Fatal error: Call to undefined function get_file_storage() in /usr/home/markp/public_html/moo-t95/mod/assignment/type/uploadsingle/assignment.class.php on line 198

I could not find the function 'get_file_storage' in lib/file_lib.php but it's likely to be somewhere else.

In short, the patch as available here does not seem to function with version 1.9.5. I do not have time to suss this out right now but will try to get it sorted in a couple of weeks after feeding the 5,000 multitudes with the Moodle loaves and fishes


Dan Marsden added a comment - 13/Aug/09 05:24 AM
not surprisingly as HEAD == 2.0

that patch likely won't apply nicely to HEAD either as a lot of structural changes have been made since. - I uploaded it here for future reference - I WILL get this in Moodle 2.0 before release!


Mark Pearson added a comment - 13/Aug/09 05:35 AM
Darn. I should have looked more closely.
So basically this won't be usable until a working release of 2.0, right?
I guess I'll go back to the previous version. There's no way we can use 2.0 in production right now.