Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
[SOLVED] Get Site members count
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!
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!
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
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.
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<>();
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.
Thanks so much Jorge! We'll try it but I'm sure it will work for us ;)