2016-03-24 12 views
0

現在、私はインターンシップを行っています。ファイルマネージャによって与えられたビデオから、プレイリストを表示するためのアクティビティモジュールを作ろうとしました。私はデータベースにビデオを送ることに成功しましたが、自分のモジュールを編集したいときは、ファイルマネージャーにビデオを表示しません。ムードルでファイルマネージャを編集するときにファイルを取り出す方法

私はMoodleのドキュメントに関するfile APIを読んで、私は(ドラフト領域にロードし、既存のファイル)次のコードを使用することにしました

if (empty($entry->id)) { 
$entry = new stdClass; 
$entry->id = null; 
} 

$draftitemid = file_get_submitted_draft_itemid('attachments'); 
file_prepare_draft_area($draftitemid, $context->id, 'mod_glossary','attachment', $entry->id,array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 50)); 
$entry->attachments = $draftitemid; 
$mform->set_data($entry); 

だから私は私のmod_form.phpに次の行を入れて:

$filemanager_options = array(); 
    $filemanager_options['accepted_types'] = '*'; 
    $filemanager_options['maxbytes'] = 0; 
    $filemanager_options['maxfiles'] = -1; 
    $filemanager_options['mainfile'] = true; 

     $mform->addElement('filemanager', 'files', get_string('selectfiles'), null, $filemanager_options); 



if (empty($entry->id)) { 
    $entry = new stdClass; 
    $entry->id = null; 
} 

$draftitemid = file_get_submitted_draft_itemid('mymanager'); 


file_prepare_draft_area($draftitemid, $this->context->id, 'mod_playlist', 'content', 0, 
         array('subdirs'=>true)); 

$entry->attachments = $draftitemid; 

$mform->set_data($entry); 

問題は、ファイルマネージャは空のままであるということです、そしてライン「$ mform-> set_data($エントリー);」のページが(空白)がクラッシュすることができます。

答えて

0

ここにファイルをアップロードするためのテンプレートがあります。ローカル/ myplugin/upload.php

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); 
require_once(dirname(__FILE__) . '/upload_form.php'); 

require_login(); 

$context = context_system::instance(); 

require_capability('local/myplugin:upload', $context); 

$pageurl = new moodle_url('/local/myplugin/upload.php'); 
$heading = get_string('myupload', 'local_myplugin'); 
$PAGE->set_context($context); 
$PAGE->set_heading(format_string($heading)); 
$PAGE->set_title(format_string($heading)); 
$PAGE->set_url('/local/myplugin/upload.php'); 

echo $OUTPUT->header(); 
echo $OUTPUT->heading($heading); 

$fileoptions = array(
     'maxbytes' => 0, 
     'maxfiles' => '1', 
     'subdirs' => 0, 
     'context' => context_system::instance() 
); 

$data = new stdClass(); 

$data = file_prepare_standard_filemanager($data, 'myfiles', 
     $fileoptions, context_system::instance(), 'local_myplugin', 'myfiles', 0); // 0 is the item id. 

$mform = new upload_form(
    null, 
    array(
     'fileoptions' => $fileoptions, 
    ) 
); 

if ($formdata = $mform->get_data()) { 
    // Save the file. 
    $data = file_postupdate_standard_filemanager($data, 'myfiles', 
      $fileoptions, context_system::instance(), 'local_myplugin', 'myfiles', 0); 
} else { 
    // Display the form. 
    $mform->set_data($data); 
    $mform->display(); 
} 

echo $OUTPUT->footer(); 

そして、ローカル/ myplugin/upload_form.php

defined('MOODLE_INTERNAL') || die; 

require_once($CFG->libdir . '/formslib.php'); 

class upload_form extends moodleform { 

    public function definition() { 
     $mform =& $this->_form; 

     $fileoptions = $this->_customdata['fileoptions']; 

     $mform->addElement('filemanager', 'myfiles_filemanager', 
       get_string('myfiles', 'local_myplugin'), null, $fileoptions); 

     $this->add_action_buttons(false, get_string('save', 'local_myplugin')); 

    } 
} 

にあなたはまた、/local/myplugin/lib.php

でこれが必要になります
function local_myplugin_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { 

    if ($context->contextlevel != CONTEXT_SYSTEM) { 
     send_file_not_found(); 
    } 

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

    send_stored_file($file); 
} 
+0

ありがとう、私が知る必要があったことありがとうございました! :) –

関連する問題