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

User fields in custom user list

Discussion in 'XenForo Development Discussions' started by TRGCommunity, Apr 13, 2016.

  1. TRGCommunity

    TRGCommunity Active Member

    Hey guys,

    I'll keep it short. I created a page with a callback, here's the PHP:

    PHP:
    <?php

    class TRG_Memberlist_Users
    {
        public static function 
    getSupporters(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_Abstract &$response)
        {


        
    $criteria = array(
            
    'secondary_group_ids' => array(9)
          );
        
    $options = array(
            
    'join' => XenForo_Model_User::FETCH_USER_FULL,
            
    'order' => 'username'
        
    );
       
        
    $users $controller->getModelFromCache('XenForo_Model_User')->getUsers($criteria$options);

        
    $response->params['users'] = $users;
           
        }
    }
    And this is the template:

    HTML:
    <ol class="section memberList">
       <xen:foreach loop="$users" value="$user">
         <xen:include template="member_list_item">
           <xen:set var="$noOverlay">1</xen:set>
         </xen:include>
       </xen:foreach>
    </ol>
    That works great, but now I would like to get the value of a custom user field. I found Jake's solution in a thread: https://xenforo.com/community/threa...message_user_info-template.20792/#post-314978

    Unfortunately I have no idea where to put the code into my PHP file, is there anyone who could point me into the right direction?

    Thanks in advance! :)

    Moritz
     
  2. TRGCommunity

    TRGCommunity Active Member

  3. wang

    wang Well-Known Member

    I think that with the code that you have, you can use the example mention at that other topic, to display the value of users custom fields. If you want to exlude invalid and banned users, like in the example from that other code, add those values to your own $criteria array. Like so:

    PHP:
    $criteria = array(
                
    'user_state' => 'valid',
                
    'is_banned' => 0,
                
    'secondary_group_ids' => 9
            
    );
    In your case, you are pulling info for users that belong to only one certain secondary group, and you do not need to array it. You can array the second group ids when you want to use more than one id.

    And then you can use the example mention at that other topic, to display the value of users custom fields.
     
  4. TRGCommunity

    TRGCommunity Active Member

    Hello wang,

    thank you very much for your kind reply :)
    I forgot to mention, that I meanwhile added more usergroup IDs, so my PHP looks like this:

    PHP:
    <?php

    class TRG_Memberlist_Users
    {
        public static function 
    getUsers(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_Abstract &$response)
        {

        
    $criteria = array(
            
    'user_group_id' => array (3,4,5,45,30)
          );
        
    $options = array(
            
    'join' => XenForo_Model_User::FETCH_USER_FULL,
            
    'order' => 'username'
        
    );
       
        
    $users $controller->getModelFromCache('XenForo_Model_User')->getUsers($criteria$options);

        
    $response->params['users'] = $users;   

        }
    }
    Now there is still the problem, that it doesn't work when I add
    PHP:
    $users $userModel->prepareUserCards($users);
    I'm still a beginner with PHP, so please apologize my questions :(
     
  5. wang

    wang Well-Known Member

    That is because you do not have defined the user model. But you can add it with the controller. Like so:

    PHP:
    $users $controller->getModelFromCache('XenForo_Model_User')->prepareUserCards($users);
     
  6. TRGCommunity

    TRGCommunity Active Member

    Okay, thank you, it stopped displaying errors and I think that's quite good :)

    I now tried to wrap a text in the following conditionals to check a specific user field, but for some reason it doesen't work:

    PHP:
    <xen:if is="{xen:helper userFieldValue, $userFieldsInfo.rank, $user{$user.customFields.rank}} == 'Premium-Supporter' ">
       
    Text to show
    </xen:if>
    Is there something wrong?
     

Share This Page