FIX: Pinned posts were not displaying at the top of categories.

This commit is contained in:
Robin Ward 2013-11-08 15:05:14 -05:00
parent 965a0a91a2
commit be5de4244c
1 changed files with 16 additions and 12 deletions

View File

@ -222,18 +222,7 @@ class TopicQuery
result = result.joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i})")
end
unless options[:unordered]
# If we're logged in, we have to pay attention to our pinned settings
if @user
result = result.order(TopicQuery.order_nocategory_with_pinned_sql)
else
result = result.order(TopicQuery.order_nocategory_basic_bumped)
end
end
result = result.listable_topics.includes(category: :topic_only_relative_url)
result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category]).references(:categories) if options[:exclude_category]
category_id = nil
if options[:category].present?
category_id = options[:category].to_i
if category_id == 0
@ -244,6 +233,21 @@ class TopicQuery
result = result.references(:categories)
end
unless options[:unordered]
# If we're logged in, we have to pay attention to our pinned settings
if @user
result = category_id.nil? ? result.order(TopicQuery.order_nocategory_with_pinned_sql) :
result.order(TopicQuery.order_with_pinned_sql)
else
result = result.order(TopicQuery.order_nocategory_basic_bumped)
end
end
result = result.listable_topics.includes(category: :topic_only_relative_url)
result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category]).references(:categories) if options[:exclude_category]
result = result.limit(options[:per_page]) unless options[:limit] == false
result = result.visible if options[:visible] || @user.nil? || @user.regular?
result = result.where('topics.id <> ?', options[:except_topic_id]).references(:topics) if options[:except_topic_id]