Quantcast
Channel: General developer forum
Viewing all articles
Browse latest Browse all 37932

plugin function in custom block

$
0
0
by Oleg Mikheev.  

Hello to everyone!

I was created my custom block and put there filemanger form. In lib.php file i was created plugin function. When file was downloaded, i hava a link via pluginfile.php and all users can download it.

But i have a little trouble. I want to get my custom itemidto all downloaded files. In my form i do this:

    file_prepare_draft_area($draftitemid, $blockcontext->id, 'block_kfu_turndocument', $req_id, 'attachments', array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 50));
    file_save_draft_area_files($draftitemid, $blockcontext->id, 'block_kfu_turndocument', 'attachments', $req_id, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 50));

    $fs = get_file_storage();
    $files = $fs->get_area_files($blockcontext->id, 'block_kfu_turndocument', 'attachments', $req_id, 'filename', false);
    foreach ($files as $file) {
     $fullurl_array = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
     $fullurl = '<a href="'.$CFG->wwwroot.'/pluginfile.php/'.$file->get_contextid().'/'.$file->get_component().'/'.$file->get_filearea().'/'.$file->get_filename().'" target="_blank">link</a>';
     print_r($fullurl);
    }

In lib.php i have this code:

    function block_kfu_turndocument_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload) {

....

....

....

    $fs = get_file_storage();

    $filename = array_pop($args);
    $filepath = $args ? '/'.implode('/', $args).'/' : '/';


    if (!$file = $fs->get_file($context->id, 'block_kfu_turndocument', 'attachments', 5, $filepath, $filename) or $file->is_directory()) {
        send_file_not_found();
    }

If you can see, in the get_file function i put custom itemid=5. But it need to be send in pluginfile function by variable. I don't understand how to do it. Thanks for your help.


Viewing all articles
Browse latest Browse all 37932

Latest Images

Trending Articles



Latest Images