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

Need fresh eyes

Discussion in 'XenForo Development Discussions' started by Mythotical, May 8, 2011.

  1. Mythotical

    Mythotical Well-Known Member

    Ok I have multiple forum chooser for my Latest Threads block. The issue is once I have it pull the option it still only displays 1 result when it should display 5.

    Here is my code:
            $ltOption XenForo_Application::get('options')->xportal_latestThreads;
    $ltMatches implode(','$ltOption);

    $lThreads $this->limitQueryResults('
                SELECT *
                FROM xf_thread
                WHERE node_id = ?
                AND discussion_state = "visible"
                AND discussion_open = "1"
                ORDER BY thread_id DESC

    I have done a print_r on $ltMatches, it is displaying like it should so I know its not in the option.

    So any help would be much appreciated.

  2. Jaxel

    Jaxel Well-Known Member

    Ah... simple mistake Steve...
    WHERE node_id = ?
    You are using the 5 as the node_id in your prepared statement, Therefore its defaulting the limit to 1. That being said, why are you writing your own query instead of using the built in thread fetching functions?

    This code below is the code I use for my portal. It gets threads not deleted or moderated. It also fetches forum and user information. It also detects whether the user has read/watched/posted on a thread. Then it sorts. Finally it prepares the thread for viewing based on permissions.
            $visitor = XenForo_Visitor::getInstance();
            $conditions = array(
                'deleted' => false,
                'moderated' => false
            $fetchOptions = array(
                'join' => XenForo_Model_Thread::FETCH_FORUM | XenForo_Model_Thread::FETCH_USER,
                'permissionCombinationId' => $visitor['permission_combination_id'],
                'readUserId' => $visitor['user_id'],
                'watchUserId' => $visitor['user_id'],
                'postCountUserId' => $visitor['user_id'],
                'order' => 'last_post_date',
                'orderDirection' => 'desc',
                'limit' => 5,
            $threads = $this->getModelFromCache('XenForo_Model_Thread')->getThreads($conditions, $fetchOptions);
            foreach ($threads AS $threadID => &$thread)
                if ($this->getModelFromCache('XenForo_Model_Thread')->canViewThreadAndContainer($thread, $thread))
                    $thread = $this->getModelFromCache('XenForo_Model_Thread')->prepareThread($thread, $thread);
            return $threads;
    Actually, its not exactly what I use. In my portal, I wrote my own "getThreads" function in order to handle node_ids.
  3. Mythotical

    Mythotical Well-Known Member

    Wow, thanks. I use the 5 in the same manner when pulling from 1 node_id so I assume when using a node_id in an array the limit isn't read properly.
  4. Mythotical

    Mythotical Well-Known Member

    Jaxel, thanks again for the code, works like a charm. Is there a way to use a WHERE clause to only pull the threads from forums specified in an option?
  5. ragtek

    ragtek Guest

    threadmodel includes already a method for this!
    start reading the code:p
    * Gets threads that belong to the specified forum.
    * @param integer $forumId
    * @param array $conditions Conditions to apply to the fetching
    * @param array $fetchOptions Collection of options that relate to fetching
    * @return array Format: [thread id] => info
    public function getThreadsInForum($forumId, array $conditions = array(), array $fetchOptions = array())
  6. Mythotical

    Mythotical Well-Known Member

    Can't read the code if I don't know the file it came from. :p

    I missed the condition array at the top. Oops.
  7. ragtek

    ragtek Guest

    Little hint:

    99% of the read operations happens in the models (xenforo/model )
    YOu want to read threads, so open xenforo/model/thread
    As next, check all available methods (because you want to get something, start searching for getXXXXX

    as you see, it isn't hard and much faster as starting an thread and hoping somebody replies^^
  8. Mythotical

    Mythotical Well-Known Member

    Thanks for the tip.

    I need a little assistance as I'm having issues getting this to work properly:
        public function getThreads()
    $visitor XenForo_Visitor::getInstance();
    $ltOption XenForo_Application::get('options')->xportal_latestThreads;
    $ltMatches explode(','$ltOption);

    $conditions = array(
    'deleted' => false,
    'moderated' => false,
    'node_id' => $ltMatches

    $fetchOptions = array(
    'join' => XenForo_Model_Thread::FETCH_FORUM XenForo_Model_Thread::FETCH_USER,
    'permissionCombinationId' => $visitor['permission_combination_id'],
    'readUserId' => $visitor['user_id'],
    'watchUserId' => $visitor['user_id'],
    'postCountUserId' => $visitor['user_id'],
    'order' => 'last_post_date',
    'orderDirection' => 'desc',
    'limit' => 5,

    $threads $this->getModelFromCache('XenForo_Model_Thread')->getThreads($conditions$fetchOptions);

            foreach (
    $threads AS $threadID => &$thread)
                if (
    $thread $this->getModelFromCache('XenForo_Model_Thread')->prepareThread($thread$thread);

    I'm not even sure how a foreach should be constructed in the template since one exists in the php file. Also the condition for node_id, am I doing something wrong?
  9. ragtek

    ragtek Guest

    $ltMatches = explode(',', $ltOption);

    $conditions = array(
    'deleted' => false,
    'moderated' => false,
    'node_id' => $ltMatches

    that's not possible!

    you can only pass 1 node_id
  10. Mythotical

    Mythotical Well-Known Member

    How would it be constructed so that it will pass all selected node ids?

Share This Page