Commit 566e5aa3 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1861370: group member search fatal error"

parents 15ed3e6e b275d510
......@@ -1910,41 +1910,43 @@ function group_get_membersearch_data($results, $group, $query, $membershiptype,
$role = group_user_access($group);
$userid = $USER->get('id');
$institution = get_field('group', 'institution', 'id', $group);
foreach ($results['data'] as &$r) {
// Check if any UserRoles are in play
$checks = $USER->apply_userrole_method('group_leave', array('groupid' => $group, 'userid' => $r['id'], 'institution' => $institution));
foreach ($checks as $check) {
if ($check['can_leave'] === false) {
continue 2;
if ($results['data']) {
foreach ($results['data'] as &$r) {
// Check if any UserRoles are in play
$checks = $USER->apply_userrole_method('group_leave', array('groupid' => $group, 'userid' => $r['id'], 'institution' => $institution));
foreach ($checks as $check) {
if ($check['can_leave'] === false) {
continue 2;
}
}
}
if ($role == 'admin' && ($r['id'] != $userid || group_user_can_leave($group, $r['id']))) {
$r['removeform'] = group_get_removeuser_form($r['id'], $group);
}
// NOTE: this is a quick approximation. We should really check whether,
// for each role in the group, that the user can change to it (using
// group_can_change_role). This only controls whether the 'change
// role' link appears though, so it doesn't matter too much. If the
// user clicks on this link, changerole.php does the full check and
// sends them back here saying that the user has no roles they can
// change to anyway.
$r['canchangerole'] = !group_is_only_admin($group, $r['id']);
}
if (!empty($membershiptype)) {
if ($membershiptype == 'request') {
foreach ($results['data'] as &$r) {
$r['addform'] = group_get_adduser_form($r['id'], $group);
$r['denyform'] = group_get_denyuser_form($r['id'], $group);
// TODO: this will suck when there's quite a few on the page,
// would be better to grab all the reasons in one go
$r['reason'] = get_field('group_member_request', 'reason', 'group', $group, 'member', $r['id']);
if ($role == 'admin' && ($r['id'] != $userid || group_user_can_leave($group, $r['id']))) {
$r['removeform'] = group_get_removeuser_form($r['id'], $group);
}
// NOTE: this is a quick approximation. We should really check whether,
// for each role in the group, that the user can change to it (using
// group_can_change_role). This only controls whether the 'change
// role' link appears though, so it doesn't matter too much. If the
// user clicks on this link, changerole.php does the full check and
// sends them back here saying that the user has no roles they can
// change to anyway.
$r['canchangerole'] = !group_is_only_admin($group, $r['id']);
}
if (!empty($membershiptype)) {
if ($membershiptype == 'request') {
foreach ($results['data'] as &$r) {
$r['addform'] = group_get_adduser_form($r['id'], $group);
$r['denyform'] = group_get_denyuser_form($r['id'], $group);
// TODO: this will suck when there's quite a few on the page,
// would be better to grab all the reasons in one go
$r['reason'] = get_field('group_member_request', 'reason', 'group', $group, 'member', $r['id']);
}
}
$smarty->assign('membershiptype', $membershiptype);
}
$smarty->assign('membershiptype', $membershiptype);
}
$results['cdata'] = array_chunk($results['data'], 2);
$results['cdata'] = array_chunk($results['data'], 2);
}
$results['roles'] = group_get_role_info($group);
$smarty->assign('results', $results);
$smarty->assign('searchurl', $searchurl);
......
......@@ -5907,3 +5907,13 @@ function notify_landing_removed($landingpage, $deleted=false) {
'url' => $url,
));
}
function get_max_offset($offset, $limit, $count) {
$offset = $limit * floor($offset / $limit);
// check offset is not going beyond last page from pagination
$maxoffset = $limit * floor($count / $limit);
if ($offset > $maxoffset) {
$offset = $maxoffset;
}
return $offset;
}
......@@ -464,7 +464,7 @@ function build_admin_user_search_results($search, $offset, $limit) {
'limit' => $limit,
'jumplinks' => 8,
'numbersincludeprevnext' => 2,
'offset' => $offset,
'offset' => $results['offset'] ? $results['offset'] : $offset,
'datatable' => 'searchresults',
'searchresultsheading' => 'resultsheading',
'jsonscript' => 'admin/users/search.json.php',
......@@ -993,7 +993,7 @@ function get_group_user_search_results($group, $query, $offset, $limit, $members
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $sortoptionidx, $nontutor
);
if ($results['count']) {
if ($results['count'] && $results['data']) {
$userids = array_map(function($a) { return $a["id"];}, $results['data']);
$introductions = get_records_sql_assoc("SELECT \"owner\", description
FROM {artefact}
......
......@@ -2196,6 +2196,9 @@ function get_users_data($userids, $getviews=true) {
}
function build_userlist_html(&$data, $searchtype, $admingroups, $filter='', $query='') {
if (isset($data['count']) && isset($data['offset']) && $data['count'] < $data['offset']) {
$data['offset'] = $data['count'];
}
if ($data['data']) {
$userlist = array_map(function($u) { return (int)$u['id']; }, $data['data']);
$userdata = get_users_data($userlist, $filter != 'pending');
......@@ -2221,6 +2224,7 @@ function build_userlist_html(&$data, $searchtype, $admingroups, $filter='', $que
$resultcounttextsingular = get_string('user', 'group');
$resultcounttextplural = get_string('users', 'group');
}
$smarty->assign('admingroups', $admingroups);
safe_require('module', 'multirecipientnotification');
$smarty->assign('mrmoduleactive', PluginModuleMultirecipientnotification::is_active());
......
......@@ -4369,7 +4369,7 @@ function build_pagination($params) {
// Build the next/last links
$islast = $page == $last;
$islast = $page >= $last;
$output .= build_pagination_pagelink(
'',
' &raquo;',
......
......@@ -620,6 +620,8 @@ class PluginSearchInternal extends PluginSearch {
$count = get_field_sql('SELECT COUNT(*) FROM {usr} u ' . $join . $where, $values);
$offset = get_max_offset($offset, $limit, $count);
if ($count > 0) {
$data = get_records_sql_assoc('
......@@ -792,6 +794,8 @@ class PluginSearchInternal extends PluginSearch {
$count = get_field_sql('SELECT COUNT(*)' . $from, $values);
$offset = get_max_offset($offset, $limit, $count);
if ($count > 0) {
$data = get_records_sql_assoc('
SELECT ' . $select . $from . ' ORDER BY ' . $orderby,
......@@ -1005,6 +1009,8 @@ class PluginSearchInternal extends PluginSearch {
$count = get_field_sql('SELECT COUNT(*) '.$sql, $values);
$offset = get_max_offset($offset, $limit, $count);
if ($count > 0) {
$sql = 'SELECT g.* ' . $sql . ' ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit);
......
Supports Markdown
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