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

changing the way threads are sorted... possible?

petertdavis

Well-known member
#1
On several of my forums we have active marketplace sections, where people can post a classified ad type post to buy, sell, or trade items. Using vBulletin, the way I've prevented excessive thread bumping from being an issue is to make the "Default Sort Field" by the thread start time, not the last post. Thus, a member can reply all they want and the thread doesn't get bumped. I've looked in my Xenforo sites and found no option like it. Am I overlooking something, or does it really not exist? Seems like an easy feature to add into the mix, and one that I rely upon.
 
R

ragtek

Guest
#2
You can do this with an add-on.

Extend/Overwrite XenForo_ControllerPublic_Forum->_getDefaultThreadSort

e.g.
PHP:
    protected function _getDefaultThreadSort(array $forum)
    {

        $bazarNodes = Ragtek::options('bazarnodes')->toArray();

        if (!in_array($forum['node_id'], $bazarNodes)){
            return array('post_date',  'asc');
        }
        return array('last_post_date',  'desc');
    }
hope this helps:)
 

gldtn

Well-known member
#3
How would I go about extending Xenforo Controller Public? I've tried following this tutorial http://xenforo.com/community/threads/how-to-add-more-actions-to-an-existing-controller.11202/

I than created an Code Event Listener, it went threw, but there must be something wrong with my code because it's taking no affect :/

Forum.php
PHP:
<?php
 
class CM_ControllerPublic_Forum extends XFCP_CM_ControllerPublic_Forum
{
    protected function _getDefaultThreadSort(array $forum)
    {
        if (!in_array($forum['138'])){
            return array('title', 'desc');
        }
        return array('last_post_date', 'desc');
    }
}
Listener.php
PHP:
<?php
 
class CM_Listener_Listener
{
    public static function extendForumController($class, array &$extend)
    {
        if ($class == 'Xenforo_ControllerPublic_Forum')
        {
            $extend[] = 'CM_ControllerPublic_Forum';
        }
    }
}
 
R

ragtek

Guest
#6
hm, could you post again the complete code you're using?

and are you sure that the event listner is active?*g*
 

gldtn

Well-known member
#7
hm, could you post again the complete code you're using?

and are you sure that the event listner is active?*g*
Yes, it's active acording to the ACP:
code_event.JPG

and under
Code Event Listeners


list it's ticked on.

CM_Listener_Listener:
PHP:
<?php
 
class CM_Listener_Listener
{
    public static function extendForumController($class, array &$extend)
    {
        if ($class == 'Xenforo_ControllerPublic_Forum')
        {
            $extend[] = 'CM_ControllerPublic_Forum';
        }
    }
}
CM_ControllerPublic_Forum:
PHP:
<?php
 
class CM_ControllerPublic_Forum extends XFCP_CM_ControllerPublic_Forum
{
    protected function _getDefaultThreadSort(array $forum)
    {
        if ($forum['node_id'] == '138'){
            return array('title', 'desc');
        }
        return array('last_post_date', 'desc');
    }
}
 
#8
I was having a similar issue, your error is in the listener. You missed a capital letter:

PHP:
        if ($class == 'Xenforo_ControllerPublic_Forum')
        {
            $extend[] = 'CM_ControllerPublic_Forum';
        }
Should be:

PHP:
        if ($class == 'XenForo_ControllerPublic_Forum')
        {
            $extend[] = 'CM_ControllerPublic_Forum';
        }
It should work afterwards.

Jose R. Lopez