[ABD] Group Template Variables

Any abandoned Extensions will be moved to this forum.

WARNING: Extensions in this forum are not currently being supported or maintained by the original Extension author. Proceed at your own risk.
Forum rules
IMPORTANT: Extension Development Forum rules

WARNING: Extensions in this forum are not currently being supported nor updated by the original Extension author. Proceed at your own risk.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

[ABD] Group Template Variables

Post by martti »

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: 1.1.0
Requirements:
  • phpBB 3.3+
  • PHP 7.1+
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 Sun Apr 12, 2020 5:15 am, edited 9 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 »

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 »

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: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti »

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
Kailey
Community Team Leader
Community Team Leader
Posts: 3887
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: [BETA] Group Template Variables

Post by Kailey »

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 Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
Lumpy Burgertushie
Registered User
Posts: 69228
Joined: Mon May 02, 2005 3:11 am

Re: [BETA] Group Template Variables

Post by Lumpy Burgertushie »

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
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
RMcGirr83
Former Team Member
Posts: 22061
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: [BETA] Group Template Variables

Post by RMcGirr83 »

Not meaning to hijack this post but been done already not that anyone would know.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3887
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: [BETA] Group Template Variables

Post by Kailey »

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 Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti »

updated: pending groups are left out correctly now.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti »

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: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti »

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 »

Very sexy. :)
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3887
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: [BETA] Group Template Variables

Post by Kailey »

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 Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: [BETA] Group Template Variables

Post by mrgoldy »

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?
phpBB Studio / Member of the Studio

Contributing: You can do it too! • Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [BETA] Group Template Variables

Post by martti »

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?

Return to “Abandoned Extensions”