コード例 #1
0
  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));
    }

    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;
    }

    int end = groupSearch.getEnd() - additionalSites;

    List<Group> groups = null;

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

      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(),
              start,
              end,
              groupSearch.getOrderByComparator());
    }

    results.addAll(groups);

    groupSearch.setResults(results);

    return groupSearch;
  }
コード例 #2
0
  public GroupSearch getGroupSearch(PortletRequest portletRequest, PortletURL portletURL)
      throws PortalException {

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

    GroupSearch groupSearch = new GroupSearch(portletRequest, portletURL);

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

    if (!searchTerms.isSearch()) {
      groupSearch.setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn");
    } else {
      groupSearch.setSearch(true);
    }

    long parentGroupId = getParentGroupId(portletRequest);

    Company company = themeDisplay.getCompany();

    List results = null;

    if (!searchTerms.hasSearchTerms()
        && isFilterManageableGroups(portletRequest)
        && (parentGroupId <= 0)) {

      List<Group> groups = getAllGroups(portletRequest);

      groupSearch.setTotal(groups.size());

      results = ListUtil.subList(groups, groupSearch.getStart(), groupSearch.getEnd());
    } else if (searchTerms.hasSearchTerms()) {
      int total =
          _groupLocalService.searchCount(
              company.getCompanyId(),
              _classNameIds,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId));

      groupSearch.setTotal(total);

      results =
          _groupLocalService.search(
              company.getCompanyId(),
              _classNameIds,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId),
              groupSearch.getStart(),
              groupSearch.getEnd(),
              groupSearch.getOrderByComparator());
    } else {
      long groupId =
          ParamUtil.getLong(portletRequest, "groupId", GroupConstants.DEFAULT_PARENT_GROUP_ID);

      int total =
          _groupLocalService.searchCount(
              company.getCompanyId(),
              _classNameIds,
              groupId,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId));

      groupSearch.setTotal(total);

      results =
          _groupLocalService.search(
              company.getCompanyId(),
              _classNameIds,
              groupId,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId),
              groupSearch.getStart(),
              groupSearch.getEnd(),
              groupSearch.getOrderByComparator());
    }

    groupSearch.setResults(results);

    return groupSearch;
  }