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

How to update pagination after filtering.

Discussion in 'XenForo Development Discussions' started by arms, Apr 3, 2014.

  1. arms

    arms Active Member

    I'm trying to filter my thread list by tags.

    upload_2014-4-3_13-0-59.png

    If i filter by tag 4 (i know there is 4 entries in that forum category), I get the correct number of threads but it doesn't update the pagination(still showing 1 to 4 of 24 threads)

    Anyone know how i refresh the pagination to show correctly.

    PHP:
    <?php


    class PG_Filter_XenForo_Model_Thread extends XFCP_PG_Filter_XenForo_Model_Thread
    {
        
    /**
         *
         * @see XenForo_Model_Thread::prepareThreadFetchOptions()
         */
        
    public function prepareThreadFetchOptions(array $fetchOptions)
        {
            
    $threadFetchOptions parent::prepareThreadFetchOptions($fetchOptions);

            
    $joinTables $threadFetchOptions['joinTables'];

            if (isset(
    $fetchOptions['ThreadTagId'])) {
                if (!empty(
    $fetchOptions['ThreadTagId'])) {
                    
    $joinTables .= '
                        INNER JOIN xf_tinhte_xentag_tagged_content AS xentag_tagged_content
                            ON (xentag_tagged_content.content_id = thread.thread_id
                            AND xentag_tagged_content.tag_id IN ( ' 
    .
                         
    $this->_getDb()->quote($fetchOptions['ThreadTagId']) . '))';
                }
            }

            return array(
                
    'selectFields' => $threadFetchOptions['selectFields'],
                
    'joinTables' => $joinTables,
                
    'orderClause' => $threadFetchOptions['orderClause']
            );
        }
    PHP:
    PHP:
    <?php

    class PG_Filter_XenForo_ControllerPublic_Forum extends XFCP_PG_Filter_XenForo_ControllerPublic_Forum
    {

    public function 
    actionForum()
        {
            
    $response parent::actionForum();

        
            if (isset(
    $response->params['pageNavParams']['ThreadTagId'])) {
                
    $response->params['ThreadTagId'] = $response->params['pageNavParams']['ThreadTagId'];
             
    //unset($response->params['pageNavParams']['ThreadTagId']);
           
    }
         
            return 
    $response;
        } 
    /* END actionForum */

    /**
         *
         * @see XenForo_ControllerPublic_Forum::_getThreadFetchElements()
         */
        
    protected function _getThreadFetchElements(array $forum, array $displayConditions)
        {
            
    $fetchElements parent::_getThreadFetchElements($forum$displayConditions);

            if (isset(
    $displayConditions['ThreadTagId'])) {
                
    $fetchElements['options']['ThreadTagId'] = $displayConditions['ThreadTagId'];
            }

            return 
    $fetchElements;
        } 
    /* END _getThreadFetchElements */

        /**
         *
         * @see XenForo_ControllerPublic_Forum::_getDisplayConditions()
         */
        
    protected function _getDisplayConditions(array $forum)
        {
            
    $displayConditions parent::_getDisplayConditions($forum);

            
    $mytags $this->_input->filterSingle('tag_id'XenForo_Input::STRING);
        
            if (
    $mytags) {
            
                
    $displayConditions['ThreadTagId'] = $mytags;
                }

            return 
    $displayConditions;
        }
     
    Last edited: Apr 3, 2014
  2. Valhalla

    Valhalla Well-Known Member

    I'm not sure if this will help, but your actionForum() doesn't have any specified viewParams for 'totalThreads' or 'threadsPerPage'.

    You may need to state these with your new fetch conditions.
     
    Last edited: Apr 3, 2014
  3. arms

    arms Active Member

    Thanks for reply @Valhalla . Its got me tearing my hair out.

    I'll try update totalThreads
     
    Valhalla likes this.

Share This Page