Commit f8c1aa47 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Fix up searching for communities to allow searching for all communities

parent 70d2e124
......@@ -46,7 +46,7 @@ $offset = param_integer('offset', 0);
switch($type) {
case 'community':
$data = search_community($query, $limit, $offset);
$data = search_community($query, $limit, $offset, true);
foreach ($data['data'] as &$result) {
$result->type = 'community';
}
......
......@@ -141,10 +141,10 @@ function search_group($query_string, $limit, $offset = 0) {
* ),
* );
*/
function search_community($query_string, $limit, $offset = 0) {
function search_community($query_string, $limit, $offset = 0, $all = false) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
return call_static_method(generate_class_name('search', $plugin), 'search_community', $query_string, $limit, $offset);
return call_static_method(generate_class_name('search', $plugin), 'search_community', $query_string, $limit, $offset, $all);
}
?>
......@@ -241,10 +241,10 @@ class PluginSearchInternal extends PluginSearch {
* ),
* );
*/
public static function search_community($query_string, $limit, $offset = 0) {
public static function search_community($query_string, $limit, $offset=0, $all=false) {
global $USER;
if ( is_postgres() ) {
$data = get_records_sql_array("
$sql = "
SELECT
id, name, description, jointype, owner, ctime, mtime
FROM
......@@ -252,18 +252,20 @@ class PluginSearchInternal extends PluginSearch {
WHERE (
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
) AND (
)";
$values = array($query_string, $query_string);
if (!$all) {
$sql .= "AND (
owner = ? OR id IN (
SELECT community FROM " . get_config('dbprefix') . "community_member WHERE member = ?
)
)
",
array($query_string, $query_string, $USER->get('id'), $USER->get('id')),
$offset,
$limit
);
)";
$values[] = $USER->get('id');
$values[] = $USER->get('id');
}
$data = get_records_sql_array($sql, $values, $offset, $limit);
$count = get_field_sql("
$sql = "
SELECT
COUNT(*)
FROM
......@@ -271,14 +273,16 @@ class PluginSearchInternal extends PluginSearch {
WHERE (
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
) AND (
owner = ? OR id IN (
SELECT community FROM " . get_config('dbprefix') . "community_member WHERE member = ?
)";
if (!$all) {
$sql .= "AND (
owner = ? OR id IN (
SELECT community FROM " . get_config('dbprefix') . "community_member WHERE member = ?
)
)
)
",
array($query_string, $query_string, $USER->get('id'), $USER->get('id'))
);
";
}
$count = get_field_sql($sql, $values);
}
// TODO
// else if ( is_mysql() ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment