add top page

This commit is contained in:
Régis Hanol
2013-12-24 00:50:36 +01:00
parent b90e811825
commit 567d2bd23c
57 changed files with 532 additions and 324 deletions

View File

@@ -8,7 +8,7 @@ require_dependency 'topic_query_sql'
class TopicQuery
# Could be rewritten to %i if Ruby 1.9 is no longer supported
VALID_OPTIONS = %w(except_topic_id
VALID_OPTIONS = %w(except_topic_ids
exclude_category
limit
page
@@ -84,6 +84,12 @@ class TopicQuery
create_list(:posted) {|l| l.where('tu.user_id IS NOT NULL') }
end
def list_top(sort_order, period)
create_list(:top, unordered: true) do |topics|
topics.joins(:top_topic).order("top_topics.#{period}_#{sort_order}_count DESC, topics.bumped_at DESC")
end
end
def list_topics_by(user)
create_list(:user_topics) do |topics|
topics.where(user_id: user.id)
@@ -227,7 +233,7 @@ class TopicQuery
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]
result = result.where.not(topics: {id: options[:except_topic_ids]}).references(:topics) if options[:except_topic_ids]
result = result.offset(options[:page].to_i * options[:per_page]) if options[:page]
if options[:topic_ids]