Improve user groups listing

This commit is contained in:
Frédéric Guillot
2020-04-05 12:05:41 -07:00
parent 95d8df405d
commit 1f6a42ace7
36 changed files with 94 additions and 92 deletions

View File

@@ -111,31 +111,28 @@ class UserHelper extends Base
/**
* Get group names for a given user and return an associative array:
* ['full_list'] = a comma-separated list of all group-memberships
* ['limited_list'] = a comma-separated list limited to N groups depending on value of SHOW_GROUP_MEMBERSHIPS_IN_USERLIST_WITH_LIMIT
* ['has_groups'] = boolean TRUE if user is member of at least one group ... else FALSE
*
* @access public
* @param integer $user_id User id
* @param integer $userID User id
* @return array
*/
public function getUsersGroupNames($user_id)
public function getUsersGroupNames($userID)
{
$groups_list = array_column($this->groupMemberModel->getGroups($user_id), 'name');
$full_list = implode(', ', $groups_list);
$groupsList = array_column($this->groupMemberModel->getGroups($userID), 'name');
$limitedList = $groupsList;
$total = count($groupsList);
// let's reduce the array to the limit
$limited_list = ( SHOW_GROUP_MEMBERSHIPS_IN_USERLIST_WITH_LIMIT == 0 ) ? $groups_list : array_slice($groups_list, 0 , SHOW_GROUP_MEMBERSHIPS_IN_USERLIST_WITH_LIMIT);
// if limiting had any effect ... let's add a hint to the list, to inform the user there are more group-memberships for that user
$limited_list = ( $groups_list == $limited_list ) ? implode(', ', $limited_list) : implode(', ', $limited_list) . ' ( >> ' . t('hover mouse over group-icon, to show all group-memberships') . ' )';
if ($total > 0 && SHOW_GROUP_MEMBERSHIPS_IN_USERLIST_WITH_LIMIT > 0) {
$limitedList = array_slice($groupsList, 0 , SHOW_GROUP_MEMBERSHIPS_IN_USERLIST_WITH_LIMIT);
}
$has_groups = (count($groups_list)) ? true : false;
return array(
'full_list' => $full_list,
'limited_list' => $limited_list,
'has_groups' => $has_groups
);
return [
'full_list' => $groupsList,
'limited_list' => $limitedList,
'has_groups' => $total > 0,
'total' => $total,
'not_shown' => $total - count($limitedList),
];
}
/**