Example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroupsCount

List of usage examples for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroupsCount

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroupsCount.

Prototype

public static int getGroupsCount(long companyId, String className, long parentGroupId) 

Source Link

Document

Returns the number of groups that are direct children of the parent group with the matching className.

Usage

From source file:com.liferay.asset.publisher.web.display.context.LayoutScopesItemSelectorViewDisplayContext.java

License:Open Source License

@Override
public GroupSearch getGroupSearch() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    GroupSearch groupSearch = new GroupSearch(getPortletRequest(), getPortletURL());

    int total = GroupLocalServiceUtil.getGroupsCount(themeDisplay.getCompanyId(), Layout.class.getName(),
            getGroupId());//from   w  w w  .  ja  v a  2 s  .c  o m

    groupSearch.setTotal(total);

    List<Group> groups = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), Layout.class.getName(),
            getGroupId(), groupSearch.getStart(), groupSearch.getEnd());

    groups = _filterLayoutGroups(groups, _isPrivateLayout());

    groupSearch.setResults(groups);

    return groupSearch;
}

From source file:com.liferay.site.admin.web.internal.display.context.SiteAdminDisplayContext.java

License:Open Source License

public int getChildSitesCount(Group group) {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    return GroupLocalServiceUtil.getGroupsCount(themeDisplay.getCompanyId(), group.getGroupId(), true);
}

From source file:com.liferay.site.browser.web.internal.display.context.SiteBrowserDisplayContext.java

License:Open Source License

public GroupSearch getGroupSearch() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    GroupSearch groupSearch = new GroupSearch(_liferayPortletRequest, getPortletURL());

    GroupSearchTerms groupSearchTerms = (GroupSearchTerms) groupSearch.getSearchTerms();

    List<Group> results = new ArrayList<>();

    int additionalSites = 0;
    int total = 0;

    boolean includeCompany = ParamUtil.getBoolean(_request, "includeCompany");
    boolean includeUserPersonalSite = ParamUtil.getBoolean(_request, "includeUserPersonalSite");

    long[] classNameIds = _CLASS_NAME_IDS;

    if (includeCompany) {
        classNameIds = ArrayUtil.append(classNameIds, PortalUtil.getClassNameId(Company.class));
    }/*from w w w  . j a  v a2 s .c  o  m*/

    if (includeUserPersonalSite) {
        if (groupSearch.getStart() == 0) {
            Group userPersonalSite = GroupLocalServiceUtil.getGroup(company.getCompanyId(),
                    GroupConstants.USER_PERSONAL_SITE);

            results.add(userPersonalSite);
        }

        additionalSites++;
    }

    String type = getType();

    if (type.equals("layoutScopes")) {
        total = GroupLocalServiceUtil.getGroupsCount(themeDisplay.getCompanyId(), Layout.class.getName(),
                getGroupId());
    } else if (type.equals("parent-sites")) {
    } else {
        total = GroupLocalServiceUtil.searchCount(themeDisplay.getCompanyId(), classNameIds,
                groupSearchTerms.getKeywords(), getGroupParams());
    }

    total += additionalSites;

    groupSearch.setTotal(total);

    int start = groupSearch.getStart();

    if (groupSearch.getStart() > additionalSites) {
        start = groupSearch.getStart() - additionalSites;
    }

    List<Group> groups = null;

    if (type.equals("layoutScopes")) {
        groups = GroupLocalServiceUtil.getGroups(company.getCompanyId(), Layout.class.getName(), getGroupId(),
                start, groupSearch.getResultEnd() - additionalSites);

        groups = _filterLayoutGroups(groups, isPrivateLayout());
    } else if (type.equals("parent-sites")) {
        Group group = GroupLocalServiceUtil.getGroup(getGroupId());

        groups = group.getAncestors();

        String filter = getFilter();

        if (Validator.isNotNull(filter)) {
            groups = _filterGroups(groups, filter);
        }

        total = groups.size();

        total += additionalSites;

        groupSearch.setTotal(total);
    } else {
        groups = GroupLocalServiceUtil.search(company.getCompanyId(), classNameIds,
                groupSearchTerms.getKeywords(), getGroupParams(), QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                groupSearch.getOrderByComparator());

        groups = _filterGroups(groups, themeDisplay.getPermissionChecker());

        total = groups.size();

        total += additionalSites;

        groupSearch.setTotal(total);

        groups = groups.subList(start, groupSearch.getResultEnd() - additionalSites);
    }

    results.addAll(groups);

    groupSearch.setResults(results);

    return groupSearch;
}