Association assignment_submissions table and files table

Association assignment_submissions table and files table

door Flo Jungwirth -
Aantal antwoorden: 6

Dear community,

I'm currently working on a new moodle block, and I need to print all files, which the current user has submitted to assignments.

My problem is, that i can't find a relationship in the database between the assignment_submissions table and the file table. So how can I find out, which file belongs to which assignment submission?

Thanks in advance,

Flo

Gemiddelde van de beoordelingen:  -
Als antwoord op Flo Jungwirth

Re: Association assignment_submissions table and files table

door Matt Gibson -

The files table stores files in a big list, with several fields that sort the files into areas. Specifically, each file has a context, component, filearea and itemid.

You tell the file upload widget what these parameters are and it sets them when it saves files. When you retrieve files, you supply the same parameters and it will return an array of all the files that were saved with those details.

Saving files:

// Add this to the definition() method in a moodleform

$filemanager_options = array('subdirs'=>1, 'maxbytes'=>$this->_customdata['course']->maxbytes, 'maxfiles'=>10, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);

$mform->addElement('filemanager', 'submission', get_string('uploadafile'), null, $filemanager_options);

// Then, when you save the form's data:

file_save_draft_area_files($submission->submissionfiles, $PAGE->context->id, 'mod_eassessment', 'submission', $submission->id, $fileoptions);

Getting files:

$fs = get_file_storage();

$submissionfiles = $fs->get_area_files($this->eassessment->get_context()->id, 'mod_eassessment', 'submission', $this->id, "id", false);

Gemiddelde van de beoordelingen:  -
Als antwoord op Flo Jungwirth

Re: Association assignment_submissions table and files table

door Davo Smith -
Foto van Core developers Foto van Peer reviewers Foto van Plugin developers

The answer depends on whether you are using Moodle 1.9 or Moodle 2.0 (you haven't specified which in your original enquiry).

The basic answer is that you will need to work back from the submissions table, to the assignment table (I've not got the code in front of me, so it's either the 'assignment' or the 'assignmentid' field).

Moodle 1.9 - from the assignment ID, you can get the course id. The submissions are all stored in the folder: [moodledata]/[courseid]/assignments/[assignmentid]/[submissionid] (or something like that - have a look in your testing moodledata folder to get the exact path.

Moodle 2.0 - from the assignmentid you can get the course module id (look in mod/assignment/view.php to see the function call you need to convert an assignment id into an cm id). From the cm id, you can get a contextid. You can then use the file functions to look up the associated files (have a look in mod/assignment/type/upload/assignment.class.php and find the 'print_student_answer' function to help you out).

Gemiddelde van de beoordelingen:  -
Als antwoord op Davo Smith

Re: Association assignment_submissions table and files table

door Flo Jungwirth -

I'm using Moodle 2.0.

Ok, I have now a list of the assignments and submissions and iterate over them. For each I get the course module id. But how can I get the contextid from the cm id?

Thank you very much for your replies!

//EDIT: What stands the contextid in the files table for? There is no entry in the context table with such an id.

Gemiddelde van de beoordelingen:  -
Als antwoord op Flo Jungwirth

Re: Association assignment_submissions table and files table

door Davo Smith -
Foto van Core developers Foto van Peer reviewers Foto van Plugin developers

$context = get_context_instance(CONTEXT_MODULE, $cmid);

Have a look here: http://docs.moodle.org/en/Development:Using_the_file_API#List_area_files

The example given happens to be exactly what you are wanting to do (although the first parameter will be $context->id, in this case).

Gemiddelde van de beoordelingen:  -
Als antwoord op Davo Smith

Re: Association assignment_submissions table and files table

door Flo Jungwirth -

Wohoow. It works! Thanks, Davo. You saved me a lot of time browsing the moodle docs glimlach

Gemiddelde van de beoordelingen:  -
Als antwoord op Flo Jungwirth

Re: Association assignment_submissions table and files table

door Carlos Lara -

Hi Flo

Im looking to add this functionality to my course. Could you point me at how you did it ? maybe you have a tutorial somewhere ? i think it would be a great addition to moodle.

im using moodle 1.9 but i would be willing to switch because it looks like you accomplished what i need.

thanks!

Carlos

Gemiddelde van de beoordelingen:  -