Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
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
-
Component/s: Assignment
-
Labels:None
-
Database:Any
-
Affected Branches:MOODLE_15_STABLE, MOODLE_16_STABLE
-
Fixed Branches:MOODLE_20_STABLE
Description
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.
Attachments
-
- assign-1.9.2.tar.gz
- 28/Oct/08 7:26 PM
- 50 kB
- chris dennison
-
- assignment_1_9_12.patch
- 29/Jul/11 2:41 AM
- 13 kB
- Craig Mickelson
-
- assignment_zip19.patch
- 17/Jul/08 5:03 AM
- 10 kB
- Mark Pearson
-
- assignment_zip19.tgz
- 17/Jul/08 10:19 PM
- 35 kB
- Mark Pearson
-
- assignment.patch
- 08/Jun/07 6:45 AM
- 11 kB
- Dan Marsden
-
$i18n.getText("admin.common.words.hide")
- assignment.zip
- 08/Jun/07 6:43 AM
- 36 kB
- Dan Marsden
-
- assignment/lib.php 101 kB
- assignment/submissions.php 2 kB
- assignment/type/.../assignment.class.php 14 kB
- assignment/type/.../assignment.class.php 40 kB
- assignment/type/.../assignment.class.php 10 kB
-
$i18n.getText("admin.common.words.hide")
- assignment.zip
- 08/Jun/07 6:18 AM
- 36 kB
- Dan Marsden
-
- assignment/lib.php 100 kB
- assignment/submissions.php 2 kB
- assignment/type/.../assignment.class.php 14 kB
- assignment/type/.../assignment.class.php 40 kB
- assignment/type/.../assignment.class.php 11 kB
-
- download_all_assignments_HEAD.patch
- 13/Jan/09 12:26 PM
- 12 kB
- Dan Marsden
-
- download_all_assignments_HEAD.patch
- 09/Jan/09 7:22 PM
- 12 kB
- Dan Marsden
-
- download_all_assignments_HEAD.patch
- 09/Jan/09 10:25 AM
- 11 kB
- Dan Marsden
-
- download_all_submitted_assignments.patch
- 07/Nov/08 6:44 AM
- 12 kB
- Paul Ortman
-
- download_assignments_as_zip.patch
- 10/Jun/10 11:16 PM
- 11 kB
- chris dennison
-
- download_assignments_as_zip.patch
- 10/Jun/10 10:37 PM
- 11 kB
- chris dennison
-
- screenshot-1.jpg
- 641 kB
- 18/Nov/08 11:15 AM
Issue Links
| This issue blocks: | ||||
| MDL-14384 | "Collect assignments" enhancement to the assignment module |
|
|
|
| This issue is duplicated by: | ||||
| MDL-1477 | Offline file access to submitted assignments |
|
|
|
| MDL-4237 | Ability to mass download assignments |
|
|
|
| This issue has been marked as being related by: | ||||
| MDL-30432 | "Download all assignments as a zip" in assignments don't copy files with same name from the same student |
|
|
|
| MDL-28335 | Bulk upload of feedback files |
|
|
|
| MDL-29343 | Separate folder for each student's work in "Download all assignments as a zip" |
|
|
|
Activity
- All
- Comments
- History
- Activity
- Source
- Test Sessions
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.....
no time to do this for 1.9 - will aim for 2.0 (as long as family don't get sick again!)
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.
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! ![]()
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
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. "_");
thanks Chris,
I keep meaning to tidy this up and get it in Core - maybe 2.0?
![]()
Dan
Dan Marsden's assignment ZIP download patch modified for use with Moodle 1.9.2
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
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!
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.
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
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
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 .........
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?
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
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.
There needs to be some code to prevent/warn two teachers downloading the same stuff at the same time.
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 ![]()
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
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?
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);
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! ![]()
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?
slight improvement to structure of patch - also uses consistent naming.
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.
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!!
- 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)
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.
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?
Duh - I must have been looking at an older version or something - thanks mate, love your work.
thanks!
- I keep meaning to push this into HEAD and then 19Stable....just need to find the time to do it!
hey, how would i change the link available on the the webpage to a button called 'download all'?
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
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
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 ![]()
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! ![]()
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.
Until 2.0 with Dan's patch, is out, you may look at my "lighter" solution that do work of 1.9
See http://tracker.moodle.org/browse/MDL-14384
Cheers.
If anyone is interested, I've taken Dan's patch (thanks!) and modified it to make a zip file with info (course, assignment, student) encoded as directory structure, rather than filename.
Git branch of M1.9 here: http://github.com/Dave-B/moodle/commits/M19_zip-assignments
PS: My git branches include some tomfoolery enabling me to work on multiple branches, each with their own set of prefixed tables in one database, so watch out for that ![]()
Oh, forgot to mention - it also adds a Zip & download all button for all assignments in a course ![]()
this is now in HEAD - will look at pushing into stable sometime..... ![]()
oh, just saw the commit, that is definitely not the current recommended way to handle files, instead please use new file API with the standard pluginfile.php callback in assignment module, this file should be also available through the new file browsing api
Also the 1.9.x is not expected to release any new features, only MD may give you an exception for that.
Hi Petr, thanks for taking a look.
I'm not sure how I can use the assignment_pluginfile to do any of this? - I need to rename each file before zipping them and the assignment_pluginfile doesn't support this and sends the file to the browser - which isn't wanted either - we need to rename each file then add them to a zip.
Unless we move to an event handler style function that adds files to a stored zip file when they are uploaded/changed I don't see why we would "store" the zipped file either - could you please provide more feedback around what you mean here?
Thanks!
Event handling is not necessary, assignment_pluginfile gets parameters from the url and can do anything - the only parameter that is actually required is the context id, the rest can be some "virtual" file that does not actually exist - that means you may create files on the fly such as when exporting to XLS, ODS, etc. I think this zip export is a similar case.
It should be possible to rename individual files when adding them to a zip archive, if not it is a bug which should be fixed.
Thanks Petr - I'm still a bit fuzzy though.
from what I can see, assignment_pluginfile works as a send_file function - there isn't a way of using it to retrieve information about all the submitted files in an assignment - which is why I use this to get the list of assignments:
$files = $fs->get_area_files($this->context->id, 'assignment_submission', $a_userid, "timemodified", false);
then each file needs to be added to a zip -I did this by copy ing the files into a new temp folder renaming them at the same time - but looking back at the code again I can't see why I was doing that - I don't need to copy the file anywhere I should be able to rename during zip.
then I use the send_temp_file function to send the file as I want the file to be deleted after sending - I presume you're saying I should use the assignment_plugin function here? - but I can't see a way for the file to be deleted after sending when using that function - could you clarify how you think I should be using the assignment_plugin function?
thanks!
ah - now I remember why I used the copy function - we can't get the location of a file using get_content_file_location to add that item to the zip - I had to copy the file to "get around" that requirement.
Is there a zip function that allows File objects to be passed instead of file paths?
1/ invent some file area for all submissions - for example "assignment_allsubmissions"
2/ decide what the itemid means - for example 0 all groups, anything else group id
3/ decide what path and filename you want to use - it can be pretty much anything because there is only one expert per assignment/group
4/ create the zip file on the fly based on parameters of send_file() methods, I suppose you need to store it in a temp dir because it would not fit into memory, use standard send_temp_file()
5/ the file browsing is different API - it is not yet implemented in many modules - see folder_get_file_areas() and folder_get_file_info()
yes, the file paths and file objects should be both allowed in the zip method
Hi Petr,
I've just pushed through a new assignment_get_files_info() function into mod/assignment/lib.php which returns a list of files using get_area_files - is this an ok way to use it?
thanks,
We've decided we can't move to Moodle 2 yet, but I needed to upgrade to a younger 1.9. I have re-applied the patch uploaded by Paul and updated with a couple of modifications taken from Dan's Moodle 2 patches:- I've changed the way groups are selected and added the error of there are no files to download. I haven't tinkered with the file naming.
Error in previous patch, line 59 replace $submissions with $submit.
flagging this as fixed in 2.0 - The zip isn't available in the 2.0 file browser for the course, but if people want this it can be a separate bug report. - thanks to all who have helped me finally get this in Core! ![]()
Any plans for a 1.9.13 patch?
Many thanks, its a superb feature.
Daniel
Hi Daniel,
someone here might add one, but if you look at the existing patch it should be easy for you to manually apply it to a 1.9.13 install
have a look in the forums - I've posted some code there somewhere which does the trick!
Dan