]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766, global search enabled.
authordongsheng <dongsheng>
Mon, 8 Sep 2008 05:38:13 +0000 (05:38 +0000)
committerdongsheng <dongsheng>
Mon, 8 Sep 2008 05:38:13 +0000 (05:38 +0000)
repository/boxnet/repository.class.php
repository/flickr/repository.class.php
repository/lib.php
repository/ws.php

index 48e6aab842593802a579b00e7de08270d5d99303..f8b7c10f39fe5eb89703204e3515d71b83d95af2 100755 (executable)
@@ -32,6 +32,16 @@ class repository_boxnet extends repository{
         return $options;
     }
 
+    public function global_search(){
+        global $SESSION;
+        $sess_name = 'box_token'.$this->id;
+        if (empty($SESSION->$sess_name)) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
     public function __construct($repositoryid, $context = SITEID, $options = array()){
         global $SESSION, $action;
         $options['username']   = optional_param('boxusername', '', PARAM_RAW);
index f461c33829499164e4db5aeeb6d404e306bd6e5f..55d7e18f60c7affda5742ac9fc98f2b3f0be38b6 100755 (executable)
@@ -33,6 +33,17 @@ class repository_flickr extends repository{
         return $options;
     }
 
+    public function global_search(){
+        global $SESSION;
+        $sess_name = 'flickrmail'.$this->id;
+        if (empty($SESSION->$sess_name)) {
+            return $sess_name;
+            return false;
+        } else {
+            return true;
+        }
+    }
+
     public function __construct($repositoryid, $context = SITEID, $options = array()){
         global $SESSION, $action, $CFG;
         $options['page']    = optional_param('p', 1, PARAM_INT);
index 350d6715789456ee4645bd32a9ef125bc7e31df5..d87829f9f4a0de2ae95cb488062814c381774a2c 100644 (file)
@@ -823,6 +823,14 @@ abstract class repository {
      */
     abstract public function print_search();
 
+    /**
+     * is it possible to do glboal search?
+     * @return boolean
+     */
+    public function global_search(){
+        return false;
+    }
+
     /**
      * Defines operations that happen occasionally on cron
      * @return <type>
@@ -1195,6 +1203,8 @@ p.upload a:hover {background: grey;color:white}
 #file-picker-$suffix strong{background:#FFFFCC}
 #file-picker-$suffix a{color: #336699}
 #file-picker-$suffix a:hover{background:#003366;color:white}
+#repo-viewbar-$suffix{width:300px;float:left}
+#search-div-$suffix{float:right}
 </style>
 <style type="text/css">
 @import "$CFG->httpswwwroot/lib/yui/resize/assets/skins/sam/resize.css";
@@ -1256,7 +1266,7 @@ function _client(){
                     height: 480, width: 630,
                     units: [
                         {position: 'top', height: 32, resize: false,
-                        body:'<div class="yui-buttongroup" id="repo-viewbar-$suffix"></div>', gutter: '2'},
+                        body:'<div class="yui-buttongroup" id="repo-viewbar-$suffix"></div><div id="search-div-$suffix"></div>', gutter: '2'},
                         {position: 'left', width: 200, resize: true,
                         body:'<ul class="repo-list" id="repo-list-$suffix"></ul>', gutter: '0 5 0 2', minWidth: 150, maxWidth: 300 },
                         {position: 'center', body: '<div id="panel-$suffix"></div>',
@@ -1334,6 +1344,51 @@ function _client(){
                 li.appendChild(opt);
                 this.appendChild(li);
                 repo = null;
+                var searchbar = new YAHOO.util.Element('search-div-$suffix');
+                searchbar.get('element').innerHTML = '<label for="search-input-$suffix">Search: </label><input id="search-input-$suffix" /><button id="search-btn-$suffix">Go!</button>';
+                var searchbtn = new YAHOO.util.Element('search-btn-$suffix');
+                searchbtn.callback = {
+                    success: function(o) {
+                        var panel = new YAHOO.util.Element('panel-$suffix');
+                        try {
+                            if(!o.responseText){
+                                var panel = new YAHOO.util.Element('panel-$suffix');
+                                panel.get('element').innerHTML = 'no';
+                                return;
+                            }
+                            var json = YAHOO.lang.JSON.parse(o.responseText);
+                        } catch(e) {
+                            alert('$strinvalidjson - '+o.responseText);
+                        }
+                        _client.ds = {};
+                        if(!json.list || json.list.length<1){
+                            var panel = new YAHOO.util.Element('panel-$suffix');
+                            panel.get('element').innerHTML = 'no';
+                            return;
+                        }
+                        _client.ds.list = json.list;
+                        if(_client.ds.list) {
+                            if(_client.viewmode) {
+                                _client.viewthumb();
+                            } else {
+                                _client.viewlist();
+                            }
+                        }
+                    }
+                }
+                searchbtn.on('click', function(e){
+                    var input_ctl = new YAHOO.util.Element('search-input-$suffix');
+                    var keyword = input_ctl.get('value');
+                    var params = [];
+                    params['s'] = keyword;
+                    params['env']=_client.env;
+                    params['action']='gsearch';
+                    params['sesskey']='$sesskey';
+                    params['ctx_id']=$context->id;
+                    _client.loading('load');
+                    var trans = YAHOO.util.Connect.asyncRequest('POST',
+                        '$CFG->httpswwwroot/repository/ws.php?action=gsearch', this.callback, _client.postdata(params));
+                });
             }
             });
     }
index 200d11a51c9b07a17a85cde4283fedbe93d716e6..6e01f39ec8b6180e8fb72ba1da43d92ae3b28bb5 100644 (file)
@@ -26,6 +26,32 @@ $repo_id = optional_param('repo_id', 1, PARAM_INT);
 $ctx_id  = optional_param('ctx_id', SITEID, PARAM_INT);
 $userid  = $USER->id;
 
+if (!repository_check_context($ctx_id)) {
+    $err = new stdclass;
+    $err->e = get_string('nopermissiontoaccess', 'repository');
+    die(json_encode($err));
+}
+
+// do global search
+if($action=='gsearch'){
+    $repos = repository_get_instances(array(get_context_instance_by_id($ctx_id), get_system_context()));
+    $list = array();
+    foreach($repos as $repo){
+        if ($repo->global_search()) {
+            try {
+                $ret = $repo->get_listing(null, $search);
+                $tmp = array_merge($list, $ret->list);
+                $list = $tmp;
+            } catch (repository_exception $e) {
+                $err = new stdclass;
+                $err->e = $e->getMessage();
+                die(json_encode($err));
+            }
+        }
+    }
+    die(json_encode(array('list'=>$list)));
+}
+
 $sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i WHERE i.id='.$repo_id.' AND i.typeid=r.id';
 if(!$repository = $DB->get_record_sql($sql)) {
     $err = new stdclass;
@@ -35,12 +61,6 @@ if(!$repository = $DB->get_record_sql($sql)) {
     $type = $repository->type;
 }
 
-if (!repository_check_context($ctx_id)) {
-    $err = new stdclass;
-    $err->e = get_string('nopermissiontoaccess', 'repository');
-    die(json_encode($err));
-}
-
 if(file_exists($CFG->dirroot.'/repository/'.
     $type.'/repository.class.php'))
 {