1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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

Discussion in 'Add-on Releases [Archive]' started by Shadab, Oct 12, 2010.

  1. Shadab

    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>
     

    Attached Files:

    gldtn, EQnoble, Darkimmortal and 10 others like this.
  2. Shadab

    Shadab Well-Known Member

    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! :)
     
    José Guedes likes this.
  3. ragtek

    ragtek Guest

    Nice one:)
     
    Shadab likes this.
  4. Brentnauer

    Brentnauer Well-Known Member

    Is there a conditional for if a user is NOT in a group?
     
  5. Shadab

    Shadab Well-Known Member

    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>
     
  6. g0rn

    g0rn Well-Known Member

    Thanks! This definitely should be included in XenForo distribution.
     
    Shadab likes this.
  7. pjfry

    pjfry Active Member

    Awesome :) Thanks!
     
    Shadab likes this.
  8. Rob

    Rob Well-Known Member

    +1
     
  9. Shanj

    Shanj Well-Known Member

    Um - what does this do?
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    Checks to see if a user is in the specified groups.
     
    Shanj likes this.
  11. karrott

    karrott Active Member

    Very nice! I'll be sure to install this. :)
     
  12. pjfry

    pjfry Active Member

    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="$usersize="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
     
  13. Shadab

    Shadab Well-Known Member

    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.
     
    José Guedes and pjfry like this.
  14. pjfry

    pjfry Active Member

    Thanks a lot! Work great for me!
     
    Shadab likes this.
  15. Shadab

    Shadab Well-Known Member

    Glad to hear that! :)
     
  16. José Guedes

    José Guedes Active Member

    Worked great to add images to usergroups.

    Great add-on!
     
    Shadab likes this.
  17. Shadab

    Shadab Well-Known Member

  18. Xarcell

    Xarcell Well-Known Member

    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!
     
  19. Luke F

    Luke F Well-Known Member

    Thanks, very handy :)
     

Share This Page