Model Thread Extending ?

arms

Well-known 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?
 
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;
    }
}
 
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;
    }
}
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);
 
Back
Top Bottom