1. 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?

Discussion in 'XenForo Questions and Support' started by petertdavis, Jan 29, 2012.

  1. petertdavis

    petertdavis Well-Known Member

    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.
     
  2. ragtek

    ragtek Guest

    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:)
     
    petertdavis likes this.
  3. gldtn

    gldtn Well-Known Member

    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';
            }
        }
    }
     
  4. ragtek

    ragtek Guest

    if ($forum['node_id'] == '138'){

    and not
    if (!in_array($forum['138'])){
     
    gldtn likes this.
  5. gldtn

    gldtn Well-Known Member

    There must be something with the listener then because it's not having any effect on any of the nodes :/
     
  6. ragtek

    ragtek Guest

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

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

    gldtn Well-Known Member

    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. momon

    momon Member

    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
     

Share This Page