refactor welcome help

This commit is contained in:
yanxd 2013-11-28 11:29:21 +08:00
parent 9f3d29a1f9
commit 49327905f8
1 changed files with 16 additions and 23 deletions

View File

@ -70,29 +70,29 @@ module WelcomeHelper
end
def sort_project_by_hot
return sort_project_by_hot_rails 0
sort_project_by_hot_rails 0, 'grade DESC'
end
def sort_course_by_hot
return sort_project_by_hot_rails 1
sort_project_by_hot_rails 1, 'course_ac_para DESC'
end
def sort_bid_by_hot
return sort_bid_by_hot_rails 1
sort_bid_by_hot_rails 1
end
def sort_contest_by_hot
return sort_bid_by_hot_rails 2
sort_bid_by_hot_rails 2
end
#取得所有活动
def find_all_activities limit=10
users = []
activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" )
activities.each { |activity|
users << activity.user_id
}
user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )")
activity = Redmine::Activity::Fetcher.new(user_objs)
# users = []
# activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" )
# activities.each { |activity|
# users << activity.user_id
# }
# user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )")
activity = Redmine::Activity::Fetcher.new(nil)
activity.events_welcome(nil, nil, {:limit => limit})
end
@ -102,23 +102,16 @@ module WelcomeHelper
Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit)
end
def sort_project_by_hot_rails project_type
limit = 10
project_type == 0 ? Project.find_by_sql("
def sort_project_by_hot_rails project_type=0, order_by='grade DESC', limit=10
Project.find_by_sql("
SELECT p.id, p.name, p.description, p.identifier, t.project_id
FROM projects AS p RIGHT OUTER JOIN (
SELECT project_id,grade FROM project_statuses
WHERE project_type = #{project_type} ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ")
: Project.find_by_sql("
SELECT p.id, p.name, p.description, p.identifier, t.project_id
FROM projects AS p RIGHT OUTER JOIN (
SELECT project_id,grade FROM project_statuses
WHERE project_type = #{project_type} ORDER BY course_ac_para DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ")
WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ")
end
def sort_bid_by_hot_rails reward_type
limit = 10
Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit).all
def sort_bid_by_hot_rails reward_type, limit = 10
Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit)
end
end