Merge branch 'develop' into szzh

This commit is contained in:
sw 2015-09-06 14:30:10 +08:00
commit fd976b4524
6 changed files with 79 additions and 70 deletions

View File

@ -169,7 +169,7 @@ module UserScoreHelper
# end # end
skill_score = 2 * praise_count_l0.to_f + 3 * praise_count_l1.to_f + 4 * praise_count_l2.to_f skill_score = 2 * praise_count_l0.to_f + 3 * praise_count_l1.to_f + 4 * praise_count_l2.to_f
- 1 * tread_count_l0.to_f - 1.5 * tread_count_l1.to_f - 2 * tread_count_l2.to_f - 1 * tread_count_l0.to_f - 1.5 * tread_count_l1.to_f - 2 * tread_count_l2.to_f
tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count
@ -320,7 +320,7 @@ module UserScoreHelper
#user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill, #user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
# :activity => activity, :file => file, :issue => issue, :level => level) # :activity => activity, :file => file, :issue => issue, :level => level)
UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill, UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
:activity => activity, :file => file, :issue => issue, :level => level) :activity => activity, :file => file, :issue => issue, :level => level)
end end
def update_user_score(user) def update_user_score(user)
@ -348,37 +348,37 @@ module UserScoreHelper
option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}' and project_id = '#{project.id}'"); option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}' and project_id = '#{project.id}'");
end end
result = nil result = nil
if option_number.nil? || option_number.count == 0 if option_number.nil? || option_number.count == 0
result = OptionNumber.new result = OptionNumber.new
result.user_id = user.id result.user_id = user.id
result.memo = 0 result.memo = 0
result.messages_for_issues = 0 result.messages_for_issues = 0
result.issues_status = 0 result.issues_status = 0
result.replay_for_message = 0 result.replay_for_message = 0
result.replay_for_memo = 0 result.replay_for_memo = 0
result.follow = 0 result.follow = 0
result.tread = 0 result.tread = 0
result.praise_by_one = 0 result.praise_by_one = 0
result.praise_by_two = 0 result.praise_by_two = 0
result.praise_by_three = 0 result.praise_by_three = 0
result.tread_by_one = 0 result.tread_by_one = 0
result.tread_by_two = 0 result.tread_by_two = 0
result.tread_by_three = 0 result.tread_by_three = 0
result.changeset = 0 result.changeset = 0
result.document = 0 result.document = 0
result.attachment = 0 result.attachment = 0
result.issue_done_ratio = 0 result.issue_done_ratio = 0
result.post_issue = 0 result.post_issue = 0
result.total_score = 0 result.total_score = 0
result.score_type =type result.score_type =type
unless project.nil? unless project.nil?
result.project_id = project.id result.project_id = project.id
end end
else else
result = option_number.first result = option_number.first
end end
result result
end end
def get_option_num_by_id(user_id,type,project_id=nil) def get_option_num_by_id(user_id,type,project_id=nil)
@ -433,7 +433,7 @@ module UserScoreHelper
#协同得分 #协同得分
def collaboration(option_number) def collaboration(option_number)
option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo option_number.memo * 2 + option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo
end end
#影响力得分 #影响力得分
def influence(option_number) def influence(option_number)
@ -441,11 +441,11 @@ module UserScoreHelper
end end
#技术得分 #技术得分
def skill(option_number) def skill(option_number)
option_number.praise_by_one * 4 + option_number.praise_by_two * 6 + option_number.praise_by_three * 8 - option_number.tread * 2 - option_number.tread_by_one * 2 - option_number.tread_by_two * 4 - option_number.tread_by_three * 6 option_number.praise_by_one * 4 + option_number.praise_by_two * 6 + option_number.praise_by_three * 8 - option_number.tread * 2 - option_number.tread_by_one * 2 - option_number.tread_by_two * 4 - option_number.tread_by_three * 6
end end
#项目贡献得分 #项目贡献得分
def active(option_number) def active(option_number)
option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4 + option_number.memo * 2 option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4
end end
#更新发帖数 #更新发帖数
@ -473,7 +473,7 @@ WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}") WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
result = 0 result = 0
users.each do |user| users.each do |user|
result = user.m_count result = user.m_count
end end
result result
end end
@ -481,15 +481,15 @@ WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
end end
def memo_score(user,project=nil) def memo_score(user,project=nil)
if project.nil? if project.nil?
User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id != -1 AND messages.board_id = boards.id User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id != -1 AND messages.board_id = boards.id
WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count
FROM `users` where id = #{user.id}") FROM `users` where id = #{user.id}")
else else
User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id = '#{project.id}' AND messages.board_id = boards.id User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id = '#{project.id}' AND messages.board_id = boards.id
WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count
FROM `users` where id = #{user.id}") FROM `users` where id = #{user.id}")
end end
end end
#更新对缺陷留言数 #更新对缺陷留言数
@ -505,7 +505,7 @@ FROM `users` where id = #{user.id}")
users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals WHERE journals.user_id = #{user.id} AND journals.notes IS NOT NULL AND journals.notes != ''") users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals WHERE journals.user_id = #{user.id} AND journals.notes IS NOT NULL AND journals.notes != ''")
result = 0 result = 0
if users.count > 0 if users.count > 0
result = users.first.m_count result = users.first.m_count
end end
result result
else else
@ -521,7 +521,7 @@ FROM `users` where id = #{user.id}")
def messges_for_issue_score(user,project=nil) def messges_for_issue_score(user,project=nil)
if project.nil? if project.nil?
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != '') AS m_score FROM users where id = #{user.id}") User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != '') AS m_score FROM users where id = #{user.id}")
else else
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals join issues on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != ''and #{Issue.table_name}.project_id = '#{project.id}') AS m_score FROM users where id = #{user.id}") User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals join issues on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != ''and #{Issue.table_name}.project_id = '#{project.id}') AS m_score FROM users where id = #{user.id}")
end end
@ -594,11 +594,11 @@ FROM `users` where id = #{user.id}")
end end
def replay_for_message_score(user,project=nil) def replay_for_message_score(user,project=nil)
if project.nil? if project.nil?
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project') as m_score FROM users WHERE users.id = '#{user.id}'") User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project') as m_score FROM users WHERE users.id = '#{user.id}'")
else else
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project' and jour_id = '#{project.id}') as m_score FROM users WHERE users.id = '#{user.id}'") User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project' and jour_id = '#{project.id}') as m_score FROM users WHERE users.id = '#{user.id}'")
end end
end end
#更新对帖子的回复数量 #更新对帖子的回复数量

