Commit 24d26966 authored by Eugene Venter's avatar Eugene Venter
Browse files

view access: add friend search to user sharing



Bug #825595.

Add "Friends" search functionality to "Share with other users and
groups" section. The Friends search view is also the new default now,
instead of Users.

Change-Id: Id2c278a64e1c8d921cb8bea8179a8c39e6a47a50
Signed-off-by: default avatarEugene Venter <eugene@catalyst.net.nz>
parent 77c45fa7
......@@ -75,6 +75,7 @@ class PluginSearchInternal extends PluginSearch {
* @param integer What result to start at (0 == first result)
* @param data Filters the users searched by
* can contain:
* 'friends' => boolean // only return $USER's friends
* 'group' => integer, // only users in this group
* 'owner' => boolean // include the group ownwer (only if group is set)
* 'exclude'=> int // excludes a user
......@@ -107,6 +108,7 @@ class PluginSearchInternal extends PluginSearch {
* );
*/
public static function search_user($query_string, $limit, $offset = 0, $data=array()) {
global $USER;
$data = self::prepare_search_user_options($data);
$sql = '
......@@ -128,6 +130,13 @@ class PluginSearchInternal extends PluginSearch {
WHERE
u.id != 0 AND u.active = 1 AND u.deleted = 0';
if (!empty($data['friends'])) {
// Only include friends in search
$where .= ' AND u.id IN (
SELECT usr1 FROM {usr_friend} f1 WHERE f1.usr2 = ' . $USER->get('id')
. ' UNION SELECT usr2 FROM {usr_friend} f2 WHERE f2.usr1 = ' . $USER->get('id') . ')';
}
if (isset($data['institutions']) && !empty($data['institutions'])) {
$where .= '
AND u.id IN (
......
......@@ -32,8 +32,9 @@
<div class="fl viewacl-advanced-search">
<label>{{str tag=search}}</label>
<select name="type" id="type">
<option value="friend" selected="selected">{{str tag=friends section=view}}</option>
<option value="group">{{str tag=groups}}</option>
<option value="user" selected="selected">{{str tag=users}}</option>
<option value="user">{{str tag=users}}</option>
</select>
<input type="text" name="search" id="search">
<button id="dosearch" class="btn-search" type="button">{{str tag=go}}</button>
......@@ -359,7 +360,7 @@ var searchTable = new TableRenderer(
);
searchTable.statevars.push('type');
searchTable.statevars.push('query');
searchTable.type = 'user';
searchTable.type = 'friend';
searchTable.pagerOptions = {
'firstPageString': '\u00AB',
'previousPageString': '<',
......@@ -373,6 +374,8 @@ searchTable.pagerOptions = {
searchTable.query = '';
searchTable.rowfunction = function(rowdata, rownumber, globaldata) {
rowdata.type = searchTable.type;
rowdata.type = rowdata.type == 'friend' ? 'user' : rowdata.type;
var buttonTD = TD({'style': 'white-space:nowrap;'});
var addButton = BUTTON({'type': 'button', 'class': 'button'}, {{jstr tag=add}});
......
......@@ -40,6 +40,9 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
switch ($type) {
case 'friend':
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id'), 'friends' => true));
break;
case 'user':
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
break;
......
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