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

Incompatibilities with other add-ons (hooking into preparePostJoinOptions)

Discussion in 'XenForo Development Discussions' started by Robust, Oct 29, 2015.

  1. Robust

    Robust Well-Known Member

    Having a 'lil problem:

    I extend XenForo_Model_Post, and have this code:

        public function preparePostJoinOptions(array $fetchOptions)
            $return = parent::preparePostJoinOptions($fetchOptions);
            $db = $this->_getDb();
            $return['selectFields'] .= ',
            $return['joinTables'] .= '
                    LEFT JOIN ba_votes
                            ON (ba_votes.thread_id = post.thread_id
                                    AND ba_votes.post_id = post.post_id
                                    AND ba_votes.vote_user_id = ' . $db->quote(XenForo_Visitor::getUserId()) . ')';
            return $return;
    It does, however, seem to cause incompatibilities with other add-ons - any solutions?

    I know I could narrow down the query to only work in the forums my add-on is enabled in (it's forum-enabled based), however, I can't fetch the forum the post is in at this level.

    What this does, essentially, is finds out if the XenForo_Visitor has voted on a piece of content. If a value for vote_date exists, it means they have voted, otherwise they haven't (this decides whether to show the vote/unvote button).
  2. Xon

    Xon Well-Known Member

    That sort of code will also break moving/copying posts.

    You should check $fetchOptions for some bits. You can stuff arbitrary data into $fetchOptions by altering the default values from the XenForo_Controller_Thread class as there is a conveniently override-able 'get defaults' function.
    Robust and thedude like this.

Share This Page