Commit 6dafa0fe authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add friends filter to groupmembersearch ajax script (bug #845290)



Allows searches for group members/non-members, etc, who are also
friends of a given user.  To be used when inviting friends into
groups.

Change-Id: I4618b665d077ea2244b38d4d7db12863aebba6d1
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 6ddb7507
......@@ -55,14 +55,17 @@ if (!$USER->get('admin') && !$USER->get('staff')) {
}
$membershiptype = param_variable('membershiptype', '');
$friends = param_integer('friends', 0);
if (!empty($membershiptype)) {
if ($role != 'admin') {
json_reply('local', get_string('accessdenied', 'error'));
}
}
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype);
$results = get_group_user_search_results(
$group->id, $query, $offset, $limit, $membershiptype, null,
$friends ? $USER->get('id') : null
);
if (!param_integer('html', 1)) {
foreach ($results['data'] as &$result) {
$result = array('id' => $result['id'], 'name' => $result['name']);
......
......@@ -362,9 +362,10 @@ function build_admin_user_search_results($search, $offset, $limit) {
* @param int $limit How many results to show
* @param array $membershiptype User membershiptype
* @param bool $random Set to true if you want the result to be ordered by random, default false
* @param int $friendof Only return friends of this user
*
*/
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $order=null) {
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $order=null, $friendof=null) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
......@@ -407,7 +408,7 @@ function get_group_user_search_results($group, $query, $offset, $limit, $members
$results = call_static_method(
generate_class_name('search', $plugin), 'group_search_user',
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order, $friendof
);
if ($results['count']) {
......
......@@ -448,7 +448,7 @@ class PluginSearchInternal extends PluginSearch {
}
public static function group_search_user($group, $query_string, $constraints, $offset, $limit, $membershiptype, $order=null) {
public static function group_search_user($group, $query_string, $constraints, $offset, $limit, $membershiptype, $order, $friendof) {
list($searchsql, $values) = self::name_search_sql($query_string);
......@@ -523,6 +523,14 @@ class PluginSearchInternal extends PluginSearch {
$orderby = db_random();
}
if ($friendof) {
$from .= '
AND u.id IN (
SELECT usr1 FROM {usr_friend} WHERE usr2 = ? UNION SELECT usr2 FROM {usr_friend} WHERE usr1 = ?
)';
array_push($values, $friendof, $friendof);
}
$count = get_field_sql('SELECT COUNT(*)' . $from, $values);
if ($count > 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