- I think there may be a problem with caching - if the assignment files change within a couple of minutes of the last time you downloaded the full zip, I'm not sure if it collects the new zip correctly. - let me know if you manage to test this!
the attached text file contains a function you need to add to mod\assignment\type\uploadsingle\assignment.class.php
then to trigger this code you need to put a link or button somewhere.... - I used this code for testing it in mod\assignment\submissions.php
replace this line at the bottom of the page:
$assignmentinstance->submissions($mode); // Display or process the submissions
with these lines
if ($download) {
$assignmentinstance->download_submissions();
} else {
$assignmentinstance->submissions($mode); // Display or process the submissions
}
then when viewing your submissions for an assignment eg http://moodle.org/mod/assignment/submissions.php?id=1
add "&download=sfddsafa" to the end of your url.
:-)
Dan
*edit* - put function into text file - post looked a bit long!
Re: Patch for Downloading assignment files as one Zip file.
to this:
function get_submissions($sort='', $dir='DESC') {
/// Return all assignment submissions by ENROLLED students (even empty)
global $CFG;
if ($sort == "lastname" or $sort == "firstname") {
$sort = "u.$sort $dir";
} else if (empty($sort)) {
$sort = "a.timemodified DESC";
} else {
$sort = "a.$sort $dir";
}
$select = "s.course = '".$this->assignment->course."' AND";
$site = get_site();
if ($this->assignment->course == $site->id) {
$select = '';
}
return get_records_sql("SELECT a.*
FROM {$CFG->prefix}assignment_submissions a,
{$CFG->prefix}user_students s,
{$CFG->prefix}user u,
{$CFG->prefix}user_teachers t
WHERE (a.userid = s.userid OR a.userid = t.userid)
AND u.id = a.userid
AND $select a.assignment = '".$this->assignment->id."'
ORDER BY $sort");
}
NOTE: - this will then include all teachers responses in the download as well as the students.
Dan
Re: Patch for Downloading assignment files as one Zip file.
I used your patch and I want to report that it doesn't seem to work with the upload review type.
Josep M.
Re: Patch for Downloading assignment files as one Zip file.
- I might get a chance to look at it sometime this week.....
Re: Patch for Downloading assignment files as one Zip file.
I think the upload review plugin (if it is technically a plugin) works somewhat different from the standard assignment types. I have a non-standard block that tells you which activities have been graded and which ones still have to be graded and while it can monitor the assignments when they are in the 'upload a single file' mode, it doesn't "see" any assignments when I use the 'upload review' mode.
Josep M.
Josep M.
Re: Patch for Downloading assignment files as one Zip file.
here's a new version of this script - the old one had a few issues with larger numbers of assignments - the script timed out instead of zipping all the files, and also if the file was quite large it wasn't downloading the whole file.
Note: - this script will take a while to process if you have a large number of submissions.
Re: Patch for Downloading assignment files as one Zip file.
Warning: Invalid argument supplied for foreach() in C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php on line 22
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php:22) in C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php on line 72
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php:22) in C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php on line 73
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php:22) in C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php on line 74
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php:22) in C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php on line 75
Fatal error: Call to undefined function readfile_chunked() in C:\wamp\www\moodle\mod\assignment\type\uploadsingle\assignment.class.php on line 76
Anyway help on this will be very much appreiated.
The firefox downloadthemall does work fine but not all lecturers here use it.
Thanks to all for the advice.
Re: Patch for Downloading assignment files as one Zip file.
Great hack, but it doesn't seem to work on our fresh Moodle 1.8 install

