001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.sitesadmin;
016    
017    import com.liferay.portal.model.Group;
018    import com.liferay.portal.model.Portlet;
019    import com.liferay.portal.security.permission.PermissionChecker;
020    import com.liferay.portal.service.GroupLocalServiceUtil;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.PortletCategoryKeys;
023    import com.liferay.portal.util.PropsValues;
024    import com.liferay.portlet.BaseControlPanelEntry;
025    
026    import java.util.LinkedHashMap;
027    
028    /**
029     * @author Jorge Ferrer
030     * @author Sergio González
031     * @author Miguel Pastor
032     */
033    public class SitesControlPanelEntry extends BaseControlPanelEntry {
034    
035            public boolean isVisible(
036                            PermissionChecker permissionChecker, Portlet portlet)
037                    throws Exception {
038    
039                    if (PropsValues.SITES_CONTROL_PANEL_MEMBERS_VISIBLE) {
040                            LinkedHashMap<String, Object> groupParams =
041                                    new LinkedHashMap<String, Object>();
042    
043                            groupParams.put("site", true);
044                            groupParams.put("usersGroups", permissionChecker.getUserId());
045    
046                            int count = GroupLocalServiceUtil.searchCount(
047                                    permissionChecker.getCompanyId(), null, null, groupParams);
048    
049                            if (count > 0) {
050                                    return true;
051                            }
052                    }
053    
054                    return false;
055            }
056    
057            @Override
058            public boolean isVisible(
059                            Portlet portlet, String category, ThemeDisplay themeDisplay)
060                    throws Exception {
061    
062                    Group scopeGroup = themeDisplay.getScopeGroup();
063    
064                    if (scopeGroup.isCompany()) {
065                            return false;
066                    }
067    
068                    String controlPanelCategory = themeDisplay.getControlPanelCategory();
069    
070                    if (controlPanelCategory.equals(PortletCategoryKeys.CONTENT)) {
071                            return false;
072                    }
073    
074                    return super.isVisible(portlet, category, themeDisplay);
075            }
076    
077    }