Commit 285244d0 authored by Geoff Cant's avatar Geoff Cant Committed by Geoff Cant
Browse files

Factoring out the postgres specific bits of search_user into a separate function.

parent 9edab31c
......@@ -76,14 +76,45 @@ class PluginSearchInternal extends PluginSearch {
}
$prefix = get_config('dbprefix');
if ( is_postgres() ) {
$fieldlist = "('" . join("','", $publicfields) . "')";
return search_user_pg($query_string, $limit, $offset, $prefix, $publicfields);
} else {
throw new SQLException('search_user() is not implemented for your database engine (' . get_config('dbtype') . ')');
}
}
$count = get_field_sql('
SELECT
COUNT(DISTINCT u.id)
FROM
' . $prefix . 'usr u
LEFT JOIN ' . $prefix . 'artefact a ON u.id=a.owner
public static function search_user_pg($query_string, $limit, $offset, $prefix, $publicfields) {
$fieldlist = "('" . join("','", $publicfields) . "')";
$count = get_field_sql('
SELECT
COUNT(DISTINCT u.id)
FROM
' . $prefix . 'usr u
LEFT JOIN ' . $prefix . 'artefact a ON u.id=a.owner
WHERE
u.id <> 0 AND u.active = 1
AND ((
u.preferredname IS NULL
AND (
u.firstname ILIKE \'%\' || ? || \'%\'
OR u.lastname ILIKE \'%\' || ? || \'%\'
)
)
OR (
a.artefacttype IN ' . $fieldlist . '
AND ( a.title ILIKE \'%\' || ? || \'%\')
)
)
',
array($query_string, $query_string, $query_string)
);
if ($count > 0) {
$data = get_records_sql_array('
SELECT DISTINCT ON (u.firstname, u.lastname, u.id)
u.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname, u.email, u.staff
FROM ' . $prefix . 'artefact a
INNER JOIN ' . $prefix .'usr u ON u.id = a.owner
WHERE
u.id <> 0 AND u.active = 1
AND ((
......@@ -98,50 +129,19 @@ class PluginSearchInternal extends PluginSearch {
AND ( a.title ILIKE \'%\' || ? || \'%\')
)
)
',
array($query_string, $query_string, $query_string)
);
ORDER BY u.firstname, u.lastname, u.id',
array($query_string, $query_string, $query_string),
$offset,
$limit);
if ($count > 0) {
$data = get_records_sql_array('
SELECT DISTINCT ON (u.firstname, u.lastname, u.id)
u.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname, u.email, u.staff
FROM ' . $prefix . 'artefact a
INNER JOIN ' . $prefix .'usr u ON u.id = a.owner
WHERE
u.id <> 0 AND u.active = 1
AND ((
u.preferredname IS NULL
AND (
u.firstname ILIKE \'%\' || ? || \'%\'
OR u.lastname ILIKE \'%\' || ? || \'%\'
)
)
OR (
a.artefacttype IN ' . $fieldlist . '
AND ( a.title ILIKE \'%\' || ? || \'%\')
)
)
ORDER BY u.firstname, u.lastname, u.id',
array($query_string, $query_string, $query_string),
$offset,
$limit);
if ($data) {
foreach ($data as &$item) {
$item = (array)$item;
}
if ($data) {
foreach ($data as &$item) {
$item = (array)$item;
}
}
else {
$data = false;
}
}
// TODO
// else if ( is_mysql() ) {
// }
else {
throw new SQLException('search_user() is not implemented for your database engine (' . get_config('dbtype') . ')');
$data = false;
}
return array(
......
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