1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Xen code for showing group labels?

Discussion in 'XenForo Development Discussions' started by dutchbb, Oct 8, 2010.

  1. dutchbb

    dutchbb Well-Known Member

    Does anyone know the xen code for showing group labels based on the usergroup?
  2. dmnkhhn

    dmnkhhn Active Member

    Inside a model you need to get the UserGroup model first.
         * @return XenForo_Model_UserGroup
    protected function _getUserGroupModel() {

    and inside your method you can then use:

    $myId 10;
    $userGroup $this->_getUserGroupModel()->getUserGroupById($myId);
    This will get you all information about a usergroup with a certain Id. :)

    You probably want to check what information it contains by doing
    print_r ($userGroup);
  3. dutchbb

    dutchbb Well-Known Member

    Wow I'm no coder :p Is all that needed? I need the equivalent of this to use in message_user_info template:

    <if condition="is_member_of($post,6)">
    <img src="images/groups/admin.gif" width="128" height="25" border="0" alt="Administrator" class="grouptag" />
  4. dmnkhhn

    dmnkhhn Active Member

    Oh I see. :)

    That should be easier to accomplish, hold on. ;)

    It seems to be more complicated than I thought.

    Here is how I would do it (theoretically):

    Extend the XenForo_Template_Helper_Core class.
    This class contains an array ($helperCallbacks) that maps a template helper to a callback (callback = method like helperUserGroup or whatever you call it)
    This array needs a new key that maps the (newly created) usergroup helper to a callback. This callback takes the $user and the usergroup in question as an argument and returns 1 if the user is in this usergroup and a 0 if he is not.
    To get that information we need to use a the UserGroup model and the getUserIdsInUserGroup() method.

    If that works you can use {xen:helper userGroup, $user, 6} to find out wether this user belongs to group 6 or not.

    I have not tried it and I would love to hear what the experts say. :)
  5. Shadab

    Shadab Well-Known Member

    <xen:if is="{$visitor.user_group_id} == 3">
    	Hi Administrator.
    Note that user_group_id only stores the primary usergroup id of a user; so you are only comparing the primary usergroup in the code above. Secondary usergroup id's are stored as a comma separated list in the secondary_group_ids field; but I haven't come across any native template helper that we can use here.

    Interesting approach. Off to try it right now. :)

    Wait. Just checked and found my primary usergroup is "Registered", and "Administrative" + "Moderating" are set as my secondary groups, by default. That's strange. The code given above wouldn't work.
  6. ragtek

    ragtek Guest

    in vB we had is_member_of for this^^
    ATM i couldn't find anything similar here
  7. dutchbb

    dutchbb Well-Known Member

    Going to try this now. Thanks.

    Yes it seems we can only use a rank image for primary groups then? I know by default the Admin account is in the Registered group, you have to change that after installation.
  8. Shadab

    Shadab Well-Known Member

Share This Page