Php Moodle Filemanager草稿图像仅对我可见

Php Moodle Filemanager草稿图像仅对我可见,php,api,file,moodle,Php,Api,File,Moodle,我一直在制作一个插件,允许管理员上传图片,我可以看到图片(其他人也可以),删除和重新上传,但问题是当另一个管理员试图编辑插件时,他们看不到草稿图片,他们只看到他们上传的图片,我看到我上传的图片作为草稿。我想要的是,如果我上传了一张图片,所有试图编辑的人都会看到我上传的图片 我将在下面添加我的代码,如果有人能帮助我,我将非常感激 view.php: $i = 1; $out = array(); $fs = get_file_storage(); $files

我一直在制作一个插件,允许管理员上传图片,我可以看到图片(其他人也可以),删除和重新上传,但问题是当另一个管理员试图编辑插件时,他们看不到草稿图片,他们只看到他们上传的图片,我看到我上传的图片作为草稿。我想要的是,如果我上传了一张图片,所有试图编辑的人都会看到我上传的图片

我将在下面添加我的代码,如果有人能帮助我,我将非常感激

view.php:

    $i = 1;


    $out = array();

    $fs = get_file_storage();
    $files = $fs->get_area_files($this->context->id, 'block_cls_user_profile', 'cls_img', $i, false, false);

    foreach ($files as $file) {
    $filename = $file->get_filename();
    $url = moodle_url::make_pluginfile_url(
          $file->get_contextid(),
          $file->get_component(),
          $file->get_filearea(),
          $file->get_itemid(),
          $file->get_filepath(),
          $filename);
    // $out[] = html_writer::link($url, $filename);
    }
    // $br = html_writer::empty_tag('br');
lib.php

// Check the contextlevel is as expected - if your plugin is a block, this becomes CONTEXT_BLOCK, etc.
if ($context->contextlevel != CONTEXT_BLOCK) {
    return false; 
}

// Make sure the filearea is one of those used by the plugin.
if ($filearea !== 'cls_img') {
    return false;
}

// $fs = get_file_storage();
// $file = $fs->get_file($context->id, 'local_myplugin', $filearea, $args[0], '/', $args[1]);

// send_stored_file($file);

// Make sure the user is logged in and has access to the module (plugins that are not course modules should leave out the 'cm' part).
require_login($course, true);

// No check for capability, because everybody needs to see it
// Check the relevant capabilities - these may vary depending on the filearea being accessed.
/*
if (!has_capability('mod/bookcase:addinstance', $context)) {
    return false;
}
*/

// Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
$itemid = array_shift($args); // The first item in the $args array.

// Use the itemid to retrieve any relevant data records and perform any security checks to see if the
// user really does have access to the file in question.

// Extract the filename / filepath from the $args array.
$filename = array_pop($args); // The last item in the $args array.
if (!$args) {
    $filepath = '/'; // $args is empty => the path is '/'
} else {
    $filepath = '/'.implode('/', $args).'/'; // $args contains elements of the filepath
}

// Retrieve the file from the Files API.
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'block_cls_user_profile', $filearea, $itemid, $filepath, $filename);
if (!$file) {
    return false; // The file does not exist.
}

// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering. 
// From Moodle 2.3, use send_stored_file instead.
send_stored_file($file, 86400, 0, $forcedownload, $options);
编辑_form.php

$mform->addElement('filemanager', 'config_profile_image', get_string('file'), null,
                array('maxbytes' => $CFG->maxbytes, 'areamaxbytes' => 10485760, 'maxfiles' => 1,
                      'accepted_types' => '*', 'return_types'=> FILE_INTERNAL | FILE_EXTERNAL));

 $i = 1;
if ($draftitemid = file_get_submitted_draft_itemid('config_profile_image')) {
    file_save_draft_area_files($draftitemid, $this->block->context->id, 'block_cls_user_profile', 'cls_img', $i,array('subdirs' => false, 'maxfiles' => 1));
  }
我已经编辑了edit_form.php,现在看起来是这样的:

global $CFG, $mform;

  $i = 0;
  $draftitemid = file_get_submitted_draft_itemid('config_profile_image');

  file_prepare_draft_area($draftitemid, $this->block->context->id, 'block_cls_user_profile', 'cls_img', $i,
                        array('subdirs' => 0, 'maxbytes' => $CFG->maxbytes, 'maxfiles' => 1));

  $entry->config_profile_image = $draftitemid;

  $mform->set_data($entry);

  file_save_draft_area_files($draftitemid, $this->block->context->id, 'block_cls_user_profile', 'cls_img', $i,array('subdirs' => false, 'maxfiles' => 1));
父::set_data($defaults);}

但我现在得到的错误是“调用null上的成员函数set_data()”

多谢各位