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

How do I create a list of members in particular usergroups on a page node?

Discussion in 'XenForo Development Discussions' started by Stuart Wright, Dec 10, 2013.

  1. Stuart Wright

    Stuart Wright Well-Known Member

  2. Brogan

    Brogan XenForo Moderator Staff Member

    If you want to have separate tabs and pull lots of statistics related to each advertiser then it will require a php callback and some custom code.
     
  3. Stuart Wright

    Stuart Wright Well-Known Member

    Don't need the tabs Brogan, just a single (standard) list of members from a couple of usergroups with some pretty HTML top and bottom.
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    How will the members be selected?
    If you're doing it manually then it's just a case of constructing the HTML and CSS depending on how you want to present the content.

    For the most part you can use core classes and structure, assuming you want similar appearance to other pages.
     
  5. Stuart Wright

    Stuart Wright Well-Known Member

    select * from user where secondaryusergroupid in (1,2) order by username
     
  6. xf_phantom

    xf_phantom Well-Known Member

    You could also use
    PHP:
    $criteria = array(
      
    'secondary_group_ids' => array(1,2)
      );
    $options = array(
           
    'join' => XenForo_Model_User::FETCH_USER_FULL,
           
    'order' => 'username'
         
    ));
      
    $users $this->getModelFromCache('XenForo_Model_User')->getUsers($criteria$options);

     
    Last edited: Dec 10, 2013
  7. Stuart Wright

    Stuart Wright Well-Known Member

    ^ This is in a php callback and then I loop in the template?
     
  8. xf_phantom

    xf_phantom Well-Known Member

    yes, my above code into the callback.

    You'll have to replace $this from $this->getModelFromCache('XenForo_Model_User')
    with the variable name you're using for the controller parameter;)
     
  9. Jeremy

    Jeremy XenForo Moderator Staff Member

    You will never be able to run raw PHP in templates. Unless its xen:* syntax or it is a whitelisted function, you won't be able to run them.
     
  10. Matthew Hawley

    Matthew Hawley Well-Known Member

  11. Stuart Wright

    Stuart Wright Well-Known Member

  12. Stuart Wright

    Stuart Wright Well-Known Member

    I'm getting an error. What do I put instead of $this?
    PHP:
    class AVForums_AdvertiserList_ControllerPublic_AdvertiserList
    {
        public static function 
    getAdvertiserList(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_Abstract &$response)
        {


        
    $criteria = array(
            
    'secondary_group_ids' => array(10,13,16)
          );
        
    $options = array(
            
    'join' => XenForo_Model_User::FETCH_USER_FULL,
            
    'order' => 'username'
        
    );
        
    $users $this->getModelFromCache('XenForo_Model_User')->getUsers($criteria$options);

        
    print_r($users);
        
    $pageout "";
        
    $response->params['pageout'] = $pageout;
           
        }
    }
     
    Last edited: Dec 12, 2013
  13. xf_phantom

    xf_phantom Well-Known Member

    Post your code:D
     
  14. Stuart Wright

    Stuart Wright Well-Known Member

    Posted in an edit ^. Just want to see what's in the $users array to start off with.
     
  15. xf_phantom

    xf_phantom Well-Known Member

    PHP:
    $controller->getModelFromCache('XenForo_Model_User'
    instead of
    PHP:
    $this->getModelFromCache('XenForo_Model_User'
     
  16. Stuart Wright

    Stuart Wright Well-Known Member

    Lovely, thank you :)
    Is there a template I can use in the php script to format each user in a row like in the notable members list please?
     
  17. xf_phantom

    xf_phantom Well-Known Member

    Code:
    
    <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>
     
  18. Matthew Hawley

    Matthew Hawley Well-Known Member

    It does.
     
  19. Stuart Wright

    Stuart Wright Well-Known Member

    I have created control over the display in my own page though matthew and it's coming along, thanks everyone.
    I've created a sidebar and put the users online and stats boxes in it, but they both contain null data.
    I'm guessing I have to call getInstance() or something to populate them.
    I looked around but couldn't find an answer.
    HTML:
    <xen:sidebar>
        <xen:edithint template="sidebar.css" />
        <xen:hook name="forum_list_sidebar">
        </xen:hook>
        <xen:include template="sidebar_online_users" />
    
        <div class="section">
            <div class="secondaryContent statsList" id="boardStats">
                <h3>{xen:phrase forum_statistics}</h3>
                <div class="pairsJustified">
                    <dl class="discussionCount"><dt>{xen:phrase discussions}:</dt>
                        <dd>{xen:number $boardTotals.discussions}</dd></dl>
                    <dl class="messageCount"><dt>{xen:phrase messages}:</dt>
                        <dd>{xen:number $boardTotals.messages}</dd></dl>
                    <dl class="memberCount"><dt>{xen:phrase members}:</dt>
                        <dd>{xen:number $boardTotals.users}</dd></dl>
                    <dl><dt>{xen:phrase latest_member}:</dt>
                        <dd><a href="{xen:link members, $boardTotals.latestUser}" class="username">{$boardTotals.latestUser.username}</a></dd></dl>
                </div>
            </div>
        </div>
    </xen:sidebar>
    
     
  20. borbole

    borbole Well-Known Member

    In your php file add this code:

    PHP:
    $visitor XenForo_Visitor::getInstance();

    $sessionModel $this->getModelFromCache('XenForo_Model_Session');

    $onlineUsers $sessionModel->getSessionActivityQuickList(
                
    $visitor->toArray(),
                array(
    'cutOff' => array('>'$sessionModel->getOnlineStatusTimeout())),
                (
    $visitor['user_id'] ? $visitor->toArray() : null)
            );
        
            
    $boardTotals $this->getModelFromCache('XenForo_Model_DataRegistry')->get('boardTotals');
            if (!
    $boardTotals)
            {
                
    $boardTotals $this->getModelFromCache('XenForo_Model_Counters')->rebuildBoardTotalsCounter();
            }
    Then register the $onlineUsers and $boardTotals vars for use in your custom template.

    PHP:
    $response->params['onlineUsers'] = $onlineUsers;
    $response->params['boardTotals'] = $boardTotals;
     

Share This Page