Incompatibilities with other add-ons (hooking into preparePostJoinOptions)

Robust

Well-known member
Having a 'lil problem:

I extend XenForo_Model_Post, and have this code:

Code:
    public function preparePostJoinOptions(array $fetchOptions)
    {
        $return = parent::preparePostJoinOptions($fetchOptions);
        $db = $this->_getDb();

        $return['selectFields'] .= ',
                ba_votes.vote_date';
        $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).
 
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.
 
Top Bottom