• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

[GP] Template-Helper for Usergroups

Shadab

Well-known member
BASIC USAGE
==============================

The basic syntax for using this helper in a template is:
{xen:helper checkusergroup, $visitor, X}

Replace X with the usergroup id you want to check. This X usergroup ID will be searched in primary as well as secondary usergroups of $visitor. The helper returns TRUE if the $visitor belongs to the usergroup; and FALSE otherwise.


SAMPLE CONDITIONAL
==============================
Code:
<xen:if is="{xen:helper checkusergroup, $visitor, 3}">
	Hello, Administrative user!
</xen:if>


ADVANCED USAGE
==============================

(Most users won't ever need to use this)

The advanced syntax for using this helper is:
{xen:helper checkusergroup, $visitor, <type>, <ids>}

<type> => The usergroup-check type. 3 options are available: ALL (default), PRIMARY, and SECONDARY. ALL is the default type & you don't need to explicitly specify it.

<ids> => A comma-separated list of usergroup ids.

You can pass any number of usergroup ids. The helper returns TRUE if it finds a match for any usergroup id passed. So essentially, the helper works like a boolean OR if multiple ids are passed to it.


ADVANCED SAMPLES
==============================
Code:
<xen:if is="{xen:helper checkusergroup, $visitor, PRIMARY, 3}">
	// User whose primary usergroup is 3
</xen:if>

<xen:if is="{xen:helper checkusergroup, $visitor, SECONDARY, 3}">
	// User whose secondary usergroup list includes 3
</xen:if>

<xen:if is="{xen:helper checkusergroup, $visitor, 1, 2, 3}">
	// User who belongs to usergroup 1 or 2 or 3
</xen:if>

<xen:if is="{xen:helper checkusergroup, $visitor, PRIMARY, 2, 3}">
	// User whose primary usergroup is 2 or 3
</xen:if>

<xen:if is="{xen:helper checkusergroup, $visitor, SECONDARY, 1, 2, 4}">
	// User whose secondary usergroup list includes 1 or 2 or 4.
</xen:if>

<xen:if is="!{xen:helper checkusergroup, $visitor, 1, 2, 3}">
	// User who does NOT belong to any of the listed usergroups
</xen:if>
 

Attachments

RELEASE HISTORY
==============================

Version 1.0 - October 12 2010
  • Initial Release
LICENSE
==============================

Fellow modification authors are free to include this helper in their own addons & products. All I ask is that you leave the Addon directory structure (/GeekPoint/) & the files included therein, unmodified.

The complete license text is available in the LICENSE.txt file inside the release package.

CREDITS
==============================

The credit goes to: dmnkhhn for the original idea posted here. Thanks! :)
 
Is there a conditional for if a user is NOT in a group?
Not straightforward, but for now this would do:
Code:
<xen:if is="!{xen:helper checkusergroup, $visitor, 1, 2, 3}">
	// User who does NOT belong to any of the listed usergroups
</xen:if>
 
Hi,

i got a problem. I use this Addon for an Secand "Staff" List. So I put the following Code under the first / original Staff List Code:

PHP:
<xen:if hascontent="true">
	<div class="section staffOnline avatarList">
		<div class="secondaryContent">
			<h3>Staff 2</h3>
			<ul>
				<xen:contentcheck>
					<xen:foreach loop="$onlineUsers.records" value="$user">
						<xen:if is="{xen:helper checkusergroup, $visitor, 16}">
							<li>
								<xen:avatar user="$user" size="s" img="true" />
								<a href="{xen:link members, $user}" class="username">{xen:helper richUserName, $user}</a>
								<div class="muted">{xen:helper userTitle, $user}</div>
							</li>
						</xen:if>
					</xen:foreach>
				</xen:contentcheck>
			</ul>
		</div>
	</div>
</xen:if>

But this shows me every Registered user online and NOT only User who belongs to Usergroup 16.

Has anybody an idea?

Thanks all!

Benny
 
But this shows me every Registered user online and NOT only User who belongs to Usergroup 16.
Please change:
Code:
<xen:if is="{xen:helper checkusergroup, $visitor, 16}">
to:
Code:
<xen:if is="{xen:helper checkusergroup, $user, 16}">
Because passing the $visitor variable to the helper would check the viewing user's usergroup, and not the user (stored in $user variable) you are looping over.
 
This mod works better for me because I can use groups NOT in a particular group, or vice versa. Also, I think the first post should be updated with the NOT groups just as a quick reference. I easily missed it the first time because I found this through search.

Also, perhaps in the package, put your folder inside a "library" folder. This helps noobs understand where the GeekPoint folder goes.

Thanks for this mod. I can't run my site without it!
 
Top Bottom