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

User Group questions

Discussion in 'XenForo Development Discussions' started by Robin De Schepper, Sep 8, 2013.

  1. Robin De Schepper

    Robin De Schepper New Member

    Hey, how can I let my addon;
    A) Create a new user group
    B) Assign users to it
    C) Check whether someone is in that user group?
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    1) XenForo_DataWriter_UserGroup
    2) Use a user group promotion, it'll be the easiest. Here's a snippet from my license validation code:
    PHP:
    <?php
            $userModel 
    XenForo_Model::create('XenForo_Model_User');
            
    $userModel->removeUserGroupChange($userId'xiLicenseValidationValidated'); // remove the record so that if they aren't in the group, they'll be promoted.
            
    $userModel->addUserGroupChange($userId'xiLicenseValidationValidated'XenForo_Application::get('options')->xilicensevalidationGroup);
    3. Where are you checking user group membership?
     
  3. Robin De Schepper

    Robin De Schepper New Member

    1) Could you post a little example snippet? If it's too much I'll just try to figure it out myself.
    3) Either inside a ControllerPublic action or View's renderHtml.
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    If you are checking it inside of a view, you should just use the xen helper ismemberof. See Brogan's resource, he explains how to use it. As for creating it, you should look into how XenForo_ControllerAdmin_UserGroup::actionSave() uses XenForo_DataWriter_UserGroup.
     

Share This Page