I can't find where it comes from...
Any idea ?
Thanks
nico
Re: Patch for Downloading assignment files as one Zip file.
Hi Nicolas - it's working for me here, bounce me an e-mail off-line and I'll send you a zip of my assignment folder.
Dan
Follow the instructions in the attached file to add this to your install
Dan
Fatal error: Call to undefined function: strripos() in /home/Moodle/public_html/mod/assignment/type/uploadsingle/assignment.class.php on line 53
Where is this function defined?
that's a PHP function (or so I thought) - turns out it only appeared in php 5 - my bad sorry! I'll rewrite that to use non php 5 specific commands, and update the file today or tomorrow!
thanks!
Dan
thanks!
Dan
On behalf of my faculty, I salute you
-- Art
Hi Dan,
I was wondering if you had a chance to look at the upload/review type to see if this can work with that?
Thanks,
Deon
no sorry, I haven't had a chance - I'll keep it on my list of things todo though!
Dan
I think downloading and uploading files and grades sound like two different tasks that should be done more or less separately. If there's a need for some kind of canonical file name to allow mappings between users and ids, or assignments and ids, then I think there should be helper functions to do it in a consistent way.
Re: Patch for Downloading assignment files as one Zip file.
Over the last few months this code has proven to be a standout addition inmy install and many of my teachers have praised the abilities it puts forward.
Have others been using this in production yet?
Re: Patch for Downloading assignment files as one Zip file.
I've been eager for something like this tool for a while! Glad to test it from cvs!
http://video.google.com/videoplay?docid=-2322043258308494819&q=dennis+daniels+moodle+download
best!
Dennis
I also want to create a function that uploads the files back to moodle for the upload/review assignment type.
Dan
P.s. (MD if you see this and are happy with it, if you gave me access to the assignment mod in cvs, I'd be happy to commit, maintain it)
>upload/review assignment type.
This will be great, Dan!
I'm curious to know how you are planning to achieve that. How will the files be identified so that the system knows which user do they belong to?
>there is also a requirement to be able to upload a list of marks to the system as
>well - allows for all to be "marked" at the same time so students all see their
>marks at the same time, and allows lecturers to mark them off-line.
This would also be a great improvement. Will it be possible to upload the marks in the form of an excel file?
Josep M.
sorry - just saw this! -
The download files include a users username in the name of the file. - it renames the files that a user uploads to include some extra info.
The marks import will hopefully work for both Excel files and CSV - I'll probably get the CSV one working first. - Been pretty busy here so haven't had a chance to do it yet!
Dan
Re: Patch for Downloading assignment files as one Zip file.
Re: Patch for Downloading assignment files as one Zip file.
Attached is the patch modified for both online and uploadsingle assignments. I have applied it to version 1.7 and it seems to work OK, but I haven't tested it exhaustively!
I would like to see the zip facility available in the standard Moodle release but I don't know how to make that happen .
Chris
Re: Patch for Downloading assignment files as one Zip file.
Do you think it would work with 1.6, too?
Thanks,
Art
Re: Patch for Downloading assignment files as one Zip file.
Re: Patch for Downloading assignment files as one Zip file.
Hi Art, I developed it on 1.6 - so just double check the line numbers of where things go in lib.php, the code should be fine.
Regards Chris
Re: Patch for Downloading assignment files as one Zip file.

Re: Patch for Downloading assignment files as one Zip file.
Re: Patch for Downloading assignment files as one Zip file.
Jérôme, I'm not a php coder and i had a problem getting the "download" switch to work. When I clicked the "zip" button nothing happened. I tried the optional_parameter function and that seemed to fix things (we're windows/php/mysql). Try some mtrace debugging to make sure the function download_submission is being called properly.
Chris
Re: Patch for Downloading assignment files as one Zip file.
But now, it is the entire backup which is blocked.
Huum, difficult choice no ?
Jérôme.

