mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
REPOSITORY/MDL-13766
pass mimetype and return value type to file picker to filter repository instances
This commit is contained in:
parent
c977816479
commit
b318bb6db2
@ -92,7 +92,6 @@ $output .= <<<EOF
|
||||
};
|
||||
}
|
||||
function moodlefilemanager(field_name, url, type, win) {
|
||||
//alert(id2suffix[tinyMCE.selectedInstance.editorId]);
|
||||
var suffix = id2suffix[tinyMCE.selectedInstance.editorId];
|
||||
document.body.className += ' yui-skin-sam';
|
||||
var picker = document.createElement('DIV');
|
||||
@ -100,7 +99,7 @@ $output .= <<<EOF
|
||||
picker.id = 'file-picker-'+suffix;
|
||||
document.body.appendChild(picker);
|
||||
var el = win.document.getElementById(field_name);
|
||||
eval('openpicker_'+suffix+'({"env":"editor","target":el})');
|
||||
eval('openpicker_'+suffix+'({"env":"editor","target":el, "mimetype":type})');
|
||||
}
|
||||
EOF;
|
||||
|
||||
|
@ -15,7 +15,9 @@ require_once(dirname(dirname(dirname(__FILE__))) . '/repository/lib.php');
|
||||
class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
var $_helpbutton='';
|
||||
|
||||
function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null) {
|
||||
function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $filetypes = '*', $returnvalue = '*') {
|
||||
$this->filetypes = $filetypes;
|
||||
$this->returnvalue = $returnvalue;
|
||||
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
}
|
||||
|
||||
@ -70,7 +72,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
}
|
||||
$repository_info = repository_get_client($context);
|
||||
$repository_info = repository_get_client($context, $this->filetypes, $this->returnvalue);
|
||||
$suffix = $repository_info['suffix'];
|
||||
|
||||
$id = $this->_attributes['id'];
|
||||
|
@ -5119,7 +5119,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
|
||||
} else {
|
||||
$ctx = $COURSE->context;
|
||||
}
|
||||
$ret = repository_get_client($ctx);
|
||||
$ret = repository_get_client($ctx, null, true, null, array('image', 'media'), '*');
|
||||
$str .= $ret['css'].$ret['js'];
|
||||
$suffix = $ret['suffix'];
|
||||
$str .= '<div class="textareaicons">';
|
||||
|
@ -11,7 +11,7 @@
|
||||
* @param object $context the context
|
||||
* @return array
|
||||
*/
|
||||
function repository_get_client($context) {
|
||||
function repository_get_client($context, $filetypes = '*', $returnvalue = '*') {
|
||||
global $CFG, $USER;
|
||||
$suffix = uniqid();
|
||||
$sesskey = sesskey();
|
||||
@ -966,7 +966,7 @@ return _client;
|
||||
EOD;
|
||||
|
||||
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$repos = repository_get_instances(array($user_context, $context, get_system_context()));
|
||||
$repos = repository_get_instances(array($user_context, $context, get_system_context()), null, true, null, $filetypes, $returnvalue);
|
||||
foreach ($repos as $repo) {
|
||||
$info = $repo->ajax_info();
|
||||
$js .= "\r\n";
|
||||
@ -980,11 +980,12 @@ function openpicker_$suffix(params) {
|
||||
if(!repository_client_$suffix.instance) {
|
||||
repository_client_$suffix.env = params.env;
|
||||
repository_client_$suffix.target = params.target;
|
||||
if(params.type) {
|
||||
repository_client_$suffix.filetype = params.filetype;
|
||||
if(params.mimetype) {
|
||||
repository_client_$suffix.mimetype = params.mimetype;
|
||||
} else {
|
||||
repository_client_$suffix.filetype = 'all';
|
||||
repository_client_$suffix.mimetype = '*';
|
||||
}
|
||||
alert(repository_client_$suffix.mimetype);
|
||||
repository_client_$suffix.instance = new repository_client_$suffix();
|
||||
repository_client_$suffix.instance.create_picker();
|
||||
if(params.callback) {
|
||||
|
@ -663,6 +663,26 @@ abstract class repository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* what kind of files will be in this repository?
|
||||
* @return array return '*' means this repository support any files, otherwise
|
||||
* return mimetypes of files, it can be an array
|
||||
*/
|
||||
public function supported_mimetype() {
|
||||
// return array('text/plain', 'image/gif');
|
||||
return '*';
|
||||
}
|
||||
|
||||
/**
|
||||
* does it return a file url or a item_id
|
||||
* @return string
|
||||
*/
|
||||
public function supported_return_value() {
|
||||
// return 'link';
|
||||
// return 'ref_id';
|
||||
return '*';
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide repository instance information for Ajax
|
||||
* @global object $CFG
|
||||
@ -1088,9 +1108,11 @@ function repository_get_editable_types($context = null) {
|
||||
* @param boolean $onlyvisible if visible == true, return visible instances only,
|
||||
* otherwise, return all instances
|
||||
* @param string $type a type name to retrieve
|
||||
* @param string $filetypes supported file types
|
||||
* @param string $returnvalue supportted returned value
|
||||
* @return array repository instances
|
||||
*/
|
||||
function repository_get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null) {
|
||||
function repository_get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null, $filetypes = '*', $returnvalue = '*') {
|
||||
global $DB, $CFG, $USER;
|
||||
|
||||
$params = array();
|
||||
@ -1140,6 +1162,24 @@ function repository_get_instances($contexts=array(), $userid = null, $onlyvisibl
|
||||
$classname = 'repository_' . $repo->repositorytype;//
|
||||
|
||||
$repository = new $classname($repo->id, $repo->contextid, $options, $repo->readonly);
|
||||
if ($filetypes !== '*' and $repository->supported_mimetype() !== '*') {
|
||||
$mimetypes = $repository->supported_mimetype();
|
||||
$is_supported = false;
|
||||
foreach ($mimetypes as $type) {
|
||||
if (in_array($type, $filetypes)) {
|
||||
$is_supported = true;
|
||||
}
|
||||
}
|
||||
if (!$is_supported) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($returnvalue !== '*' and $repository->supported_return_value() !== '*') {
|
||||
$tmp = $repository->supported_return_value();
|
||||
if ($tmp == $returnvalue) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!$onlyvisible || ($repository->is_visible() && !$repository->disabled)) {
|
||||
$ret[] = $repository;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user