Beispiel #1
0
    public function prepareThreadFetchOptions(array $fetchOptions)
    {
        $result = parent::prepareThreadFetchOptions($fetchOptions);
        extract($result);
        if (!empty($fetchOptions[self::FETCH_OPTIONS_POLL_JOIN])) {
            $selectFields .= ',
					poll.*';
            $joinTables .= '
					LEFT JOIN xf_poll AS poll ON
					(poll.content_type = \'thread\' AND content_id = thread.thread_id)';
        }
        if (!empty($fetchOptions[self::FETCH_OPTIONS_FORUM_FULL_JOIN]) and empty($fetchOptions['join'])) {
            $selectFields .= ',
					forum.*';
            $joinTables .= '
					INNER JOIN xf_forum AS forum ON
					(forum.node_id = thread.node_id)';
        }
        if (!empty($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN]) and empty($fetchOptions['join'])) {
            if ($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN] & self::FETCH_USER) {
                $selectFields .= ',
						1 AS fetched_last_post_user, user.*';
                $joinTables .= '
						LEFT JOIN xf_user AS user ON
						(user.user_id = thread.last_post_user_id)';
            } elseif ($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN] & self::FETCH_AVATAR) {
                $selectFields .= ',
						1 AS fetched_last_post_user, user.gender, user.avatar_date, user.gravatar';
                $joinTables .= '
						LEFT JOIN xf_user AS user ON
						(user.user_id = thread.last_post_user_id)';
            }
            if ($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN] & self::FETCH_FIRSTPOST) {
                $selectFields .= ',
					1 AS fetched_last_post, post.message, post.attach_count';
                $joinTables .= '
					LEFT JOIN xf_post AS post ON
						(post.post_id = thread.last_post_id)';
            }
        }
        if (!empty($fetchOptions['order'])) {
            switch ($fetchOptions['order']) {
                case self::FETCH_OPTIONS_ORDER_RANDOM:
                    $orderClause = 'ORDER BY RAND()';
                    break;
            }
        }
        return compact('selectFields', 'joinTables', 'orderClause');
    }
    public function prepareThreadFetchOptions(array $fetchOptions)
    {
        $proxyFetchOptions = $fetchOptions;
        if (!empty($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN]) && empty($fetchOptions['join'])) {
            $proxyFetchOptions['join'] = $fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN];
            $lastPostJoins = array(self::FETCH_USER, self::FETCH_AVATAR, self::FETCH_FIRSTPOST);
            foreach ($lastPostJoins as $join) {
                if ($proxyFetchOptions['join'] & $join) {
                    // remove last post joins from fetch options
                    $proxyFetchOptions['join'] ^= $join;
                }
            }
        }
        $result = parent::prepareThreadFetchOptions($proxyFetchOptions);
        $selectFields = $result['selectFields'];
        $joinTables = $result['joinTables'];
        $orderClause = $result['orderClause'];
        if (!empty($fetchOptions[self::FETCH_OPTIONS_POLL_JOIN])) {
            $selectFields .= ',
					poll.*';
            $joinTables .= '
					LEFT JOIN xf_poll AS poll ON
					(poll.content_type = \'thread\' AND content_id = thread.thread_id)';
        }
        if (!empty($fetchOptions[self::FETCH_OPTIONS_FORUM_FULL_JOIN]) && empty($fetchOptions['join'])) {
            $selectFields .= ',
					forum.*';
            $joinTables .= '
					INNER JOIN xf_forum AS forum ON
					(forum.node_id = thread.node_id)';
        }
        if (!empty($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN]) && empty($fetchOptions['join'])) {
            // IMPORTANT: update $proxyFetchOptions['join'] calculation if more fetch flags are supported
            if ($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN] & self::FETCH_USER) {
                $selectFields .= ',
						1 AS fetched_last_post_user, user.*';
                $joinTables .= '
						LEFT JOIN xf_user AS user ON
						(user.user_id = thread.last_post_user_id)';
            } elseif ($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN] & self::FETCH_AVATAR) {
                $selectFields .= ',
						1 AS fetched_last_post_user, user.gender, user.avatar_date, user.gravatar';
                $joinTables .= '
						LEFT JOIN xf_user AS user ON
						(user.user_id = thread.last_post_user_id)';
            }
            if ($fetchOptions[self::FETCH_OPTIONS_LAST_POST_JOIN] & self::FETCH_FIRSTPOST) {
                $selectFields .= ',
					1 AS fetched_last_post, post.message, post.attach_count';
                $joinTables .= '
					LEFT JOIN xf_post AS post ON
						(post.post_id = thread.last_post_id)';
            }
            // IMPORTANT: update $proxyFetchOptions['join'] calculation if more fetch flags are supported
        }
        if (!empty($fetchOptions['order'])) {
            switch ($fetchOptions['order']) {
                case self::FETCH_OPTIONS_ORDER_RANDOM:
                    $orderClause = 'ORDER BY RAND()';
                    break;
            }
        }
        return compact('selectFields', 'joinTables', 'orderClause');
    }