Commit 7ff452e4 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Do the right thing for empty results list

parent 10d6a269
......@@ -75,6 +75,20 @@ class PluginSearchInternal extends PluginSearch {
if ( is_postgres() ) {
if (!empty($publicfields)) {
$fieldlist = "('" . join("','", $publicfields) . "')";
$count = get_field_sql('
SELECT
COUNT(DISTINCT owner)
FROM
' . $prefix . 'artefact
WHERE
owner <> 0
AND artefacttype IN ' . $fieldlist . "
AND ( title ILIKE '%' || ? || '%')",
array($query_string));
if ($count > 0) {
$users = get_records_sql_assoc('
SELECT DISTINCT ON (u.preferredname, u.lastname, u.firstname, u.id)
u.id, u.preferredname, u.lastname, u.firstname, u.username, u.institution
......@@ -85,8 +99,11 @@ class PluginSearchInternal extends PluginSearch {
AND a.artefacttype IN ' . $fieldlist . "
AND (a.title ILIKE '%' || ? || '%')
ORDER BY u.preferredname, u.lastname, u.firstname, u.id",
array($query_string), $offset, $limit);
$userlist = '(' . join(',', array_map(create_function('$u','return $u->id;'), $users)) . ')';
array($query_string),
$offset,
$limit);
$userlist = '('.join(',', array_map(create_function('$u','return $u->id;'), $users)).')';
$data = get_records_sql_array('
SELECT
......@@ -109,22 +126,13 @@ class PluginSearchInternal extends PluginSearch {
$users[$rec->id]->{$rec->artefacttype} = $rec->title;
}
}
}
$count = get_field_sql('
SELECT
COUNT(DISTINCT owner)
FROM
' . $prefix . 'artefact
WHERE
owner <> 0
AND artefacttype IN ' . $fieldlist . "
AND ( title ILIKE '%' || ? || '%')",
array($query_string)
);
$data = array_values($users);
}
}
else {
$data = false;
}
}
else {
$data = false;
$count = 0;
......
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