Commit 680fb9c9 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add institutions filter to user search query



If the 'myinstitutions' option is passed to search_user(), add an
institution subselect to the query so that only users sharing an
institution with the logged-in user are returned.

Change-Id: I058f3a1ab4921da6faa934aebebd0a3f2d2d18c8
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 3f842856
......@@ -135,6 +135,19 @@ class PluginSearchInternal extends PluginSearch {
(gm.member = u.id AND gm.group = ' . (int)$data['group'] . $groupadminsql . ")\n";
$sql .= $groupjoin;
}
$where = '
WHERE
u.id != 0 AND u.active = 1 AND u.deleted = 0';
if (isset($data['institutions']) && !empty($data['institutions'])) {
$where .= '
AND u.id IN (
SELECT usr FROM {usr_institution} WHERE institution IN ('
. join(',', array_map('db_quote', $data['institutions'])) . ')
)';
}
$sql .= "
LEFT OUTER JOIN {usr_account_preference} h ON (u.id = h.usr AND h.field = 'hiderealname')";
$querydata = self::split_query_string(strtolower(trim($query_string)));
......@@ -155,10 +168,6 @@ class PluginSearchInternal extends PluginSearch {
}
}
$where = '
WHERE
u.id != 0 AND u.active = 1 AND u.deleted = 0';
$values = array();
foreach ($querydata as $term) {
$where .= '
......@@ -260,6 +269,7 @@ class PluginSearchInternal extends PluginSearch {
private static function prepare_search_user_options($options) {
global $USER;
if (isset($options['group'])) {
$options['group'] = intval($options['group']);
}
......@@ -275,6 +285,11 @@ class PluginSearchInternal extends PluginSearch {
if (isset($options['exclude'])) {
$options['exclude'] = intval($options['exclude']);
}
if (isset($options['myinstitutions'])) {
if ($institutions = array_keys($USER->get('institutions'))) {
$options['institutions'] = $institutions;
}
}
return $options;
}
......
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