[3.2][RC] Group Template Variables

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Suggested Hosts
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
martti
Registered User
Posts: 573
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

[3.2][RC] Group Template Variables

Post by martti » Wed Jul 08, 2015 2:29 pm

Extension Name: Group Template Variables
Author: martti
Extension Description:
The extension provide a template variable for every group the current user is in. They are all put under the template variable marttiphpbb_grouptempvars

I.e:

Code: Select all

{%- if marttiphpbb_grouptempvars.4 -%}
    This content is only visible when the user is in group with id 4.
{%- endif -%}
To list all group ids a user is in:

Code: Select all

<div class="panel">
  <h3>
    all group ids:
  </h3>
  <p>
    {%- for group_id, value in marttiphpbb_grouptempvars -%}
      {{- group_id -}}
    	{%- if not loop.last -%},&nbsp;{%- endif -%}
    {%- endfor -%}
  </p>
</div>
This shows:

Image

In the previous version (for phpBB 3.1) of this extension the variables were available in the form of:

Code: Select all

S_GROUP_ID
Where ID was to be replaced with the id number of the group.
This format is still available but depreciated.

This extension can be used together with my extension Custom Code for inserting custom template code in a non destructive way.

How to determine the group ids?

Extension Version: 0.2.0
Extension Download: https://github.com/marttiphpbb/phpbb-ex ... master.zip
The files are to be put in ext/marttiphpbb/grouptempvars
Github repository: https://github.com/marttiphpbb/phpbb-ext-grouptempvars
Languages: n/a
Templates: n/a (all)
Last edited by martti on Tue Jun 19, 2018 6:24 pm, edited 7 times in total.

User avatar
Mauron
Registered User
Posts: 342
Joined: Wed Jul 16, 2014 11:25 am

Re: [BETA] Group Template Variables

Post by Mauron » Wed Jul 08, 2015 3:58 pm

Good!

User avatar
uruguayito
Registered User
Posts: 266
Joined: Mon Dec 13, 2010 2:46 pm
Location: Montevideo - Uruguay

Re: [BETA] Group Template Variables

Post by uruguayito » Wed Jul 08, 2015 4:42 pm

Interesting extension . Thanks.

