mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
"MDL-13766, use file api to move files"
This commit is contained in:
parent
476c00cba5
commit
d8eb6e180c
@ -197,7 +197,8 @@ $output .= <<<EOF
|
||||
tinyMCE.execCommand('mceToggleEditor',false,id);
|
||||
}
|
||||
function mce_moodlefilemanager(field_name, url, type, win) {
|
||||
openpicker({'env':'editor'});
|
||||
var el = win.document.getElementById(field_name);
|
||||
openpicker({'env':'editor','target':el});
|
||||
}
|
||||
function mce_saveOnSubmit(id) {
|
||||
var prevOnSubmit = document.getElementById(id).form.onsubmit;
|
||||
|
@ -45,7 +45,18 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_button
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
$ret = get_repository_client();
|
||||
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' onclick=\'openpicker({"env":"form"})\' />'.$ret['html'].$ret['js'];
|
||||
$str = $this->_getTabs();
|
||||
$str .= '<input type="hidden" value="" name="repo_attachment" id="repo_value" />';
|
||||
$str .= <<<EOD
|
||||
<script type="text/javascript">
|
||||
function callpicker(){
|
||||
var el=document.getElementById('repo_value');
|
||||
openpicker({"env":"form", 'target':el})
|
||||
}
|
||||
</script>
|
||||
EOD;
|
||||
$str .= '<input' . $this->_getAttrString($this->_attributes) . ' onclick=\'callpicker()\' />'.$ret['html'].$ret['js'];
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,6 +331,36 @@ function repository_get_plugins(){
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function move_to_filepool($path, $name) {
|
||||
global $DB, $CFG, $USER;
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$entry = new object();
|
||||
$entry->filearea = 'user_draft';
|
||||
$entry->contextid = $context->id;
|
||||
$entry->filename = $name;
|
||||
$entry->filepath = '/';
|
||||
$entry->timecreated = time();
|
||||
$entry->timemodified = time();
|
||||
$entry->itemid = $USER->id;
|
||||
$entry->mimetype = mimeinfo('type', $path);
|
||||
$entry->userid = $USER->id;
|
||||
$fs = get_file_storage();
|
||||
$browser = get_file_browser();
|
||||
if ($file = $fs->create_file_from_pathname($entry, $path)) {
|
||||
$id = json_encode($file->get_itemid());
|
||||
$ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
// TODO
|
||||
// get_params should include id value, talk to Petr.
|
||||
$params = $ret->get_params();
|
||||
$params['id'] = 88;
|
||||
return array('url'=>$ret->get_url(),'id'=>$params['id']);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_repository_client(){
|
||||
global $CFG;
|
||||
$strsubmit = get_string('submit', 'repository');
|
||||
@ -632,7 +662,7 @@ function get_repository_client(){
|
||||
var file = document.getElementById('fileurl').value;
|
||||
_client.loading();
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
'$CFG->wwwroot/repository/ws.php?id='+_client.repositoryid+'&action=download',
|
||||
'$CFG->wwwroot/repository/ws.php?repo_id='+_client.repositoryid+'&action=download',
|
||||
_client.dlfile, _client.postdata({'env':_client.env, 'file':file, 'title':title}));
|
||||
}
|
||||
_client.login = function(){
|
||||
@ -653,6 +683,10 @@ function get_repository_client(){
|
||||
'$CFG->wwwroot/repository/ws.php', _client.callback,
|
||||
_client.postdata(obj));
|
||||
}
|
||||
_client.end = function(str){
|
||||
_client.target.value = str;
|
||||
_client.viewfiles();
|
||||
}
|
||||
_client.callback = {
|
||||
success: function(o) {
|
||||
var panel = new YAHOO.util.Element('panel');
|
||||
@ -690,7 +724,8 @@ function get_repository_client(){
|
||||
return;
|
||||
}
|
||||
var html = '<h1>Download Successfully!</h1>';
|
||||
html += '<a href="###" onclick="repository_client.viewfiles()">Back</a>';
|
||||
//html += '<a href="###" onclick="repository_client.viewfiles()">Back</a>';
|
||||
html += '<a href="###" onclick="repository_client.end(\''+ret+'\')">Add!</a>';
|
||||
panel.get('element').innerHTML = html;
|
||||
}
|
||||
}
|
||||
@ -699,7 +734,7 @@ function get_repository_client(){
|
||||
_client.viewbar.set('disabled', false);
|
||||
_client.loading();
|
||||
_client.repositoryid = id;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&p='+path+'&reset='+reset+'&env='+_client.env, _client.callback);
|
||||
var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?repo_id='+id+'&p='+path+'&reset='+reset+'&env='+_client.env, _client.callback);
|
||||
}
|
||||
_client.search = function(id){
|
||||
var data = window.prompt("What are you searching for?");
|
||||
@ -709,7 +744,7 @@ function get_repository_client(){
|
||||
}
|
||||
_client.viewbar.set('disabled', false);
|
||||
_client.loading();
|
||||
var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&s='+data+'&env='+_client.env, _client.callback);
|
||||
var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?repo_id='+id+'&s='+data+'&env='+_client.env, _client.callback);
|
||||
}
|
||||
return _client;
|
||||
})();
|
||||
@ -725,6 +760,7 @@ EOD;
|
||||
function openpicker(obj) {
|
||||
if(!repository_client.instance) {
|
||||
repository_client.env = obj.env;
|
||||
repository_client.target = obj.target;
|
||||
repository_client.instance = new repository_client();
|
||||
repository_client.instance.create_picker();
|
||||
} else {
|
||||
|
@ -59,31 +59,14 @@ if($action == 'list') {
|
||||
}
|
||||
|
||||
} elseif($action == 'download') {
|
||||
$ret = $repo->get_file($file, $title);
|
||||
// TODO
|
||||
// Ask Petr how to use FILE_API here
|
||||
$path = $repo->get_file($file, $title);
|
||||
try {
|
||||
$pathname = $ret;
|
||||
$entry = new object();
|
||||
$entry->contextid = SITEID;
|
||||
$entry->filearea = 'repository';
|
||||
$entry->filepath = '/';
|
||||
$entry->filename = $title;
|
||||
$entry->timecreated = time();
|
||||
$entry->timemodified = time();
|
||||
$entry->itemid = $USER->id;
|
||||
$entry->mimetype = mimeinfo('type', $pathname);
|
||||
$entry->userid = $USER->id;
|
||||
$fs = get_file_storage();
|
||||
if ($file = $fs->create_file_from_pathname($entry, $pathname)) {
|
||||
if($env == 'form'){
|
||||
// return reference id
|
||||
echo json_encode($file->get_itemid());
|
||||
} elseif($env == 'editor') {
|
||||
// return url
|
||||
// echo json_encode($file->get_content_file_location());
|
||||
} else {
|
||||
}
|
||||
$info = move_to_filepool($path, $title);
|
||||
if($env == 'form'){
|
||||
echo json_encode($info['id']);
|
||||
} elseif($env == 'editor') {
|
||||
echo json_encode($info['url']);
|
||||
} else {
|
||||
}
|
||||
} catch (repository_exception $e){
|
||||
$err = new stdclass;
|
||||
|
Loading…
x
Reference in New Issue
Block a user