Commit 13bd7235 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

Added group field to userlist which restricts to users in that group

Other search files changed to support this
parent 2dbd91aa
......@@ -42,8 +42,17 @@ catch (ParameterException $e) {
$limit = param_integer('limit', 20);
$offset = param_integer('offset', 0);
$allfields = param_boolean('allfields');
$group = param_integer('group', 0);
$data = search_user($query, $limit, $offset);
if ($group) {
$data = array(
'group' => $group
);
$data = search_user($query, $limit, $offset, $data);
}
else {
$data = search_user($query, $limit, $offset);
}
json_headers();
$data['error'] = false;
......
......@@ -61,7 +61,7 @@ defined('INTERNAL') || die();
* ),
* );
*/
function search_user($query_string, $limit, $offset = 0) {
function search_user($query_string, $limit, $offset = 0, $data = array()) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
safe_require('artefact', 'internal');
......@@ -72,7 +72,7 @@ function search_user($query_string, $limit, $offset = 0) {
}
$fieldlist = "('" . join("','", $publicfields) . "')";
$results = call_static_method(generate_class_name('search', $plugin), 'search_user', $query_string, $limit, $offset);
$results = call_static_method(generate_class_name('search', $plugin), 'search_user', $query_string, $limit, $offset, $data);
if ($results['data']) {
$userlist = '('.join(',', array_map(create_function('$u','return $u[\'id\'];'), $results['data'])).')';
......
......@@ -68,14 +68,14 @@ class PluginSearchInternal extends PluginSearch {
* ),
* );
*/
public static function search_user($query_string, $limit, $offset = 0) {
public static function search_user($query_string, $limit, $offset = 0, $data=array()) {
safe_require('artefact', 'internal');
$publicfields = array_keys(ArtefactTypeProfile::get_public_fields());
if (empty($publicfields)) {
$publicfields = array('preferredname');
}
if (is_postgres()) {
return self::search_user_pg($query_string, $limit, $offset, $publicfields);
return self::search_user_pg($query_string, $limit, $offset, $data, $publicfields);
}
else if (is_mysql()) {
return self::search_user_my($query_string, $limit, $offset, $publicfields);
......@@ -85,8 +85,11 @@ class PluginSearchInternal extends PluginSearch {
}
}
public static function search_user_pg($query_string, $limit, $offset, $publicfields) {
public static function search_user_pg($query_string, $limit, $offset, $data, $publicfields) {
$fieldlist = "('" . join("','", $publicfields) . "')";
$group = isset($data['group'])
? 'INNER JOIN {group_member} g ON g.group = ' . (int)$data['group'] . ' AND g.member = u.id'
: '';
$count = get_field_sql('
SELECT
......@@ -94,6 +97,7 @@ class PluginSearchInternal extends PluginSearch {
FROM
{usr} u
LEFT JOIN {artefact} a ON u.id=a.owner
' . $group . '
WHERE
u.id <> 0 AND u.active = 1
AND ((
......@@ -121,6 +125,7 @@ class PluginSearchInternal extends PluginSearch {
u.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname, u.email, u.staff
FROM {artefact} a
INNER JOIN {usr} u ON u.id = a.owner
' . $group . '
WHERE
u.id <> 0 AND u.active = 1
AND ((
......@@ -161,15 +166,21 @@ class PluginSearchInternal extends PluginSearch {
);
}
public static function search_user_my($query_string, $limit, $offset, $publicfields) {
public static function search_user_my($query_string, $limit, $offset, $data, $publicfields) {
$fieldlist = "('" . join("','", $publicfields) . "')";
$group = isset($data['group'])
? 'INNER JOIN {group_member} g ON g.group = ' . (int)$data['group'] . ' AND g.member = u.id'
: '';
$count = get_field_sql('
SELECT
COUNT(DISTINCT owner)
FROM
{usr} u
LEFT JOIN {artefact} a ON u.id=a.owner
' . $group . '
WHERE
u.id <> 0 AND u.active = 1
AND ((
......@@ -199,6 +210,7 @@ class PluginSearchInternal extends PluginSearch {
u.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname, u.email, u.staff
FROM {artefact} a
INNER JOIN {usr} u ON u.id = a.owner
' . $group . '
WHERE
u.id <> 0 AND u.active = 1
AND ((
......
......@@ -5,7 +5,7 @@
replaceChildNodes('{{$name}}_messages');
sendjsonrequest('{{$WWWROOT}}json/usersearch.php', {'query':q, 'limit': 100}, 'GET',
sendjsonrequest('{{$WWWROOT}}json/usersearch.php', {'query':q, 'limit': 100 {{if $group}}, 'group': {{$group}}{{/if}}}, 'GET',
function (users) {
var members = {};
var counter = 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