0

コミュニティ選択ボックスを作成して、訪問者が Liferay コミュニティを開くことができるようにしようとしています。ただし、認証されたユーザーに対してのみ機能するようです。では、ログアウトしたユーザーを含むすべてのユーザーに「オープン」コミュニティを一覧表示するにはどうすればよいでしょうか?

これが私の現在のコードです

#set ($myPlaces = $user.getMyPlaces())
    #if($listTool.size($myPlaces) > 0)

        <select id="communitySelector">

        #foreach ($myPlace IN $myPlaces)
            #if ($myPlace.isCommunity())

                #set ($myPlaceURL = ${myPlace.getFriendlyURL()})
                ## Only link if theres pages
                #if ($myPlace.hasPublicLayouts())
                    ## Prefix web for 'public'
                   #set ($myPlaceURL = "${public_pages_url}${myPlaceURL}")

                   ## Select if current community
                     #set($commSelected = "")
                    #if($themeDisplay.getLayout().getGroup().getName() == $myPlace.getName())
                        #set($commSelected = " selected='selected' ")
                    #end
                    <option $commSelected value="${portal_url}${myPlaceURL.toString()}">$myPlace.getName()</option>


               #end

            #end
        #end
            </select>
    #end
4

1 に答える 1

1

私自身の Liferay の質問に答えるという長い伝統の中で、パブリック/ゲスト ログアウト ユーザーを含むすべてのユーザーにコミュニティを一覧表示するために私が思いついたソリューションのコード スニペットを次に示します。

  ## Grab this service as MyPlaces only available to authenticated users
  #set($groupLocalService =  $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))

  ## Get all Groups
  #set($groupList = $groupLocalService.getGroups(-1, -1))

  ## Grab all groups that are Communities
  #set($commList = [])
  #foreach($group in $groupList)

    #if($group.isCommunity())

        $commList.add($group)
    #end
  #end

  #foreach($comm in $commList)
    ## Exclude Control Panel which is also validated as Community in LR
    #if($comm.getName()!="Control Panel")
        #if($comm.hasPublicLayouts())
            <a href="$comm.getFriendlyURL()">$comm.getName()</a><br />
         #elseif($comm.hasPrivateLayouts() && $is_signed_in)
            ## Community is private so only print this link if user authenticated
            <a href="$comm.getFriendlyURL()">$comm.getName()</a><br />
         #end
    #end
  #end

編集 - これは他の誰かが投稿した同様のスニペットですhttps://stackoverflow.com/a/8457759/417933

于 2012-02-04T07:41:31.220 に答える