Commit 000e2e50 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Modified internal search plugin to obey the API, fixed searchlib to work when the API if obeyed ;-)

parent b4e1881b
......@@ -62,10 +62,53 @@ defined('INTERNAL') || die();
* );
*/
function search_user($query_string, $limit, $offset = 0) {
$prefix = get_config('dbprefix');
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
safe_require('artefact', 'internal');
return call_static_method(generate_class_name('search', $plugin), 'search_user', $query_string, $limit, $offset);
$publicfields = array_keys(ArtefactTypeProfile::get_public_fields());
if (empty($publicfields)) {
$publicfields = array('preferredname');
}
$fieldlist = "('" . join("','", $publicfields) . "')";
$results = call_static_method(generate_class_name('search', $plugin), 'search_user', $query_string, $limit, $offset);
if ($results['count'] > 0) {
$userlist = '('.join(',', array_map(create_function('$u','return $u[\'id\'];'), $results['data'])).')';
$public_fields = get_records_sql_array('
SELECT
u.id, a.artefacttype, a.title
FROM
' . $prefix . 'usr u
LEFT JOIN ' . $prefix . 'artefact a ON u.id=a.owner AND a.artefacttype IN ' . $fieldlist . '
WHERE
u.id IN ' . $userlist . '
ORDER BY u.firstname, u.lastname, u.id, a.artefacttype',
array()
);
$public_fields_byuser = array();
if (!empty($public_fields)) {
foreach ($public_fields as $field) {
$public_fields_byuser[$field->id][$field->artefacttype] = $field->title;
}
}
foreach ($results['data'] as &$result) {
$result['name'] = display_name($result);
if (isset($public_fields_byuser[$result['id']])) {
foreach ($public_fields_byuser[$result['id']] as $field => $value) {
$result[$field] = $value;
}
}
}
}
return $results;
}
/**
......
......@@ -103,9 +103,9 @@ class PluginSearchInternal extends PluginSearch {
);
if ($count > 0) {
$users = get_records_sql_assoc('
$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.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname, u.email
FROM ' . $prefix . 'artefact a
INNER JOIN ' . $prefix .'usr u ON u.id = a.owner
WHERE
......@@ -127,42 +127,10 @@ class PluginSearchInternal extends PluginSearch {
$offset,
$limit);
$userlist = '('.join(',', array_map(create_function('$u','return $u->id;'), $users)).')';
log_debug($userlist);
$data = get_records_sql_array('
SELECT
u.id, a.artefacttype, a.title
FROM
' . $prefix . 'usr u
LEFT JOIN ' . $prefix . 'artefact a ON u.id=a.owner AND a.artefacttype IN ' . $fieldlist . '
WHERE
u.id IN ' . $userlist . '
ORDER BY u.firstname, u.lastname, u.id, a.artefacttype',
array());
log_debug($data);
if (!empty($data)) {
foreach ($users as &$user) {
$user->name = display_name($user);
unset($user->username);
unset($user->institution);
unset($user->firstname);
unset($user->lastname);
unset($user->preferredname);
}
foreach ($data as $rec) {
if (!isset($rec->artefacttype)) {
continue;
}
if ($rec->artefacttype == 'email') {
$users[$rec->id]->email[] = $rec->title;
}
else {
$users[$rec->id]->{$rec->artefacttype} = $rec->title;
}
if ($data) {
foreach ($data as &$item) {
$item = (array)$item;
}
$data = array_values($users);
}
}
else {
......
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