Fórum

How to get the site type with the api (public, restricted etc.)

Jack Palm, modificado 8 Anos atrás.

How to get the site type with the api (public, restricted etc.)

Junior Member Postagens: 28 Data de Entrada: 13/04/15 Postagens Recentes
I have been looking around but found nothing, read the documentation and so on..

I have a group object:

Group group = GroupLocalServiceUtil.getGroup(groupId);

The group id is correct, already used it to retrive the users and it works, and from the current site.. But from here on I do not find any solution to find out the site type with my group object?

I need to know if the current site / group is Open, Public Restricted, Private Restricted or Private! How can I get this in code?

Thank you in advance
thumbnail
Andew Jardine, modificado 8 Anos atrás.

RE: How to get the site type with the api (public, restricted etc.) (Resposta)

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hi Jack,

Are you referring to the type_ column on the Group table? You can have a look at the com.liferay.portal.model.GroupConstants class and you will find in there


        public static final int TYPE_SITE_OPEN = 1;
	public static final String TYPE_SITE_OPEN_LABEL = "open";
	public static final int TYPE_SITE_PRIVATE = 3;
	public static final String TYPE_SITE_PRIVATE_LABEL = "private";
	public static final int TYPE_SITE_RESTRICTED = 2;
	public static final String TYPE_SITE_RESTRICTED_LABEL = "restricted";
	public static final int TYPE_SITE_SYSTEM = 4;
	public static final String TYPE_SITE_SYSTEM_LABEL = "system";
	public static final String USER_PERSONAL_SITE = "User Personal Site";


Once you have your Group object, you should be able to retrieve the type using the getType() method. You can then use the GroupConstants.getTypeLabel( int ) method to get the string version if that is what you are after.
Jack Palm, modificado 8 Anos atrás.

RE: How to get the site type with the api (public, restricted etc.)

Junior Member Postagens: 28 Data de Entrada: 13/04/15 Postagens Recentes
Thanks this were the method I were looking for! I have something called social office installed with my Liferay, that is why we have four types:

Open, Public Restricted, Private Restricted, Private

Maybe you know where I can find some nice documentation online for membership request for social office?
thumbnail
Andew Jardine, modificado 8 Anos atrás.

RE: How to get the site type with the api (public, restricted etc.)

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hey Jack,

The different types of sites actually goes back a little farther than social office (as far as I know anyway). If you go back a few versions in liferay you will find that "sites" were once referred to as "communities". The properties you have listed (Open, Public Restricted, Private Restricted, Private) were essentially the membership types. Public of course means anyone can see if and anyone can "join". Public restricted meant that anyone could SEE the community, but that member ship had to be requested. Private restricted goes a step further in that the existence was hidden. To join private restricted you had to basically be "invited" to become a member. Private is pretty self explanatory.

I'm not entirely sure what your question is regarding membership. Can you provide some more details?
Jack Palm, modificado 8 Anos atrás.

RE: How to get the site type with the api (public, restricted etc.)

Junior Member Postagens: 28 Data de Entrada: 13/04/15 Postagens Recentes
Ok, now I understand emoticon Thank you. I have only been using liferay for two weeks, still learning.

Well since I were coding the membership functions from a portlet I needed to make a difference between public restricted and private restricted since the portlet were going to have different functionallities for these two. But when a user joined the group both public restricted and private restricted returned as int of 2 with getType method, because of this I could not make a difference.

Anyway, I solved it in another way so thank you very much for the support!
thumbnail
Andew Jardine, modificado 8 Anos atrás.

RE: How to get the site type with the api (public, restricted etc.)

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hey Jack,

If you get a minute maybe you can share with us the problem you were trying to solve, and how you solved it. This way, if anyone else comes along looking for details on the same, or a similar problem -- this post might help them as well emoticon
Jack Palm, modificado 8 Anos atrás.

RE: How to get the site type with the api (public, restricted etc.)

Junior Member Postagens: 28 Data de Entrada: 13/04/15 Postagens Recentes
Well, I didnt realy "solve" it, but, I realised that when a group is private restricted, the portlet were not going to show if you were not a member (because of this I never needed a request button for this group), I can share my code for displaying different buttons for different users and group types and maybe it will be easier for someone to do the same:

	public void chooseButton(RenderRequest renderRequest, long groupId, ThemeDisplay themeDisplay){
		
		try {
			
			Group group = GroupLocalServiceUtil.getGroup(groupId);
			typeOfGroup = group.getType();
			
		} catch (PortalException | SystemException e2) {
			e2.printStackTrace();
		}
		
		try {
			
			isUserMember = UserLocalServiceUtil.hasGroupUser(groupId, themeDisplay.getUserId());
		
		} catch (SystemException e1) {
			e1.printStackTrace();
		}
		
		if(isUserMember){

			renderRequest.setAttribute("codeButton", "1");
			
		}else{
			
			if(typeOfGroup == 1){

				renderRequest.setAttribute("codeButton", "2");
			
			}else if(typeOfGroup == 2){
				
				renderRequest.setAttribute("codeButton", "3");
				
			}
			
		}
		
	}


Code for the buttons to work and show the correct button depending on group and membership type:

<%String requestMessage = (String)request.getAttribute("requestMessage");%>

<%String codeButton = (String)renderRequest.getAttribute("codeButton");%>

<% if(codeButton == "1"){ %>
<form class="formDisplay" method="post" action="<%=leaveURL %>">
<button type="submit">Leave group</button>
</form>
&lt;% }else if(codeButton == "2"){ %&gt;
<form class="formDisplay" method="post" action="<%=joinURL %>">
<button type="submit">Join group</button>
</form>
&lt;% }else if(codeButton == "3" &amp;&amp; requestMessage != "4"){ %&gt;
<form class="formDisplay" method="post" action="<%=sendRequestURL %>">
<button type="submit">Request membership</button>
</form>
&lt;% }else if(codeButton == "3" &amp;&amp; requestMessage == "4"){ %&gt;
<form class="formDisplay" method="post" action="">
<button type="button">Request sent</button>
</form>
&lt;% } %&gt;