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