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

Do the right thing for empty results list

parent 10d6a269
...@@ -75,41 +75,6 @@ class PluginSearchInternal extends PluginSearch { ...@@ -75,41 +75,6 @@ class PluginSearchInternal extends PluginSearch {
if ( is_postgres() ) { if ( is_postgres() ) {
if (!empty($publicfields)) { if (!empty($publicfields)) {
$fieldlist = "('" . join("','", $publicfields) . "')"; $fieldlist = "('" . join("','", $publicfields) . "')";
$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
FROM ' . $prefix . 'artefact a
INNER JOIN ' . $prefix .'usr u ON u.id = a.owner
WHERE
u.id <> 0
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)) . ')';
$data = get_records_sql_array('
SELECT
u.id, a.artefacttype, a.title
FROM
' . $prefix . 'artefact a
INNER JOIN ' . $prefix . 'usr u ON u.id = a.owner
WHERE
a.artefacttype IN ' . $fieldlist . '
AND u.id IN ' . $userlist . '
ORDER BY u.preferredname, u.lastname, u.firstname, u.id, a.artefacttype',
array());
if (!empty($data)) {
foreach ($data as $rec) {
if ($rec->artefacttype == 'email') {
$users[$rec->id]->email[] = $rec->title;
}
else {
$users[$rec->id]->{$rec->artefacttype} = $rec->title;
}
}
}
$count = get_field_sql(' $count = get_field_sql('
SELECT SELECT
...@@ -120,10 +85,53 @@ class PluginSearchInternal extends PluginSearch { ...@@ -120,10 +85,53 @@ class PluginSearchInternal extends PluginSearch {
owner <> 0 owner <> 0
AND artefacttype IN ' . $fieldlist . " AND artefacttype IN ' . $fieldlist . "
AND ( title ILIKE '%' || ? || '%')", AND ( title ILIKE '%' || ? || '%')",
array($query_string) array($query_string));
);
if ($count > 0) {
$data = array_values($users);
$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
FROM ' . $prefix . 'artefact a
INNER JOIN ' . $prefix .'usr u ON u.id = a.owner
WHERE
u.id <> 0
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)).')';
$data = get_records_sql_array('
SELECT
u.id, a.artefacttype, a.title
FROM
' . $prefix . 'artefact a
INNER JOIN ' . $prefix . 'usr u ON u.id = a.owner
WHERE
a.artefacttype IN ' . $fieldlist . '
AND u.id IN ' . $userlist . '
ORDER BY u.preferredname, u.lastname, u.firstname, u.id, a.artefacttype',
array());
if (!empty($data)) {
foreach ($data as $rec) {
if ($rec->artefacttype == 'email') {
$users[$rec->id]->email[] = $rec->title;
}
else {
$users[$rec->id]->{$rec->artefacttype} = $rec->title;
}
}
$data = array_values($users);
}
}
else {
$data = false;
}
} }
else { else {
$data = false; $data = false;
......
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