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

Model Thread Extending ?

Discussion in 'XenForo Development Discussions' started by arms, Sep 12, 2013.

  1. arms

    arms Active Member

    Excuse if this seems really basic :notworthy:

    I've extend the thread model (with reference to this: http://xenforo.com/community/threads/need-to-join-table-with-xf_thread-can-i.21557/#post-272533)

    I've used:

    PHP:
      class PGArms_Model_Thread extends XFCP_PGArms_Model_Thread
    {
         
        public function 
    prepareThreadFetchOptions(array $fetchOptions)
          {
        
    // CALL ORIGINAL
            
    $threadFetchOptions parent::prepareThreadFetchOptions($fetchOptions);
         
    // ADD YOUR OWN JOINS Left join table 
            
    if(!empty($fetchOptions['join']) )
            {
                
    $threadFetchOptions['selectFields'] .= ',
                    dates.start_date, dates.closing_date'
    ;
                
    $threadFetchOptions['joinTables'] .= '
                    LEFT JOIN pg_dates AS dates ON
                    (thread.thread_id = dates.thread_id)'
    ;
            }            
            return 
    $threadFetchOptions;
        }
    }
    Which works, and is picking up extra fields.

    BUT, how do i get this to only run only within specified nodes? Or doesn't it really have an impact due to the left join?
     
  2. Nobita.Kun

    Nobita.Kun Well-Known Member

    In case condition you should added: $conditions['node_id'] = $specialNodeId ;)
     
    arms likes this.
  3. arms

    arms Active Member

    So I need to Extend prepareThreadConditions also?
     
  4. Nobita.Kun

    Nobita.Kun Well-Known Member

    No. This function already You can using that
    Code:
    $conditions = array(
    'node_id' => $specialNodeId
    );
     
  5. arms

    arms Active Member

    Not sure where to add $conditions.
    public function prepareThreadFetchOptions(array $conditions, array $fetchOptions) isn't valid.

    I've tried:

    PHP:
    class PGArms_Model_Thread extends XFCP_PGArms_Model_Thread
    {
          public function 
    prepareThreadFetchOptions(array $fetchOptions)
          {
        
    // CALL ORIGINAL
            
    $threadFetchOptions parent::prepareThreadFetchOptions($fetchOptions);
            
    $options XenForo_Application::get('options');

            if(
    'thread.node_id' == $options->MyForumChooser[0])
                {
            
    // ADD YOUR OWN JOINS Left join table
                
    if(!empty($fetchOptions['join']) )
                    {
                        
    $threadFetchOptions['selectFields'] .= ',
                            dates.start_date, dates.closing_date'
    ;
                        
    $threadFetchOptions['joinTables'] .= '
                            LEFT JOIN pg_dates AS dates ON
                            (thread.thread_id = dates.thread_id)'
    ;
                    }
                }         
            return 
    $threadFetchOptions;
        }
    }
     
  6. Daniel Hood

    Daniel Hood Well-Known Member

    Extend:
    PHP:
    XenForo_Thread_Model::prepareThreadConditions(array $conditions, array &$fetchOptions)
     
  7. Nobita.Kun

    Nobita.Kun Well-Known Member

    As I said "This is existing on xenForo". Example code:
    PHP:
    $coditions = array(
            
    'node_id' => $specialNodeId
        
    );
        
    $fetchOptions = array(
            
    // your code for join
        
    );
       
        
    $threads $this->getModelFromCache('XenForo_Model_Thread')->getThreads($coditions$fetchOptions);
     

Share This Page