mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 11:46:19 +01:00
MDL-13766, global search enabled.
This commit is contained in:
parent
6fe8b02294
commit
455860cecb
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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'))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user