001    /**
002     * Copyright (c) 2000-2012 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.Portlet;
018    import com.liferay.portal.security.permission.PermissionChecker;
019    import com.liferay.portal.service.GroupLocalServiceUtil;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portal.util.PortletCategoryKeys;
022    import com.liferay.portal.util.PropsValues;
023    import com.liferay.portlet.BaseControlPanelEntry;
024    
025    import java.util.LinkedHashMap;
026    
027    /**
028     * @author Jorge Ferrer
029     * @author Sergio González
030     * @author Miguel Pastor
031     */
032    public class SitesControlPanelEntry extends BaseControlPanelEntry {
033    
034            public boolean isVisible(
035                            PermissionChecker permissionChecker, Portlet portlet)
036                    throws Exception {
037    
038                    if (PropsValues.SITES_CONTROL_PANEL_MEMBERS_VISIBLE) {
039                            LinkedHashMap<String, Object> groupParams =
040                                    new LinkedHashMap<String, Object>();
041    
042                            groupParams.put("site", true);
043                            groupParams.put("usersGroups", permissionChecker.getUserId());
044    
045                            int count = GroupLocalServiceUtil.searchCount(
046                                    permissionChecker.getCompanyId(), null, null, groupParams);
047    
048                            if (count > 0) {
049                                    return true;
050                            }
051                    }
052    
053                    return false;
054            }
055    
056            @Override
057            public boolean isVisible(
058                            Portlet portlet, String category, ThemeDisplay themeDisplay)
059                    throws Exception {
060    
061                    String controlPanelCategory = themeDisplay.getControlPanelCategory();
062    
063                    if (controlPanelCategory.equals(PortletCategoryKeys.CONTENT)) {
064                            return false;
065                    }
066    
067                    return super.isVisible(portlet, category, themeDisplay);
068            }
069    
070    }