welcome activity.

This commit is contained in:
yanxd 2013-11-28 09:29:59 +08:00
parent d955480184
commit 6a97cb69a8
3 changed files with 292 additions and 231 deletions

View File

@ -37,16 +37,16 @@ module WelcomeHelper
end
def find_all_hot_course
sort_course_by_hot
sort_course_by_hot
end
def find_all_hot_bid
sort_bid_by_hot
sort_bid_by_hot
end
def find_all_hot_contest
sort_contest_by_hot
end
def find_all_hot_contest
sort_contest_by_hot
end
private
@ -70,45 +70,54 @@ module WelcomeHelper
end
def sort_project_by_hot
return sort_project_by_hot_rails 0
end
return sort_project_by_hot_rails 0
end
def sort_course_by_hot
return sort_project_by_hot_rails 1
end
def sort_course_by_hot
return sort_project_by_hot_rails 1
end
def sort_bid_by_hot
return sort_bid_by_hot_rails 1
end
def sort_bid_by_hot
return sort_bid_by_hot_rails 1
end
def sort_contest_by_hot
return sort_bid_by_hot_rails 2
end
#取得所有活动
def find_all_activities
def sort_contest_by_hot
return 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)
end
#取得论坛数据
def find_hot_forum_topics
activity.events_welcome(nil, nil, {:limit => limit})
end
end
def sort_project_by_hot_rails project_type
limit = 10
project_type == 0 ? 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 ")
end
#取得论坛数据
def find_hot_forum_topics
def sort_bid_by_hot_rails reward_type
limit = 10
Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit).all
end
end
def sort_project_by_hot_rails project_type
limit = 10
project_type == 0 ? 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 ")
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
end
end

View File

@ -81,6 +81,40 @@ module Redmine
scope.all(provider_options[:find_options].dup)
end
def find_events1(event_type, user, from, to, options)
provider_options = activity_provider_options[event_type]
raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
scope = self
if from && to
scope = scope.scoped(:conditions => ["#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to])
end
if options[:author]
return [] if provider_options[:author_key].nil?
scope = scope.scoped(:conditions => ["#{provider_options[:author_key]} = ?", options[:author].id])
end
if options[:limit]
# id and creation time should be in same order in most cases
scope = scope.scoped(:order => "#{table_name}.id DESC", :limit => options[:limit])
end
if provider_options.has_key?(:permission)
user1 = User.find_by_login('user')
scope = scope.scoped(:conditions => Project.allowed_to_condition(user1, provider_options[:permission] || :view_project, options))
elsif respond_to?(:visible)
scope = scope.visible(user1, options)
else
ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option."
scope = scope.scoped(:conditions => Project.allowed_to_condition(user1, "view_#{self.name.underscore.pluralize}".to_sym, options))
end
scope.all(provider_options[:find_options].dup)
end
end
end
end

View File

@ -85,6 +85,24 @@ module Redmine
e
end
def events_welcome(from = nil, to = nil, options={})
e = []
@options[:limit] = options[:limit]
@scope.each do |event_type|
constantized_providers(event_type).each do |provider|
e += provider.find_events1(event_type, @user, from, to, @options)
end
end
e.sort! {|a,b| b.event_datetime <=> a.event_datetime}
if options[:limit]
e = e.slice(0, options[:limit])
end
e
end
private
def constantized_providers(event_type)