]> git.mjollnir.org Git - moodle.git/commitdiff
REPOSITORY/MDL-13766
authordongsheng <dongsheng>
Wed, 26 Nov 2008 03:26:33 +0000 (03:26 +0000)
committerdongsheng <dongsheng>
Wed, 26 Nov 2008 03:26:33 +0000 (03:26 +0000)
pass mimetype and return value type to file picker to filter repository instances

lib/editor/tinymce/tinymce.js.php
lib/form/filepicker.php
lib/weblib.php
repository/javascript.php
repository/lib.php

index 8c03ad37449dfe70498b2732bc2c9924107600f8..61fdaf808ba519da87c9f6d79f0e5f35acd402a1 100644 (file)
@@ -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;
 
index 1efc69dffb7e164a1ffaaf2e4ce123b032e1223b..d270c69872af0885e7f835629843d6cada6760e6 100644 (file)
@@ -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'];
index e87756f7777dd74550f4f3e113811b1649c530b7..80954a606f9b45f4260c0bb8c21792765b308921 100644 (file)
@@ -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">';
index c5fea04a98d573326cd787890b7456c290ae2fb6..7fd7452b6c845546b2a1f5452ab854edf2e34af3 100644 (file)
@@ -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) {
index 3d5abb91af4f0738ab5b9714e200df2597271781..ba7be14011967cbc0eed021ca9f7f6aa66bcd899 100644 (file)
@@ -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;
         }