]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766
authordongsheng <dongsheng>
Mon, 8 Sep 2008 06:20:24 +0000 (06:20 +0000)
committerdongsheng <dongsheng>
Mon, 8 Sep 2008 06:20:24 +0000 (06:20 +0000)
1. fix boxnet search feature
2. fix bugs in global search

repository/boxnet/repository.class.php
repository/flickr/repository.class.php
repository/lib.php
repository/ws.php

index f8b7c10f39fe5eb89703204e3515d71b83d95af2..2ff416c49982cd575977c4d4583ff21c95b851c3 100755 (executable)
@@ -106,6 +106,28 @@ class repository_boxnet extends repository{
         global $CFG, $SESSION;
         $list = array();
         $ret  = array();
+        if (!empty($search)) {
+            $tree = $this->box->getAccountTree();
+            if (!empty($tree)) {
+                $filenames = $tree['file_name'];
+                $fileids   = $tree['file_id'];
+                $filesizes = $tree['file_size'];
+                $filedates = $tree['file_date'];
+                $fileicon  = $tree['thumbnail'];
+                foreach ($filenames as $n=>$v){
+                    if(strstr($v, $search) !== false) {
+                        $list[] = array('title'=>$v, 
+                                'size'=>$filesizes[$n],
+                                'date'=>$filedates[$n],
+                                'source'=>'http://box.net/api/1.0/download/'
+                                    .$this->options['auth_token'].'/'.$fileids[$n],
+                                'thumbnail'=>$CFG->pixpath.'/f/'.mimeinfo('icon', $v));
+                    }
+                }
+            }
+            $ret['list'] = $list;
+            return $ret;
+        }
         $tree = $this->box->getfiletree($path);
         if(!empty($tree)) {
             // TODO: think about how to search
index 55d7e18f60c7affda5742ac9fc98f2b3f0be38b6..1ec44616569350def07bc4d9bd4f3f65155b7b33 100755 (executable)
@@ -37,7 +37,6 @@ class repository_flickr extends repository{
         global $SESSION;
         $sess_name = 'flickrmail'.$this->id;
         if (empty($SESSION->$sess_name)) {
-            return $sess_name;
             return false;
         } else {
             return true;
@@ -146,14 +145,14 @@ EOD;
             $photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 36, $path);
         }
 
-        $ret = new stdclass;
-        $ret->manage = $photos_url;
-        $ret->list  = array();
-        $ret->pages = $photos['pages'];
-        if(is_int($path) && $path <= $ret->pages) {
-            $ret->page = $path;
+        $ret = array();
+        $ret['manage'] = $photos_url;
+        $ret['list']  = array();
+        $ret['pages'] = $photos['pages'];
+        if(is_int($path) && $path <= $ret['pages']) {
+            $ret['page'] = $path;
         } else {
-            $ret->page = 1;
+            $ret['page'] = 1;
         }
         foreach ($photos['photo'] as $p) {
             if(empty($p['title'])) {
@@ -164,7 +163,7 @@ EOD;
             } else {
                 $format = 'jpg';
             }
-            $ret->list[] =
+            $ret['list'][] =
                 array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), 'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
         }
         if(empty($ret)) {
index d87829f9f4a0de2ae95cb488062814c381774a2c..5822ea07d265ba219071216bdcaaf5d2df0bad90 100644 (file)
@@ -1345,7 +1345,7 @@ function _client(){
                 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>';
+                searchbar.get('element').innerHTML = '<label for="search-input-$suffix">$strsearch: </label><input id="search-input-$suffix" /><button id="search-btn-$suffix">$strsearch</button>';
                 var searchbtn = new YAHOO.util.Element('search-btn-$suffix');
                 searchbtn.callback = {
                     success: function(o) {
@@ -1373,12 +1373,14 @@ function _client(){
                             } else {
                                 _client.viewlist();
                             }
+                            var input_ctl = new YAHOO.util.Element('search-input-$suffix');
+                            input_ctl.get('element').value='';
                         }
                     }
                 }
+                searchbtn.input_ctl = new YAHOO.util.Element('search-input-$suffix');
                 searchbtn.on('click', function(e){
-                    var input_ctl = new YAHOO.util.Element('search-input-$suffix');
-                    var keyword = input_ctl.get('value');
+                    var keyword = this.input_ctl.get('value');
                     var params = [];
                     params['s'] = keyword;
                     params['env']=_client.env;
@@ -1437,9 +1439,10 @@ _client.loading = function(type, name){
     //content.innerHTML = '';
     panel.get('element').appendChild(content);
 }
-_client.rename = function(oldname, url, icon){
+_client.rename = function(oldname, url, icon, repo_id){
     var panel = new YAHOO.util.Element('panel-$suffix');
     var html = '<div class="rename-form">';
+    _client.repositoryid=repo_id;
     html += '<p><img src="'+icon+'" /></p>';
     html += '<p><label for="newname-$suffix">$strsaveas</label>';
     html += '<input type="text" id="newname-$suffix" value="'+oldname+'" /></p>';
@@ -1548,8 +1551,9 @@ _client.viewthumb = function(ds){
             el.title = list[k].title;
             el.value = list[k].source;
             el.icon  = list[k].thumbnail;
+            el.repo_id = list[k].repo_id;
             el.on('click', function(){
-                repository_client_$suffix.rename(this.title, this.value, this.icon);
+                repository_client_$suffix.rename(this.title, this.value, this.icon, this.repo_id);
             });
         }
         count++;
@@ -1563,6 +1567,11 @@ _client.buildtree = function(node, level){
     var tmpNode = new YAHOO.widget.TextNode(info, level, false);
     var tooltip = new YAHOO.widget.Tooltip(tmpNode.labelElId, {
         context:tmpNode.labelElId, text:info.title});
+    if(node.repo_id){
+        tmpNode.repo_id=node.repo_id;
+    }else{
+        tmpNode.repo_id=_client.repositoryid;
+    }
     tmpNode.filename = node.title;
     tmpNode.value  = node.source;
     tmpNode.icon = node.thumbnail;
@@ -1579,7 +1588,7 @@ _client.buildtree = function(node, level){
     } else {
         tmpNode.isLeaf = true;
         tmpNode.onLabelClick = function() {
-            repository_client_$suffix.rename(this.filename, this.value, this.icon);
+            repository_client_$suffix.rename(this.filename, this.value, this.icon, this.repo_id);
         }
     }
 }
index 6e01f39ec8b6180e8fb72ba1da43d92ae3b28bb5..40becc9c9c9e14a6a44c5ef9aefe2af1907769da 100644 (file)
@@ -32,6 +32,9 @@ if (!repository_check_context($ctx_id)) {
     die(json_encode($err));
 }
 
+function attach_repository_id(&$value, $key, $id){
+    $value['repo_id'] = $id;
+}
 // do global search
 if($action=='gsearch'){
     $repos = repository_get_instances(array(get_context_instance_by_id($ctx_id), get_system_context()));
@@ -40,7 +43,8 @@ if($action=='gsearch'){
         if ($repo->global_search()) {
             try {
                 $ret = $repo->get_listing(null, $search);
-                $tmp = array_merge($list, $ret->list);
+                array_walk($ret['list'], 'attach_repository_id', $repo->id);
+                $tmp = array_merge($list, $ret['list']);
                 $list = $tmp;
             } catch (repository_exception $e) {
                 $err = new stdclass;