View File

@ -15,6 +15,8 @@ class CourseMessage < ActiveRecord::Base
after_create :add_user_message after_create :add_user_message
def add_user_message def add_user_message
self.message_alls << MessageAll.new(:user_id => self.user_id) if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end end
end end

View File

@ -22,6 +22,8 @@ class ForgeMessage < ActiveRecord::Base
after_create :add_user_message after_create :add_user_message
def add_user_message def add_user_message
self.message_alls << MessageAll.new(:user_id => self.user_id) if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end end
end end

View File

@ -12,6 +12,8 @@ class MemoMessage < ActiveRecord::Base
after_create :add_user_message after_create :add_user_message
def add_user_message def add_user_message
self.message_alls << MessageAll.new(:user_id => self.user_id) if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end end
end end

View File

@ -493,26 +493,27 @@ class Query < ActiveRecord::Base
def project_statement def project_statement
project_clauses = [] project_clauses = []
# unless project.descendants.blank? # unless project.descendants.blank?
if project && project.descendants && project.descendants.active && !project.descendants.active.empty? # if project && project.descendants && project.descendants.active && !project.descendants.active.empty?
ids = [project.id] # ids = [project.id]
if has_filter?("subproject_id") # if has_filter?("subproject_id")
case operator_for("subproject_id") # case operator_for("subproject_id")
when '=' # when '='
# include the selected subprojects # # include the selected subprojects
ids += values_for("subproject_id").each(&:to_i) # ids += values_for("subproject_id").each(&:to_i)
when '!*' # when '!*'
# main project only # # main project only
else # else
# all subprojects # # all subprojects
ids += project.descendants.collect(&:id) # ids += project.descendants.collect(&:id)
end # end
elsif Setting.display_subprojects_issues? # elsif Setting.display_subprojects_issues?
ids += project.descendants.collect(&:id) # ids += project.descendants.collect(&:id)
end # end
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') # project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
elsif project # elsif project
if project
project_clauses << "#{Project.table_name}.id = %d" % project.id project_clauses << "#{Project.table_name}.id = %d" % project.id
end end
# end # end
project_clauses.any? ? project_clauses.join(' AND ') : nil project_clauses.any? ? project_clauses.join(' AND ') : nil
end end

View File

@ -11,6 +11,8 @@ class UserFeedbackMessage < ActiveRecord::Base
after_save :add_user_message after_save :add_user_message
def add_user_message def add_user_message
self.message_alls << MessageAll.new(:user_id => self.user_id) if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end end
end end