Commit 599eed13 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show institution invitations/requests on user search when using solr plugin

parent bc2dd777
......@@ -94,7 +94,7 @@ if ($usertype == 'requesters') {
'title' => get_string('inviteuserstojoin', 'admin'),
'lefttitle' => get_string('Non-members', 'admin'),
'righttitle' => get_string('userstobeinvited', 'admin'),
'searchparams' => array('member' => 0, 'invited' => 0, 'requested' => 0)
'searchparams' => array('member' => 0, 'invitedby' => 0, 'requested' => 0)
);
$submittext = get_string('inviteusers', 'admin');
}
......
......@@ -34,7 +34,7 @@ $params = new StdClass;
$params->query = trim(param_variable('query', ''));
$params->institution = param_alphanum('institution', null);
$params->requested = param_integer('requested', null);
$params->invited = param_integer('invited', null);
$params->invitedby = param_integer('invitedby', null);
$params->member = param_integer('member', null);
$limit = param_integer('limit', 100);
......
......@@ -364,7 +364,8 @@ $string['Admins'] = 'Admins';
$string['Query'] = 'Query';
$string['Institution'] = 'Institution';
$string['confirm'] = 'confirm';
$string['invited'] = 'invited';
$string['invitedby'] = 'Invited by';
$string['requestto'] = 'Request to';
$string['useradded'] = 'User added';
$string['invitationsent'] = 'Invitation sent';
......
......@@ -130,7 +130,7 @@ function search_user($query_string, $limit, $offset = 0) {
function get_institutional_admin_search_results($search, $limit) {
$institution = new StdClass;
$institution->name = $search->institution;
foreach (array('member', 'requested', 'invited') as $p) {
foreach (array('member', 'requested', 'invitedby') as $p) {
$institution->{$p} = $search->{$p};
}
$results = institutional_admin_user_search($search->query, $institution, $limit);
......@@ -260,7 +260,7 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
$institutions = get_records_assoc('institution', '', '', '', 'name,displayname');
if (count($institutions) > 1) {
$cols['institution'] = array('name' => get_string('institution'),
'template' => '{if empty($r.institutions)}{$institutions.mahara->displayname}{else}{foreach from=$r.institutions item=i}<div>{$institutions[$i]->displayname}</div>{/foreach}{/if}{if !empty($r.requested)}{foreach from=$r.requested item=i}<div>{$institutions[$i]->displayname} ({if $USER->is_institutional_admin("$i")}<a href="{$WWWROOT}admin/users/addtoinstitution.php?id={$r.id}&institution={$i}">{str tag=confirm section=admin}</a>{else}{str tag=requested}{/if})</div>{/foreach}{/if}{if !empty($r.invitedby)}{foreach from=$r.invitedby item=i}<div>{$institutions[$i]->displayname} ({str tag=invited section=admin})</div>{/foreach}{/if}');
'template' => '{if empty($r.institutions)}{$institutions.mahara->displayname}{else}{foreach from=$r.institutions item=i}<div>{$institutions[$i]->displayname}</div>{/foreach}{/if}{if !empty($r.requested)}{foreach from=$r.requested item=i}<div class="pending">{str tag=requestto section=admin} {$institutions[$i]->displayname}{if $USER->is_institutional_admin("$i")} (<a href="{$WWWROOT}admin/users/addtoinstitution.php?id={$r.id}&institution={$i}">{str tag=confirm section=admin}</a>){/if}</div>{/foreach}{/if}{if !empty($r.invitedby)}{foreach from=$r.invitedby item=i}<div class="pending">{str tag=invitedby section=admin} {$institutions[$i]->displayname}</div>{/foreach}{/if}');
}
$smarty = smarty_core();
......
......@@ -408,7 +408,7 @@ class PluginSearchInternal extends PluginSearch {
AND ' . ($institution->member ? ' NOT ' : '') . ' member.usr IS NULL';
$studentid = ', member.studentid';
}
if (!is_null($institution->requested) || !is_null($institution->invited)) {
if (!is_null($institution->requested) || !is_null($institution->invitedby)) {
$sql .= '
LEFT OUTER JOIN {usr_institution_request} req ON (req.usr = u.id
AND req.institution = ' . db_quote($institution->name) . ')';
......@@ -420,7 +420,7 @@ class PluginSearchInternal extends PluginSearch {
}
$studentid = ', req.studentid';
}
if (!is_null($institution->invited)) {
if (!is_null($institution->invitedby)) {
if ($institution->requested == 1) {
$where .= ' AND req.confirmedinstitution = 1';
} else {
......
......@@ -170,6 +170,12 @@ END;
private static function remove_key_prefix($results) {
if (is_array($results['data'])) {
$toarray = array(
'institutions' => 1,
'invitedby' => 1,
'member' => 1,
'requested' => 1,
);
foreach ($results['data'] as &$result) {
$new_result = array();
foreach ($result as $key => &$value) {
......@@ -185,7 +191,7 @@ END;
}
if ($key_parts[0] == 'store' || $key_parts[0] == 'text' || $key_parts[0] == 'string') {
if ($key_parts[1] == 'institutions') {
if (isset($toarray[$key_parts[1]])) {
$value = $value == 'mahara' ? array() : explode(' ', $value);
}
$new_result[$key_parts[1]] = $value;
......@@ -268,11 +274,11 @@ END;
}
if (!empty($institution->name)) {
foreach (array('member', 'requested', 'invited') as $f) {
foreach (array('member', 'requested', 'invitedby') as $f) {
if ($institution->{$f} == 0) {
$neg[] = '-text_' . $f . '_institution:' . $institution->name;
$neg[] = '-text_' . $f . ':' . $institution->name;
} else if ($institution->{$f} == 1) {
$q[] = 'text_' . $f . '_institution:' . $institution->name;
$q[] = 'text_' . $f . ':' . $institution->name;
}
}
}
......@@ -502,9 +508,9 @@ END;
'index_active' => $user['active'],
'string_suspended' => (int)!empty($user['suspendedcusr']),
'text_institutions_requested' => join(' ', $institutions_requested),
'text_member_institution' => join(' ', $user['institutions']),
'text_requested_institution' => join(' ', $requested),
'text_invited_institution' => join(' ', $invited),
'text_member' => join(' ', $user['institutions']),
'text_requested' => join(' ', $requested),
'text_invitedby' => join(' ', $invited),
);
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