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

Getting user group ids without any additional queries

Discussion in 'XenForo Development Discussions' started by Cyb3r, Sep 11, 2015.

  1. Cyb3r

    Cyb3r Well-Known Member

    I'm overriding Core function "helperRichUserName" but it seems not all attributes are provided in the $user array, I tried to check "is_staff" and usergroup ids but didn't work, so I tried to create a model for the user by user id:
    PHP:
    $full_user XenForo_Model::create('XenForo_Model_User')->getUserById($user['user_id']);
    It worked but the queries has doubled, so I was wondering if there's a function that extract only usergroup ids and check it by user_id.
     
  2. Cyb3r

    Cyb3r Well-Known Member

    Never mind I got it working by checking the display_style_group_id which return the highest level usergroup which was exactly what I need, here is the code for future reference if anyone interested in:
    PHP:
    if($user['display_style_group_id'] == '13')
    {
       
    // Do something here
    }
    Change 13 to the usergroup you want to match, if you want more than one group use in_array, here's an example:
    PHP:
    if (in_array($user['display_style_group_id'], array('13','3')))
    {
       
    // Here goes your code
    }

    - Cyb3r
     

Share This Page