[SOLVED] Get Site members count

thumbnail
Iván Bautista, modified 6 Years ago. New Member Posts: 16 Join Date: 1/13/15 Recent Posts
Dear all,

I would like to get a report to check how many users are in the membership list of each Site. The problem is that using the API I'm just getting the users that were manually added, but not the complete list I see if I navigate to Membership are in the Site admin panel. This is caused by the users that are coming from a user group that has been configured in some Sites.

So, I'm looking for (and not finding) some class that can give me the number of users that are able to access to a certain Site in just one method call (in other case I would have to get different tables thru the API users_groups, groups_usergroups and users_usergroups).

Does anyone have a solution for this?

Thanks so much in advance!
thumbnail
Jorge Díaz, modified 6 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Hi Iván!

You can get that information calling UserLocalServiceUtil.searchCount method with inherit =true and usersGroups=groupId in last map parameter.

You have an example here: https://github.com/liferay/liferay-portal/blob/50aaaf090520d096389a1ced933c21a2ccb2b1a3/modules/apps/site/site-admin-web/src/main/java/com/liferay/site/admin/web/internal/display/context/SiteAdminDisplayContext.java#L348-L362
    public int getUsersCount(Group group) {
        LinkedHashMap<string, object> userParams = new LinkedHashMap&lt;&gt;();

        ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
            WebKeys.THEME_DISPLAY);

        Company company = themeDisplay.getCompany();

        userParams.put("inherit", Boolean.TRUE);
        userParams.put("usersGroups", group.getGroupId());

        return UserLocalServiceUtil.searchCount(
            company.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
            userParams);
    }
</string,>


Same syntax is available for UserLocalServiceUtil.search method.

Both search and searchCount methods allows a lots of search options in the map parameter, but unfortunately, there is no documentation about them.

Map parameter is handled here: https://github.com/liferay/liferay-portal/blob/50aaaf090520d096389a1ced933c21a2ccb2b1a3/portal-impl/src/com/liferay/portal/service/persistence/impl/UserFinderImpl.java#L1106-L1344 if you want more information, you can try understanding that code, but IMHO it is one of the most obscure methods of Liferay code.
thumbnail
Iván Bautista, modified 6 Years ago. New Member Posts: 16 Join Date: 1/13/15 Recent Posts
Thanks so much Jorge! We'll try it but I'm sure it will work for us ;)