pass mimetype and return value type to file picker to filter repository instances
};
}
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');
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;
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);
}
} 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'];
} 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">';
* @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();
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";
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) {
}
}
+ /**
+ * 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
* @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();
$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;
}