开发者

Moodle 1.9.7: Uploading file in assignment admin panel

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 :)


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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