views:

105

answers:

1

In Moodle 1.9.7, I need to allow the teacher to upload a file in the admin panel of a brand new assignment plugin.

When overriding the *setup_elements* function in my assignment.class.php, I'm doing something like:

$mform->addElement('file', 'foo', 'Label');
$mform->setHelpButton('foo', array('foo', 'Label', 'assignment/type/my_assignment'));

The form is upload with a nice file picker, but how should I manage the uploaded file? Which function should be overridden? How can I specify the place where I want to upload the file?

There's a complete lack of documentation (mixed to a bit of confusion) in Moodle about this :(

I'm digging into the code to see what's happening behind the stage. In the meantime I thought some of you could have done the same in the past.

I know this is highly specific, but maybe a Moodle developer is looking at this :)

A: 

Well, after digging in the code, here's what I've done.

I've overridden the following assignment functions:

function add_instance($submission)
{
  return (save_uploaded_files($submission)) ? parent::add_instance($submission) : false;
}

function update_instance($submission)
{
  return (save_uploaded_files($submission)) ? parent::update_instance($submission) : false;
}

Where the save_uploaded_files($submission) function looks like:

function save_uploaded_files($submission)
{
  global $CFG;

  $um = new upload_manager('my_file', ... [OPTIONS HERE] ... );
  return $um->process_file_uploads("my/upload/path");
}
Roberto Aloi