Commit 2e8ff45a authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show public profile fields in user search results

parent 86ee1f68
......@@ -47,37 +47,16 @@ $offset = param_integer('offset', 0);
switch($type) {
case 'community':
$data = search_community($query, $limit, $offset, true);
foreach ($data['data'] as &$result) {
$result->type = 'community';
}
log_debug($data);
$data['type'] = 'community';
break;
default:
$data = search_user($query, $limit, $offset);
if ($data['data']) {
foreach ($data['data'] as &$result) {
$result->name = display_name($result);
$result->type = 'user';
/* if (!$USER->get('admin')) {
unset($result->firstname);
unset($result->lastname);
unset($result->preferredname);
unset($result->email);
unset($result->institution);
unset($result->username);
} */
}
}
safe_require('artefact', 'internal');
$data['userfields'] = array_keys(ArtefactTypeProfile::get_public_fields());
$data['type'] = 'user';
break;
}
log_debug($data);
json_headers();
$data['error'] = false;
$data['message'] = '';
......
......@@ -39,19 +39,35 @@ $javascript = <<<EOF
var results = new TableRenderer(
'searchresults',
'{$wwwroot}json/search.php',
[
function(r) {
if ( r.type == 'community' ) {
return TD(null,A({'href':'contacts/communities/view.php?id=' + r.id},r.name));
}
return TD(null,A({'href':'user/view.php?id=' + r.id},r.name));
},
]
[]
);
results.statevars.push('query');
results.statevars.push('type');
results.emptycontent = '{$noresults}';
results.rowfunction = function(r,n,d) {
if ( d.type == 'community' ) {
return TR({'class':'r'+(n%2)},
TD(null,A({'href':'contacts/communities/view.php?id=' + r.id},r.name)));
}
var row = TR({'class':'r'+(n%2)},TD(null,A({'href':'user/view.php?id=' + r.id},r.name)));
for (var i = 0; i < d.userfields.length; i++) {
if (r[d.userfields[i]]) {
if (d.userfields[i] == 'email') {
appendChildNodes(row, TD(null, map(partial(DIV,null), r[d.userfields[i]])));
}
else {
appendChildNodes(row, TD(null, r[d.userfields[i]]));
}
}
else {
appendChildNodes(row, TD(null, '-'));
}
}
return row
}
function doSearch() {
results.query = $('search_query').value;
results.type = $('search_type').options[$('search_type').selectedIndex].value;
......
......@@ -93,7 +93,7 @@ class PluginSearchInternal extends PluginSearch {
$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
u.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname
FROM ' . $prefix . 'artefact a
INNER JOIN ' . $prefix .'usr u ON u.id = a.owner
WHERE
......@@ -120,6 +120,14 @@ class PluginSearchInternal extends PluginSearch {
array());
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 ($rec->artefacttype == 'email') {
$users[$rec->id]->email[] = $rec->title;
......
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