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

Show pending users in searches by institutional admins

parent 27df8377
......@@ -154,11 +154,11 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
if (!$USER->get('admin')) {
$allowed = $USER->get('admininstitutions');
if ($search->institution == 'all' || !isset($allowed[$search->institution])) {
$constraints[] = array('field' => 'institution',
$constraints[] = array('field' => 'institution_requested',
'type' => 'in',
'list' => $allowed);
} else {
$constraints[] = array('field' => 'institution',
$constraints[] = array('field' => 'institution_requested',
'type' => 'equals',
'string' => $search->institution);
}
......
......@@ -277,23 +277,34 @@ class PluginSearchInternal extends PluginSearch {
foreach ($constraints as $f) {
if ($f['field'] == 'institution') {
$institutionsearch .= ' LEFT OUTER JOIN {usr_institution} i ON i.usr = u.id ';
if ($f['type'] == 'in') {
$where .= " AND i.institution IN ('" . join("','", $f['list']) . "')";
} else if ($f['string'] == 'mahara') {
if ($f['string'] == 'mahara') {
$where .= ' AND i.institution IS NULL';
} else {
$where .= ' AND i.institution' . $matchtypes[$f['type']];
$values[] = $f['string'];
}
} else if ($f['field'] == 'institution_requested') {
$institutionsearch .= ' LEFT OUTER JOIN {usr_institution} i ON i.usr = u.id ';
$institutionsearch .= ' LEFT OUTER JOIN {usr_institution_request} ir ON ir.usr = u.id ';
if ($f['type'] == 'in') {
$institutions = "('" . join("','", $f['list']) . "')";
$where .= ' AND (i.institution IN ' . $institutions . 'OR ir.institution IN ' . $institutions . ')';
} else if ($f['type'] == 'equals') {
$where .= ' AND (i.institution = ? OR ir.institution = ?)';
$values[] = $f['string'];
$values[] = $f['string'];
}
} else {
$where .= ' AND u.' . $f['field'] . $matchtypes[$f['type']];
$values[] = $f['string'];
}
}
}
if (strpos($sort, 'institution') === 0 && $institutionsearch == '') {
$institutionsearch = ' LEFT OUTER JOIN {usr_institution} i ON i.usr = u.id ';
if (strpos($sort, 'institution') === 0) {
$sort = 'i.' . $sort;
if ($institutionsearch == '') {
$institutionsearch = ' LEFT OUTER JOIN {usr_institution} i ON i.usr = u.id ';
}
}
$count = get_field_sql('SELECT COUNT(*) FROM {usr} u ' . $institutionsearch . $where, $values);
......
......@@ -179,8 +179,7 @@ END;
continue;
}
if ($key_parts[0] == 'store' || $key_parts[0] == 'text' || $key_parts[0] == 'string'
|| $key == 'ref_institution') {
if ($key_parts[0] == 'store' || $key_parts[0] == 'text' || $key_parts[0] == 'string') {
$new_result[$key_parts[1]] = $value;
}
}
......@@ -208,7 +207,8 @@ END;
'email' => 'string_email',
'username' => 'text_username',
'firstname' => 'text_firstname',
'lastname' => 'text_lastname'
'lastname' => 'text_lastname',
'institution_requested' => 'text_institutions_requested',
);
if (!empty($queries)) {
$terms = array();
......@@ -422,7 +422,6 @@ END;
}
if (
!isset($user['preferredname'])
|| !isset($user['institution'])
|| !isset($user['email'])
|| !isset($user['username'])
|| !isset($user['preferredname'])
......@@ -434,22 +433,30 @@ END;
$user = (array)$user;
}
}
if (!isset($user['institutions'])) {
$user['institutions'] = get_column('usr_institution', 'institution', 'usr', $user['id']);
}
if ($user['deleted']) {
self::delete_byidtype($user['id'], 'user');
return;
}
if (!isset($user['institutions'])) {
$user['institutions'] = get_column('usr_institution', 'institution', 'usr', $user['id']);
}
if (!isset($user['institutions_requested'])) {
$institutions_requested = $user['institutions'];
foreach (get_column('usr_institution_request', 'institution', 'usr', $user['id']) as $i) {
if (!in_array($i, $institutions_requested)) {
$institutions_requested[] = $i;
}
}
}
// @todo: need to index public profile fields
$doc = array(
'id' => $user['id'],
'owner' => $user['id'],
'type' => 'user',
'index_name' => $user['preferredname'],
'ref_institution' => $user['institution'],
'text_institutions' => empty($user['institutions']) ? 'mahara' : join(' ', $user['institutions']),
'string_email' => $user['email'],
'text_username' => $user['username'],
......@@ -458,6 +465,7 @@ END;
'text_lastname' => $user['lastname'],
'index_active' => $user['active'],
'store_suspended' => (int)!empty($user['suspendedcusr']),
'text_institutions_requested' => join(' ', $institutions_requested),
);
if (empty($doc['index_name'])) {
$doc['index_name'] = $user['firstname'] . ' ' . $user['lastname'];
......
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