Please, tell me: where I put the sentence that you refer to ? (Also I have installed your other extension)
(I don't understand how to do)
I speak spanish
Sorry for my bad english

User avatar
martti
Registered User
Posts: 573
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti » Wed Jul 08, 2015 5:36 pm

uruguayito wrote:Interesting extension . Thanks.

Please, tell me: where I put the sentence that you refer to ? (Also I have installed your other extension)
(I don't understand how to do)
In ACP > Extensions > Custom Code > Edit : choose one of the template event locations.

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1683
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: [BETA] Group Template Variables

Post by kinerity » Wed Jul 08, 2015 11:55 pm

This only grabs the user's primary group - not all groups a user is a member of. It's best to use the group_memberships() function.

Nice idea though. ;)
Kailey Truscott - Community Team

User avatar
Lumpy Burgertushie
Registered User
Posts: 64572
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: [BETA] Group Template Variables

Post by Lumpy Burgertushie » Thu Jul 09, 2015 1:05 am

grabbing all the groups a member is a member of is not needed. this is only for showing or hiding something to one specific group and it works perfectly for that.

actually, it doesn't grab any group IDs , you have to supply the group ID yourself when using it and depending on how you word the switch variable it can apply to multiple groups at once.

robert
I am available for custom work on a donation basis. Please send me a PM with your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20810
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: [BETA] Group Template Variables

Post by RMcGirr83 » Thu Jul 09, 2015 2:32 am

Not meaning to hijack this post but been done already not that anyone would know.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1683
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: [BETA] Group Template Variables

Post by kinerity » Thu Jul 09, 2015 4:53 am

Lumpy Burgertushie wrote:grabbing all the groups a member is a member of is not needed. this is only for showing or hiding something to one specific group and it works perfectly for that.

actually, it doesn't grab any group IDs , you have to supply the group ID yourself when using it and depending on how you word the switch variable it can apply to multiple groups at once.
I'm well aware of how this extension works. ;) I think you might have missed my point though. If you look at the code, they are grabbing the group_id from the users table, which is used to designate the primary group. An example: I am a member of group 1, 2, and 5, with my primary group being group 1. Using this extension, if I try to display something to members of group 2 only (using an <!-- IF S_GROUP_2 --> switch), I would expect it to show for me also, but it won't because it doesn't take into account the user_group table. This is why the group_memberships() function would be a better fit.
RMcGirr83 wrote:Not meaning to hijack this post but been done already not that anyone would know.
I certainly didn't know. :P
Kailey Truscott - Community Team

User avatar
martti
Registered User
Posts: 573
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti » Thu Jul 09, 2015 5:58 am

updated: pending groups are left out correctly now.

User avatar
martti
Registered User
Posts: 573
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti » Thu Jul 09, 2015 6:50 am

kinerity wrote: I'm well aware of how this extension works. ;) I think you might have missed my point though. If you look at the code, they are grabbing the group_id from the users table, which is used to designate the primary group. An example: I am a member of group 1, 2, and 5, with my primary group being group 1. Using this extension, if I try to display something to members of group 2 only (using an <!-- IF S_GROUP_2 --> switch), I would expect it to show for me also, but it won't because it doesn't take into account the user_group table. This is why the group_memberships() function would be a better fit.
Have a closer look and see it's the USER_GROUP_TABLE that's being fetched from.

Code: Select all

		$sql = 'SELECT group_id 
			FROM ' . USER_GROUP_TABLE . '
			WHERE user_id = ' . $user_id . '
				AND user_pending = 0';
		$result = $this->db->sql_query($sql);
		while ($group_id = $this->db->sql_fetchfield('group_id'))
		{
			$template_vars['S_GROUP_' . $group_id] = true;
		}
https://github.com/marttiphpbb/phpbb-ex ... hp#L61-L71

We don't want to use the group_memberships() function because it JOINs the USER_TABLE and the USER_GROUP_TABLE and fetches all the colums of the USER_GROUP_TABLE and the username, username_clean and user_email columns of the USER_TABLE. But we are simply after all the group ids of the current user. It doesn't make sense to fetch all that data just to throw it away.
https://github.com/phpbb/phpbb/blob/dc8 ... .php#L3495
kinerity wrote:
RMcGirr83 wrote:Not meaning to hijack this post but been done already not that anyone would know.
I certainly didn't know. :P
I didn't either. But I like my solution without the group_memberships() function more.

Edit: replaced the link to group_memberships() with a permalink.
Last edited by martti on Fri Apr 27, 2018 4:34 am, edited 2 times in total.

User avatar
martti
Registered User
Posts: 573
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti » Thu Jul 09, 2015 7:48 am

ALL groups have a template variable. The rumours are not true.

Code: Select all

<!-- check group variables -->
<p>
<!-- IF S_GROUP_5 --> 
    You're in the admin group.
<!-- ELSE --> 
    You're NOT in the admin group.
<!-- ENDIF -->
</p>
<p>
<!-- IF S_GROUP_4 --> 
    You're in the global moderators group.
<!-- ELSE --> 
    You're NOT in the global moderators group.
<!-- ENDIF -->
</p>
Logged in as the board owner:
Image
Logged in as a normal user:
Image

User avatar
Mess
Registered User
Posts: 985
Joined: Wed Jul 01, 2009 6:37 am
Name: Kim

Re: [BETA] Group Template Variables

Post by Mess » Thu Jul 09, 2015 9:39 am

Very sexy. :)

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1683
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: [BETA] Group Template Variables

Post by kinerity » Thu Jul 09, 2015 1:07 pm

martti wrote:Have a closer look and see it's the USER_GROUP_TABLE that's being fetched from
I swear it didn't say that earlier! :lol: I apologize then. :oops:
Kailey Truscott - Community Team

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: [BETA] Group Template Variables

Post by posey » Thu Oct 01, 2015 1:02 pm

Hello,

I was wondering if I could use something similar in the Pages extension. I created a page and parsed the HTML with this extension enabled. I had part in the page: <!-- IF S_GROUP_1 -->This is only visible for guests<!-- ENDIF--> However, all registered members and administrators could see it. Is there any chance this does not work in the html parsing of the Pages extension?
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
martti
Registered User
Posts: 573
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti » Thu Oct 01, 2015 1:49 pm

posey wrote:Hello,

I was wondering if I could use something similar in the Pages extension. I created a page and parsed the HTML with this extension enabled. I had part in the page: <!-- IF S_GROUP_1 -->This is only visible for guests<!-- ENDIF--> However, all registered members and administrators could see it. Is there any chance this does not work in the html parsing of the Pages extension?
Do you see the tag <!-- IF S_GROUP_1-->? If so, then it is not working. If not, maybe your registered members and administrators also belong to the guests group?

Post Reply

Return to “Extensions in Development”

Who is online

Users browsing this forum: Hippie459MN, jan_2017 and 22 guests