001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
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", Boolean.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                    String controlPanelCategory = themeDisplay.getControlPanelCategory();
063    
064                    if (controlPanelCategory.equals(PortletCategoryKeys.CONTENT)) {
065                            return false;
066                    }
067    
068                    return super.isVisible(portlet, category, themeDisplay);
069            }
070    
071    }