1
votes

I need help in printing private and public sites of which the user is a member.

By resuing the code from the post (How do I get Sites of which the user is a member in Liferay theme?) I am able to get the sites, but it gives users' private and public pages too.

How to avoid printing user's private and public pages, since I need only Communities or rather Sites.

<ul>
    #foreach($site in $user.mySites)
       #if ($site.hasPrivateLayouts())
              <li><a href="/group${site.friendlyURL}">$site.descriptiveName</a></li>
       #end
       #if ($site.hasPublicLayouts())
              <li><a href="/web${site.friendlyURL}">$site.descriptiveName</a></li>
    #end
    #end
</ul>

Environment: Liferay 6.1

Thanks

3

3 Answers

1
votes

I think instead of using the mysites section for user you should use the user services and group service to fetch the user groups.

#set($userId = $getterUtil.getLong($request.remote-user))
#set($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set($user = $userLocalService.getUserById($userId))
#set($groupLocalService=$serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
#set($userGroup = $groupLocalService.getUserGroup($companyId,$getterUtil.getLong($userId)))

$userGroup
1
votes

I think you can use the same code with some changes:

<ul>
    #foreach($site in $user.mySites)        
        <!-- if it is NOT a user's public or private site only then print it -->
        #if(!$site.isUserPersonalSite())            
            #if ($site.hasPrivateLayouts())
                <li><a href="/group${site.friendlyURL}">$site.descriptiveName</a></li>
            #end

            #if ($site.hasPublicLayouts())
                <li><a href="/web${site.friendlyURL}">$site.descriptiveName</a></li>
            #end
        #end
    #end
</ul>

Note the if(!$site.isUserPersonalSite()) code, if the site is a user's public or private site (i.e. containing user's public & private pages) then don't print anything.

0
votes

Update the following properties in your portal-ext.properties in liferay root

# Deactivate Personal Community with *private* pages:
layout.user.private.layouts.enabled=false   

# Deactivate Personal Community with *public* pages:
layout.user.public.layouts.enabled=false