How to expose online members data to custom template?

Matthew Hawley

Well-known member
Could someone give me a tutorial on how to expose online members and members count data to a custom template? I'm pretty sure it has something to do with viewparams...

Thanks!
 
There is a table called xf_session which logs the sessions of users online currently.Use that table to join with users and grabs the data about members you require.
 
Also check out the Xenforo Model called Session in the default xf lib. There are a few functions which may help you.
 
Look at on XenForo_ControllerPublic_Forum at line:41
PHP:
'onlineUsers' => $this->_getSessionActivityList(),
And this function:
PHP:
protected function _getSessionActivityList()
    {
        $visitor = XenForo_Visitor::getInstance();

        /** @var $sessionModel XenForo_Model_Session */
        $sessionModel = $this->getModelFromCache('XenForo_Model_Session');

        return $sessionModel->getSessionActivityQuickList(
            $visitor->toArray(),
            array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
            ($visitor['user_id'] ? $visitor->toArray() : null)
        );

    }
I think its useful for you :)
 
Back
Top Bottom