Re: Patch for Downloading assignment files as one Zip file.
Ouch!
The 1.7 forums seem full of backup problems...
So - Mondays, Wednesdays and Fridays you do backups
Tuesdays and Thursdays staff can zip their files...
Sorry I'm being facetious. I've only ever used the internal zip routines.
Chris
Re: Patch for Downloading assignment files as one Zip file.
If you want it included in the core, I suggest you create a new feature request in the bug tracker and attach your modified files.
Re: Patch for Downloading assignment files as one Zip file.
Hi Chris,
It's already in the tracker - see MDL-7206
Have I missed something? - the main thing holding me back from putting this in core was that I hadn't written and hadn't seen anyone else do the advanced upload script.... - are you sure it works for the advanced upload type?
thanks,
Dan
Re: Patch for Downloading assignment files as one Zip file.
I have applied it to my 1.8 and 1.9alpha with no issues to report.
It is working in the advanced upload assignment type, but currently only grabs the files, not the notes. This is enough for me at the moment.
I have attached my patched 1.8.1 code to this post. For those tha want to use it, just over-write your existing assignment files with these ones.
P.S. Obviously back up first!!
Re: Patch for Downloading assignment files as one Zip file.
What you do is
diff -c old/assignment new/assignment > assignment-1zip.diff
where old is the directory with the original version and
new is the patched version. This will create a context diff
file.
What I want to do is use the unix patch utility to
apply this "patch".
See http://en.wikipedia.org/wiki/Patch_(Unix)
for background. What patch does is to look at the output
of diff and apply this as a "difference". This is a long time technique in the
unix community to send patches in discussion forums
(originally in network news). As long as
your original files are in sync, using diffs works fine.
The advantage of this approach
is easier management of patches using diff.
For example, you can create a "backup" of the original
with the patch -b option. This will work with a whole
directory tree where multiple files are being changed.
Where I'm going with this is the patch could be listed
in the Moodle Modules and plugins.
I'm working in 1.8.1 (on about May 5th), which is what
you said you have.
I tried to create my own diff -c, but there were quite
a few files that are missing. Rather than guessing at
this, I thought I get you to generate it for me.
Thanks --Dirk
Re: Patch for Downloading assignment files as one Zip file.
Hi Dirk,
I've just attached a diff to MDL-7206
I'm not soo keen putting it in Modules and Plugins - I'm aiming to have it in the main download....
thanks,
Dan
Re: Patch for Downloading assignment files as one Zip file.
Have you raised this with Martin? Whats the status?
JR
Re: Patch for Downloading assignment files as one Zip file.
yup - aiming for 1.9 - I just need nto test using the function sendfile to send files to the user instead of the method currently used. - I'm on holiday these next few weeks, but hope to get it in over that time!
Da
Re: Patch for Downloading assignment files as one Zip file.
I have got it working in 1.9 beta on both the 'Upload single' and 'online' assignment types. Am a little lost getting it going in 'Advanced upload' assignments however.
Open to advice/answers here
Re: Patch for Downloading assignment files as one Zip file.
Wonderful job, guys! This should be in any standard install of moodle!
Jay in Japan
I have not checked the other kinds of assignments.
Re: Patch for Downloading assignment files as one Zip file.
PCLZIP_ERR_READ_OPEN_FAIL (-2) : Unable to open archive './assignment.zip' in wb mode
Do I have permissions in a directory set wrong? (Linux system)
TIA...
Jim
Re: Patch for Downloading assignment files as one Zip file.
Regards Chris
Re: Patch for Downloading assignment files as one Zip file.
Re: Patch for Downloading assignment files as one Zip file.
Jim, my zip file was created on windows. Just unpack to a new directory then copy files out from there.
Chris
Re: Patch for Downloading assignment files as one Zip file.
I've been working on getting the ZIP assignment operational with my test Moodle 1.8.3. Basically, a number of 'power users' are crying out for the ability to download all the assignment submissions as a single zip file. I am happy to announce that it now worketh.
All the gory details are in my Moodle Issues TiddlyWiki under the tag assignment_zip
I have tested this with the latest Moodle 1.8.3 so I cannot guarantee that it'll work with anything younger.
Mark
Re: Patch for Downloading assignment files as one Zip file.
Julian
Re: Patch for Downloading assignment files as one Zip file.
Mark
Re: Patch for Downloading assignment files as one Zip file.
I've had a go using your mods and hit the problem with the responses directory. I've installed a work-around which uses str_replace to change the '/' character to a '_' character for the destination file name. If anyone is interested I'll post the patch.
Have you any idea how to limit the download to a group? Or maybe put the group name into the file name?
Regarding on-line, I need to get that working. We use that for an Edexcel on-line exam where students are allowed a total of 4 hours access to their on-line document. The activity is hidden when they are not in class (so they can't alter anything from home for example).
If you have any suggestions as to what's wrong with the on-line code I'd be pleased to receive them.
Chris
Re: Patch for Downloading assignment files as one Zip file.
The online assignment stores user contributions in the database, not in folders. This means that the folder located :-
So the mkdir call to create the temp file fails.
I've got a test setup working where I check the existence of 'course'/moddata/assignment/'number' - and create it if it doesn't exist.
Then the call to mkdir('course'/moddata/assignment/'number'/temp) works.
To make sure that the folders moddata/assignment were created, I created an 'upload' assignment in the same course, AND had to upload a file.
If anyone knows where the code is that creates the missing folders please let me know because it should (imho) be added to the on-line submission code.
Another fix would be to use a function like mkdir which creates missing directory tree elements - that would make all this much simpler...perhaps there is one already
Chris
Re: Patch for Downloading assignment files as one Zip file.
Now I can tidy up my hacking. Merry Xmas all.
Re: Patch for Downloading assignment files as one Zip file.
Also, have you got an account with Eduspaces ? It's a really great social networking for eduhackers based on elgg. I have a 'community' there called Moodle Vanguard which you may like to join. Or anyone else for that matter.
[England lost the world cup final -- boo hoo
M
Re: Patch for Downloading assignment files as one Zip file in 1.9
I finally got round to installing this, and through following your dif's am happy to report that this works in 1.9 as well.
great work.
JR
Re: Patch for Downloading assignment files as one Zip file in 1.9
In the meantime, how can I change it so that it will add the student's first and last names to the file instead of or in addition to the username?
Thanks,
Evan
Re: Patch for Downloading assignment files as one Zip file in 1.9
just noticed a couple of inconsistencies! - the online assignment saves files using the firstname/lastname, and the upload saves by username:
find this:
$filesforzip = $desttemp . $a_user->username . "_" . $filenewname . "_" . $file; replace it with this: $filesforzip = $desttemp . $a_user->firstname ."_". $a_user->lastname . $file; and that should do it! This isn't going to make it into 1.9 unfortunately - I didn't get it in time before the feature freeze - will try for 2.0!
Re: Patch for Downloading assignment files as one Zip file in 1.9
Thanks. Seems to work just as I want. Awesome...
I'll let you know if I have any problems...
- Evan
I've also re-jiggered the name of the zip directory since before multiple downloads all downloaded as "assignment.zip". The attached version uses "assmt." + shortname of the course + groupname (if exists) + internal id number of the assignment in order to keep the assignments unique.
Also, since I tend to give l-o-n-g names to the assignment links, like "Upload your project here by Jan. 20th!" it didn't make sense to include all of this in each student's file name, so my version uses this formula: username+assmt internal id + uploaded file name.
I've zipped this all into a folder called "type.zip" which can simply replace the "type" folder inside the assignments module. It includes the code for the offline assmt type for completeness even though it hasn't been touched. As a precaution, you might want to rename the old assignment type folder to "type-old" before copying this into the mod/assignment folder just to be on the safe side. All assignment types however work for me in *my* environment!
Dan, feel free to take any part of this revision and incorporate it into yours. I don't intend to maintain this further, although if people report bugs with the code, I'm certainly willing to fix it.
Cheers,
Tom
the version of the patch in MDL-7206 has been able to handle groups for a while, and possibly has a range of other fixes that you haven't put into place.
I've been thinking a lot about the naming of files - I like your suggestions around the naming of the main assignment.zip file, and the individual files. I've had a lot of queries regarding having the Student ID number (not the userid) as the first part of the file (but it's not a required field in Moodle and most people using Moodle probably don't populate it.) - I've also had queries from people asking for the firstname/lastname to be included as well. It would be good if you could post some feedback on MDL-7206 - I'm keen to get it in Core in the next couple of weeks!
Thanks for this. I hope to try out the patch over the next few days.
It seems an ideal answer for a member of staff who has a very unreliable home internet connection. She can download the pupils' work whilst at school and then take it home on a USB for marking.
Question: Is any work being done on the reverse process? How could she easily upload the marked work with comments back to the students? I know she could access the pupils one at a time from the marking screen and reupload their marked work back to them - but is there any way to speed up the process?
Jonathan Smith
ICT Coordinator
Portsmouth High School
no work on the reverse process at this stage, but I've had a lot of interest, just needs someone to front up with the funding to get it done! (let me know if you're interested!)
I've had a go at doing this because we are reducing the turnaround time for feedback and need to speed up the process of uploading marked scripts. I had to make some changes to your download code to achieve a directory structure that suited our needs.
I have attached the patch and this is the help file explaining how it works:
Bulk upload feedback
In order to use this feature, you must first download all submissions using the button 'Bulk download all submissions'. The download will be a zip file which, when extracted, will be of the format:do_not_edit.txt
You can edit the downloaded files or add extra files to the [lastname]_[firstname]_[userid] directories. But DO NOT rename or add directories.
When all feedback is complete, zip up the [course shortname]_[assignment name]_[assno] folder and upload it using this form.
The uploaded files will not overwrite the student files. They will be renamed and saved in a sub directory for each user (within the file structure courseid/moddata/assignment):
eg:
IMPORTANT - Do not edit or delete the 'do_not_edit.txt' file. This is used to verify that you are uploading the correct zip file for the current course and assignment.
Also note that each time you use this feature, any feedback files will be overwritten, unless you rename them.
eg:
1. bulk download files as above example
2. edit myassignment.docx
3. bulk upload the files
This results in a new file .../responses/myassignment_feedback.docx
repeat steps 1 - 3
File .../responses/myassignment_feedback.docx is overwritten with the uploaded file.
Now try
1. bulk download files as above
2. rename myassignment.docx as myassignment2.docx and edit it
3. bulk upload the files
This results in a new file .../responses/myassignment2_feedback.docx, whilst
.../responses/myassignment_feedback.docx is preserved.
Once feedback is released. the student will see all files that reside in their corresponding responses directory.
So in this example student abbf999 will see:
myassignment_feedback2.docx
great to see that you've had a look at this!
I see you've done this work based on 1.9 - the patch for MDL-7206 is now in 2.0 core - would be great if you had a chance to generate a patch for 2.0
the code in 2.0 includes the userid as part of the names of the files (just before the ext) - and includes the original filename - you shouldn't need to use the do_not_edit file and should be able to check to see if the userid exists in the course, then calculate the original file name used by the student and check to make sure that file exists too.
Thanks for sharing your code - if you don't have time to work on a 2.0 version of this someone else could pick up your code and run with it!
Re: Patch for Downloading assignment files - by groups
Hi Dan, I have this 80% complete now. My code works but needs some more testing, commenting and refactoring. I have to leave it for a week, but I'll have it ready for you look at before Grimass.
I love the new file handling code in Moodle 2.0!
Re: Patch for Downloading assignment files as one Zip file.
To use the script:
1. download the submissions (you get assignment.zip)
2. expand the zip, you get a directory assignment filled with files
3. cd into the assignment directory
4. run the script, moodle.py
This forum post has been removed
Re: Patch for Downloading assignment files as one Zip file.
perhaps this might be more useful:
http://docs.moodle.org/en/Development:How_to_apply_a_patch
Re: Patch for Downloading assignment files as one Zip file.
i try to create a button in order to download all files submitted and it works. but the problem is obtained when in the same course there is multiple section and each section is given by one tutor, selecting specific section and trying to download all the assigment related will result of downloading all the assigment without considering the section specified. Any help with my case....Thank you in advanced.
Re: Patch for Downloading assignment files as one Zip file.
Peter, the download can be controlled using groups. Each teacher can have a group for each section. I hope this helps. Chris
Re: Patch for Downloading assignment files as one Zip file.
Dear Chris,
Tutors on my moodle has separate groups in assigments section and zip and download all assigments button. the problem is that i need to give my tutor the ability to download the assigment for all the students in a specific section ( choosen from the drop down list of separate groups)
Re: Patch for Downloading assignment files as one Zip file.
Peter, the download is specific to a particular assignment - and therefore to a section.
At the moment the patch depends on the 'view submissions' functionality. Either you download all submissions or you choose one group to view then download as a zip file.
Would it solve your problem if you could choose more than one of the groups to view then download?
Re: Patch for Downloading assignment files as one Zip file.
Chris,
Even if i choose all participants from the drop down list and i hit on zip and download all assigments i only obtain the one section downloaded. this is an example of a tutor that teachs two sections in a course and would like to download all assigments for that course. tutor in moodle does have that privelege to do so...
Re: Patch for Downloading assignment files as one Zip file.
Hi Peter
Did you ever get the zip download working for a tutor that teaches two sections?
Cheers,
Lynda