Commit 39f657fe authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes Icf28f531,I310bed95,I058f3a1a,I6cf82916

* changes:
  Add 'My institutions' filter drop-down to find friends page
  Add institutions filter to pagination links in search results
  Add institutions filter to user search query
  Add institution filter parameter to user search page
parents aa5f5a85 1ac5f69d
......@@ -50,8 +50,15 @@ if ($page == 'myfriends') {
$data['filter'] = $filter;
}
else {
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
$options = array('exclude' => $USER->get('id'));
if ($filter == 'myinstitutions') {
$options['myinstitutions'] = true;
}
$data = search_user($query, $limit, $offset, $options);
$data['query'] = $query;
if (!empty($options['myinstitutions'])) {
$data['filter'] = $filter;
}
}
$controlledgroups = count_records_sql("SELECT COUNT(g.id)
......
......@@ -262,6 +262,8 @@ $string['friends'] = 'friends';
$string['user'] = 'user';
$string['users'] = 'users';
$string['Friends'] = 'Friends';
$string['Everyone'] = 'Everyone';
$string['myinstitutions'] = 'My Institutions';
$string['friendlistfailure'] = 'Failed to modify your friends list';
$string['userdoesntwantfriends'] = 'This user doesn\'t want any new friends';
......
......@@ -1441,23 +1441,30 @@ function build_userlist_html(&$data, $page, $admingroups) {
$smarty = smarty_core();
$smarty->assign('data', isset($userdata) ? $userdata : null);
$smarty->assign('page', $page);
$params = array();
if (isset($data['query'])) {
$smarty->assign('query', $data['query']);
$params = '?query=' . $data['query'];
$resultcounttextsingular = get_string('user', 'group');
$resultcounttextplural = get_string('users', 'group');
$smarty->assign('query', 1);
$params['query'] = $data['query'];
}
elseif (isset($data['filter'])) {
$smarty->assign('filter', $data['filter']);
$params = '?filter=' . $data['filter'];
if (isset($data['filter'])) {
$params['filter'] = $data['filter'];
}
if ($page == 'myfriends') {
$resultcounttextsingular = get_string('friend', 'group');
$resultcounttextplural = get_string('friends', 'group');
}
else {
$resultcounttextsingular = get_string('user', 'group');
$resultcounttextplural = get_string('users', 'group');
}
$smarty->assign('admingroups', $admingroups);
$data['tablerows'] = $smarty->fetch('user/userresults.tpl');
$pagination = build_pagination(array(
'id' => 'friendslist_pagination',
'url' => get_config('wwwroot') . 'user/' . $page . '.php' . $params,
'url' => get_config('wwwroot') . 'user/' . $page . '.php?' . http_build_query($params),
'jsonscript' => 'json/friendsearch.php',
'datatable' => 'friendslist',
'count' => $data['count'],
......
......@@ -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;
}
......
......@@ -38,10 +38,22 @@ define('SECTION_PAGE', 'find');
$query = param_variable('query', '');
$offset = param_integer('offset', 0);
$filter = param_alpha('filter', 'myinstitutions');
$limit = 10;
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
$options = array('exclude' => $USER->get('id'));
if ($filter == 'myinstitutions' && $USER->get('institutions')) {
$options['myinstitutions'] = true;
}
else {
$filter = 'all';
}
$data = search_user($query, $limit, $offset, $options);
$data['query'] = $query;
if (!empty($options['myinstitutions'])) {
$data['filter'] = $filter;
}
require_once(get_config('libroot').'group.php');
$admingroups = false;
......@@ -55,20 +67,33 @@ foreach (group_get_user_groups() as $g) {
build_userlist_html($data, 'find', $admingroups);
$searchform = pieform(array(
$searchform = array(
'name' => 'search',
'renderer' => 'oneline',
'elements' => array(
'query' => array(
'type' => 'text',
'defaultvalue' => $query
'elements' => array(),
);
if ($USER->get('institutions')) {
$searchform['elements']['filter'] = array(
'type' => 'select',
'options' => array(
'all' => get_string('Everyone', 'group'),
'myinstitutions' => get_string('myinstitutions', 'group'),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('search')
)
)
));
'defaultvalue' => $filter,
);
}
$searchform['elements']['query'] = array(
'type' => 'text',
'defaultvalue' => $query,
);
$searchform['elements']['submit'] = array(
'type' => 'submit',
'value' => get_string('search'),
);
$searchform = pieform($searchform);
$js = <<< EOF
addLoadEvent(function () {
......@@ -76,6 +101,9 @@ addLoadEvent(function () {
connect('search_submit', 'onclick', function (event) {
replaceChildNodes('messages');
var params = {'query': $('search_query').value, 'extradata':serializeJSON({'page':'find'})};
if ($('search_filter')) {
params.filter = $('search_filter').value;
}
p.sendQuery(params);
event.stop();
});
......
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