积分计算修改

This commit is contained in:
z9hang 2014-08-13 11:17:22 +08:00
parent 87f6f81279
commit caed78327a
20 changed files with 184 additions and 81 deletions

View File

@ -76,6 +76,7 @@ class ProjectsController < ApplicationController
# helper :watcherlist # helper :watcherlist
helper :words helper :words
helper :project_score helper :project_score
helper :user_score
### added by william ### added by william
include ActsAsTaggableOn::TagsHelper include ActsAsTaggableOn::TagsHelper
@ -111,7 +112,7 @@ class ProjectsController < ApplicationController
per_page_option = 10 per_page_option = 10
@projects_all = Project.active.visible. @projects_all = Project.active.visible.
joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id").joins("LEFT JOIN #{ProjectScore.table_name} ON #{Project.table_name}.id = #{ProjectScore.table_name}.project_id").
where("#{Project.table_name}.project_type = ? ", Project::ProjectType_project) where("#{Project.table_name}.project_type = ? ", Project::ProjectType_project)
@project_count = @projects_all.count @project_count = @projects_all.count
@ -134,7 +135,7 @@ class ProjectsController < ApplicationController
@projects = @projects_all.order("created_on desc") @projects = @projects_all.order("created_on desc")
@s_type = 0 @s_type = 0
when '1' when '1'
@projects = @projects_all.order("grade desc") @projects = @projects_all.order("score desc")
@s_type = 1 @s_type = 1
when '2' when '2'
@projects = @projects_all.order("watchers_count desc") @projects = @projects_all.order("watchers_count desc")
@ -148,7 +149,7 @@ class ProjectsController < ApplicationController
@projects = @projects[@project_pages.offset, @project_pages.per_page] @projects = @projects[@project_pages.offset, @project_pages.per_page]
else else
@projects = @projects = @projects_all.order("grade desc") @projects = @projects = @projects_all.order("score desc")
@s_type = 1 @s_type = 1
end end
@projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page)

View File

@ -27,14 +27,14 @@ class WelcomeController < ApplicationController
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.where("page_type = 'project'").first
#@show_course = @first_page.show_course #@show_course = @first_page.show_course
if @first_page.nil? || @first_page.sort_type.nil? if @first_page.nil? || @first_page.sort_type.nil?
@projects = find_miracle_project(10, 3,"grade desc") @projects = find_miracle_project(10, 3,"score desc")
else else
case @first_page.sort_type case @first_page.sort_type
when 0 when 0
@projects = find_miracle_project(10, 3,"created_on desc") @projects = find_miracle_project(10, 3,"created_on desc")
#@projects = @projects_all.order("created_on desc") #@projects = @projects_all.order("created_on desc")
when 1 when 1
@projects = find_miracle_project(10, 3,"grade desc") @projects = find_miracle_project(10, 3,"score desc")
#@projects = @projects_all.order("grade desc") #@projects = @projects_all.order("grade desc")
when 2 when 2
@projects = find_miracle_project(10, 3,"watchers_count desc") @projects = find_miracle_project(10, 3,"watchers_count desc")
@ -48,7 +48,7 @@ class WelcomeController < ApplicationController
# @projects = @projects[@project_pages.offset, @project_pages.per_page] # @projects = @projects[@project_pages.offset, @project_pages.per_page]
else else
@projects = @projects_all.order("grade desc") @projects = @projects_all.order("score desc")
end end
end end

View File

@ -65,26 +65,34 @@ module ProjectScoreHelper
b_m_num * 2 b_m_num * 2
end end
#项目得分 #计算项目得分
def project_scores project def project_scores project
result = (issue_score project) + (news_score project) + (document_score project) + (changesets_score project) + (board_message_score project) result = (issue_score project) + (news_score project) + (document_score project) + (changesets_score project) + (board_message_score project)
pss = ProjectStatus.where("project_id = '#{project.id}'") pss = ProjectScore.where("project_id = '#{project.id}'")
if pss.nil? || pss.count == 0 if pss.nil? || pss.count == 0
ps = ProjectStatus.new ps = ProjectScore.new
ps.grade = result ps.score = result
ps.project = project ps.project = project
ps.watchers_count = project.watcher_users.count
ps.changesets_count = project.changesets.count
ps.save ps.save
else else
ps = pss.first ps = pss.first
ps.grade = result ps.score = result
if ps.changesets_count.nil? || ps.changesets_count == ""
ps.changesets_count = project.changesets.count
end
ps.save ps.save
end end
result result
end end
#读取项目得分
def red_project_scores project
grade = 0
pss = ProjectScore.where("project_id = '#{project.id}'")
if pss.nil? || pss.count == 0
grade
else
ps = pss.first
grade = ps.score
grade
end
end
end end

View File

@ -445,7 +445,7 @@ FROM `users` where id = #{user.id}")
def messges_for_issue_num(user,project=nil) def messges_for_issue_num(user,project=nil)
if project.nil? if project.nil?
Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count Journal.includes(:user).where("user_id = '#{user.id}' and notes is not null and notes != ''").all.count
else else
Journal.includes(:user).joins(:issue).where("#{Journal.table_name}.user_id = '#{user.id}' and #{Issue.table_name}.project_id = '#{project.id}' and #{Journal.table_name}.notes != '' and #{Journal.table_name}.notes is not null").all.count Journal.includes(:user).joins(:issue).where("#{Journal.table_name}.user_id = '#{user.id}' and #{Issue.table_name}.project_id = '#{project.id}' and #{Journal.table_name}.notes != '' and #{Journal.table_name}.notes is not null").all.count
end end
@ -475,6 +475,16 @@ FROM `users` where id = #{user.id}")
end end
def issues_status_score(user,project=nil)
if project.nil?
#Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id) AS m_score FROM users WHERE users.id = '#{user.id}'")
else
#Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id and issues.project_id = '#{project.id}') AS m_score FROM users WHERE users.id = '#{user.id}'")
end
end
#更新对留言的回复数量 #更新对留言的回复数量
def update_replay_for_message(user,type,project=nil) def update_replay_for_message(user,type,project=nil)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -491,6 +501,14 @@ FROM `users` where id = #{user.id}")
end end
def replay_for_message_score(user,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}'")
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}'")
end
end
#更新对帖子的回复数量 #更新对帖子的回复数量
def update_replay_for_memo(user,type,project=nil) def update_replay_for_memo(user,type,project=nil)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -506,6 +524,14 @@ FROM `users` where id = #{user.id}")
end end
end end
def replay_for_memo_score(user,project=nil)
if project.nil?
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = users.id AND boards.project_id != -1) FROM users WHERE users.id = #{user.id}")
else
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = users.id AND boards.project_id = #{project.id}) FROM users WHERE users.id = #{user.id}")
end
end
#更新被关注的人数 #更新被关注的人数
def update_follow(user,type) def update_follow(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -517,6 +543,10 @@ FROM `users` where id = #{user.id}")
Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count
end end
def follow_score(user)
User.find_by_sql("SELECT users.id, (SELECT COUNT(*) * 2 FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' and watchable_id = '#{user.id}') FROM users WHERE users.id = '#{user.id}'")
end
#更新帖子踩各项数量 #更新帖子踩各项数量
def update_tread(user,type,project=nil) def update_tread(user,type,project=nil)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -542,7 +572,7 @@ FROM `users` where id = #{user.id}")
end end
target_user = obj.author target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project #project = pt.project
if level == 1 && target_user.id == user.id if level == 1 && target_user.id == user.id
result << pt result << pt
elsif level == 2 && target_user.id == user.id elsif level == 2 && target_user.id == user.id
@ -560,7 +590,7 @@ FROM `users` where id = #{user.id}")
result2 = [] result2 = []
pts.each do |pt| pts.each do |pt|
obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id) obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id)
if obj.nil? if obj.nil? || (pt.praise_tread_object_type == "Issue" && obj.project.nil?) || (pt.praise_tread_object_type == "Message" && obj.board.nil?) || (pt.praise_tread_object_type == "Message" && obj.board.project.nil?)
next next
end end
if !(pt.praise_tread_object_type == "Issue" && obj.project.id == project.id) && !(pt.praise_tread_object_type == "Message" && obj.board.project.id == project.id) if !(pt.praise_tread_object_type == "Issue" && obj.project.id == project.id) && !(pt.praise_tread_object_type == "Message" && obj.board.project.id == project.id)
@ -568,7 +598,7 @@ FROM `users` where id = #{user.id}")
end end
target_user = obj.author target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project #project = pt.project
if level == 1 && target_user.id == user.id if level == 1 && target_user.id == user.id
result << pt result << pt
elsif level == 2 && target_user.id == user.id elsif level == 2 && target_user.id == user.id
@ -600,7 +630,7 @@ FROM `users` where id = #{user.id}")
result2 = [] result2 = []
pts.each do |pt| pts.each do |pt|
obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id) obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id)
if obj.nil? if obj.nil? || (pt.praise_tread_object_type == "Issue" && obj.project.nil?) || (pt.praise_tread_object_type == "Message" && obj.board.nil?) || (pt.praise_tread_object_type == "Message" && obj.board.project.nil?)
next next
end end
if !(pt.praise_tread_object_type == "Issue" && obj.project.id == project.id) && !(pt.praise_tread_object_type == "Message" && obj.board.project.id == project.id) if !(pt.praise_tread_object_type == "Issue" && obj.project.id == project.id) && !(pt.praise_tread_object_type == "Message" && obj.board.project.id == project.id)
@ -608,7 +638,7 @@ FROM `users` where id = #{user.id}")
end end
target_user = obj.author target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project #project = pt.project
if level == 1 && target_user.id == user.id if level == 1 && target_user.id == user.id
result << pt result << pt
elsif level == 2 && target_user.id == user.id elsif level == 2 && target_user.id == user.id

View File

@ -428,13 +428,13 @@ module WelcomeHelper
resultSet.take(limit) resultSet.take(limit)
end end
def sort_project_by_hot_rails project_type=0, order_by='grade DESC', limit=15 def sort_project_by_hot_rails project_type=0, order_by='score DESC', limit=15
# Project.find_by_sql(" # Project.find_by_sql("
# SELECT p.id, p.name, p.description, p.identifier, t.project_id # SELECT p.id, p.name, p.description, p.identifier, t.project_id
# FROM projects AS p LEFT OUTER JOIN ( # FROM projects AS p LEFT OUTER JOIN (
# SELECT project_id,grade FROM project_statuses # SELECT project_id,grade FROM project_statuses
# WHERE project_type = #{project_type} ORDER BY #{order_by} 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 ")
Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all Project.visible.joins(:project_status).joins("LEFT JOIN #{ProjectScore.table_name} ON #{Project.table_name}.id = #{ProjectScore.table_name}.project_id").where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all
end end
def sort_bid_by_hot_rails reward_type, limit = 10 def sort_bid_by_hot_rails reward_type, limit = 10

View File

@ -26,6 +26,8 @@ class Attachment < ActiveRecord::Base
belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :author, :class_name => "User", :foreign_key => "author_id"
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id" belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
include UserScoreHelper
validates_presence_of :filename, :author validates_presence_of :filename, :author
validates_length_of :filename, :maximum => 255 validates_length_of :filename, :maximum => 255
validates_length_of :disk_filename, :maximum => 255 validates_length_of :disk_filename, :maximum => 255
@ -68,8 +70,9 @@ class Attachment < ActiveRecord::Base
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
before_save :files_to_final_location before_save :files_to_final_location
before_save :be_user_score # user_score after_create :be_user_score # user_score
after_destroy :delete_from_disk after_update :be_user_score
after_destroy :delete_from_disk,:down_user_score
# add by nwb # add by nwb
# 获取所有可公开的资源文件列表 # 获取所有可公开的资源文件列表
@ -504,9 +507,16 @@ class Attachment < ActiveRecord::Base
type = self.container_type type = self.container_type
types = %w|Document News Version Project Issue Message WikiPage| types = %w|Document News Version Project Issue Message WikiPage|
if types.include?(type) if types.include?(type)
UserScore.project(:push_file, User.current,self, { attachment_id: self.id }) #UserScore.project(:push_file, self.author,self, { attachment_id: self.id })
end end
end end
update_attachment(self.author,1)
end
#删除附件时重新统计用户的附件数量得分
def down_user_score
update_attachment(self.author,1)
end end
end end

View File

@ -18,7 +18,7 @@
class Changeset < ActiveRecord::Base class Changeset < ActiveRecord::Base
belongs_to :repository belongs_to :repository
belongs_to :user belongs_to :user
include UserScoreHelper
#after_save :be_user_score # user_score #after_save :be_user_score # user_score
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
@ -64,6 +64,8 @@ class Changeset < ActiveRecord::Base
} }
after_create :scan_for_issues,:be_user_score # user_score after_create :scan_for_issues,:be_user_score # user_score
after_update :be_user_score
after_destroy :down_user_score
before_create :before_create_cs before_create :before_create_cs
# fq # fq
@ -305,6 +307,13 @@ class Changeset < ActiveRecord::Base
UserScore.project(:push_code, self.user,self, { changeset_id: self.id }) UserScore.project(:push_code, self.user,self, { changeset_id: self.id })
#更新用户等级 #更新用户等级
UserLevels.update_user_level(self.user) UserLevels.update_user_level(self.user)
update_changeset(self.user,1)
end
#积分刷新
def down_user_score
UserLevels.update_user_level(self.user)
update_changeset(self.user,1)
end end
end end

View File

@ -20,9 +20,9 @@ class Document < ActiveRecord::Base
belongs_to :project belongs_to :project
belongs_to :user belongs_to :user
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
include UserScoreHelper
after_create :be_user_score # user_score after_save :be_user_score # user_score
after_destroy :down_user_score
acts_as_attachable :delete_permission => :delete_documents acts_as_attachable :delete_permission => :delete_documents
@ -68,5 +68,10 @@ class Document < ActiveRecord::Base
# update user score # update user score
def be_user_score def be_user_score
UserScore.project(:push_document, self.user,self,{ document_id: self.id }) UserScore.project(:push_document, self.user,self,{ document_id: self.id })
update_document(self.user,1)
end
def down_user_score
update_document(self.user,1)
end end
end end

View File

@ -79,7 +79,7 @@ class Issue < ActiveRecord::Base
# fq # fq
after_create :act_as_activity,:be_user_score_new_issue after_create :act_as_activity,:be_user_score_new_issue
after_update :be_user_score after_update :be_user_score
before_destroy :down_user_score after_destroy :down_user_score
# after_create :be_user_score # after_create :be_user_score
# end # end
@ -1508,35 +1508,38 @@ class Issue < ActiveRecord::Base
def be_user_score def be_user_score
#缺陷完成度更新 #缺陷完成度更新
if self.done_ratio_changed? if self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id }) UserScore.project(:update_issue_ratio, self.author,self,{ issue_id: self.id })
#update_issue_done_ratio(User.current,1) #update_issue_done_ratio(self.author,1)
end end
#缺陷状态更改 #缺陷状态更改
if self.status_id_changed? if self.status_id_changed?
#协同得分 #协同得分
UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id}) UserScore.joint(:change_issue_status, self.author,nil,self, {issue_id: self.id})
#update_issues_status(self.author , 1) #update_issues_status(self.author , 1)
end end
end end
#发布缺陷 #发布缺陷
def be_user_score_new_issue def be_user_score_new_issue
UserScore.project(:post_issue, User.current,self, { issue_id: self.id }) UserScore.project(:post_issue, self.author,self, { issue_id: self.id })
update_post_issue(self.author,1) update_post_issue(self.author,1)
end end
def down_user_score def down_user_score
#缺陷完成度更新 #缺陷完成度更新
if self.done_ratio_changed? #if self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id }) # UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id })
#update_issue_done_ratio(User.current,1) # update_issue_done_ratio(User.current,1)
end #end
#缺陷状态更改 #缺陷状态更改
if self.status_id_changed? #if self.status_id_changed?
#协同得分 # #协同得分
UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id}) # UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id})
#update_issues_status(self.author , 1) # update_issues_status(self.author , 1)
end #end
update_post_issue(self.author,1)
update_issue_done_ratio(User.current,1)
update_issues_status(self.author , 1)
end end

View File

@ -46,11 +46,11 @@ class Journal < ActiveRecord::Base
before_create :split_private_notes before_create :split_private_notes
# fq # fq
after_create :act_as_activity,:be_user_score after_save :act_as_activity,:be_user_score
# end # end
#after_destroy :down_user_score #after_destroy :down_user_score
#before_save :be_user_score #before_save :be_user_score
before_destroy :down_user_score after_destroy :down_user_score
scope :visible, lambda {|*args| scope :visible, lambda {|*args|
user = args.shift || User.current user = args.shift || User.current
@ -162,8 +162,9 @@ class Journal < ActiveRecord::Base
if !self.notes.nil? && self.notes.gsub(' ','') != '' if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分加分 #协同得分加分
UserScore.joint(:post_issue_message, self.user,self.issue.author,self, { message_id: self.id }) UserScore.joint(:post_issue_message, self.user,self.issue.author,self, { message_id: self.id })
update_messges_for_issue(self.user,1)
end end
#update_messges_for_issue(User.current,1)
end end
# 减少用户分数 -by zjc # 减少用户分数 -by zjc
def down_user_score def down_user_score
@ -171,7 +172,8 @@ class Journal < ActiveRecord::Base
if !self.notes.nil? && self.notes.gsub(' ','') != '' if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分减分 #协同得分减分
UserScore.joint(:delete_issue_message, self.user,self.issue.author,self, { message_id: self.id }) UserScore.joint(:delete_issue_message, self.user,self.issue.author,self, { message_id: self.id })
update_messges_for_issue(self.user,1)
end end
#update_messges_for_issue(User.current,1)
end end
end end

View File

@ -19,9 +19,9 @@ class JournalDetail < ActiveRecord::Base
include UserScoreHelper include UserScoreHelper
belongs_to :journal belongs_to :journal
before_save :normalize_values before_save :normalize_values
after_create :be_user_score after_save :be_user_score
#after_destroy :down_user_score after_destroy :down_user_score
before_destroy :down_user_score #before_destroy :down_user_score
private private
def normalize_values def normalize_values
@ -45,23 +45,21 @@ class JournalDetail < ActiveRecord::Base
def be_user_score def be_user_score
#更新缺陷完成度 #更新缺陷完成度
if self.prop_key == 'done_ratio' if self.prop_key == 'done_ratio'
#update_issue_done_ratio(User.current,1) update_issue_done_ratio(self.journal.user,1)
#更新缺陷状态 #更新缺陷状态
elsif self.prop_key == 'status_id' elsif self.prop_key == 'status_id'
#update_issues_status(User.current , 1) update_issues_status(self.journal.user , 1)
end end
end end
#更新用户分数 #更新用户分数
def down_user_score def down_user_score
#update_issue_done_ratio(User.current,1)
#update_issues_status(User.current , 1)
if self.prop_key == 'done_ratio' if self.prop_key == 'done_ratio'
update_issue_done_ratio(self.journal.user,1)
#更新缺陷状态 #更新缺陷状态
elsif self.prop_key == 'status_id' elsif self.prop_key == 'status_id'
UserScore.joint(:delete_issue_status, self.journal.user,nil,self, {issue_id: self.id}) update_issues_status(self.journal.user, 1)
end end
end end

View File

@ -54,10 +54,10 @@ class JournalsForMessage < ActiveRecord::Base
validates :notes, presence: true validates :notes, presence: true
after_create :act_as_activity #huang after_create :act_as_activity #huang
after_create :reset_counters!,:be_user_score after_create :reset_counters!
after_destroy :reset_counters! after_destroy :reset_counters!
#before_save :be_user_score after_save :be_user_score
#before_destroy :down_user_score after_destroy :down_user_score
# default_scope { where('m_parent_id IS NULL') } # default_scope { where('m_parent_id IS NULL') }
@ -142,8 +142,8 @@ class JournalsForMessage < ActiveRecord::Base
#新建了留言回复 #新建了留言回复
if self.reply_id != 0 if self.reply_id != 0
#协同得分加分 #协同得分加分
UserScore.joint(:reply_message, User.current,User.find(self.reply_id),self, { journals_for_messages_id: self.id }) UserScore.joint(:reply_message, self.user,User.find(self.reply_id),self, { journals_for_messages_id: self.id })
update_replay_for_message(User.current,1) update_replay_for_message(self.user,1)
end end
end end
# 更新用户分数 -by zjc # 更新用户分数 -by zjc
@ -151,7 +151,8 @@ class JournalsForMessage < ActiveRecord::Base
#删除了留言回复 #删除了留言回复
if self.reply_id != 0 if self.reply_id != 0
#协同得分减分 #协同得分减分
UserScore.joint(:reply_message_delete, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id }) UserScore.joint(:reply_message_delete, self.user,User.find(self.reply_id), { journals_for_messages_id: self.id })
update_replay_for_message(self.user,1)
end end
end end
end end

View File

@ -14,6 +14,7 @@ class Memo < ActiveRecord::Base
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC" acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"
acts_as_attachable acts_as_attachable
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id' belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
# acts_as_searchable :column => ['subject', 'content'], # acts_as_searchable :column => ['subject', 'content'],
# #:include => { :forum => :p} # #:include => { :forum => :p}

View File

@ -21,6 +21,8 @@ class Message < ActiveRecord::Base
belongs_to :board belongs_to :board
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
acts_as_attachable acts_as_attachable
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
@ -59,12 +61,11 @@ class Message < ActiveRecord::Base
after_create :add_author_as_watcher, :reset_counters! after_create :add_author_as_watcher, :reset_counters!
after_update :update_messages_board after_update :update_messages_board
after_destroy :reset_counters!#,:down_user_score after_destroy :reset_counters!,:down_user_score
# fq # fq
after_create :act_as_activity,:be_user_score after_create :act_as_activity,:be_user_score
#before_save :be_user_score #before_save :be_user_score
before_destroy :down_user_score
# end # end
scope :visible, lambda {|*args| scope :visible, lambda {|*args|
@ -151,11 +152,11 @@ class Message < ActiveRecord::Base
#新建message且无parent的为发帖 #新建message且无parent的为发帖
if self.parent_id.nil? && !self.board.project.nil? if self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:post_message, self.author,nil,self, { message_id: self.id }) UserScore.joint(:post_message, self.author,nil,self, { message_id: self.id })
#update_memo_number(User.current,1) update_memo_number(User.current,1)
#新建message且有parent的为回帖 #新建message且有parent的为回帖
elsif !self.parent_id.nil? && !self.board.project.nil? elsif !self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:reply_posting, self.author,self.parent.author,self, { message_id: self.id }) UserScore.joint(:reply_posting, self.author,self.parent.author,self, { message_id: self.id })
#update_replay_for_memo(User.current,1) update_replay_for_memo(User.current,1)
end end
end end
@ -163,10 +164,10 @@ class Message < ActiveRecord::Base
def down_user_score def down_user_score
if self.parent_id.nil? && !self.board.project.nil? if self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:delete_message, self.author,nil,self, { message_id: self.id }) UserScore.joint(:delete_message, self.author,nil,self, { message_id: self.id })
update_memo_number(User.current,1)
elsif !self.parent_id.nil? && !self.board.project.nil? elsif !self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:reply_deleting, self.author,self.parent.author,self, { message_id: self.id }) UserScore.joint(:reply_deleting, self.author,self.parent.author,self, { message_id: self.id })
update_replay_for_memo(User.current,1)
end end
#update_memo_number(User.current,1)
#update_replay_for_memo(User.current,1)
end end
end end

View File

@ -3,7 +3,8 @@ class PraiseTread < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :praise_tread_object, polymorphic: true belongs_to :praise_tread_object, polymorphic: true
after_create :be_user_score after_create :be_user_score
after_destroy :down_user_score
include UserScoreHelper
def self.find_object_by_type_and_id(type,id) def self.find_object_by_type_and_id(type,id)
@obj = nil @obj = nil
case type case type
@ -28,7 +29,7 @@ class PraiseTread < ActiveRecord::Base
# 获取裁定对象为Message时Message所属的项目或课程 # 获取裁定对象为Message时Message所属的项目或课程
def project def project
project = nil project = nil
if self.praise_tread_object_type == 'Message' if self.praise_tread_object_type == 'Message' || self.praise_tread_object_type == 'Issues'
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
project = obj.project project = obj.project
end end
@ -38,15 +39,37 @@ class PraiseTread < ActiveRecord::Base
#更新用户分数 - by zjc #更新用户分数 - by zjc
def be_user_score def be_user_score
#踩贴吧或讨论区帖子 #踩贴吧或讨论区帖子
if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author target_user = obj.author
UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id })
update_tread(User.current,1)
update_tread(target_user,1)
#顶贴吧或讨论区帖子 #顶贴吧或讨论区帖子
elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author target_user = obj.author
UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
update_praise(target_user,1)
#更新用户等级
UserLevels.update_user_level(target_user)
end
end
def down_user_score
#踩贴吧或讨论区帖子
if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
#UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id })
update_tread(User.current,1)
update_tread(target_user,1)
#顶贴吧或讨论区帖子
elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
#UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
update_praise(target_user,1)
#更新用户等级 #更新用户等级
UserLevels.update_user_level(target_user) UserLevels.update_user_level(target_user)
end end

View File

@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Watcher < ActiveRecord::Base class Watcher < ActiveRecord::Base
include UserScoreHelper
belongs_to :watchable, :polymorphic => true belongs_to :watchable, :polymorphic => true
belongs_to :user belongs_to :user
#Added by nie #Added by nie
@ -23,7 +24,7 @@ class Watcher < ActiveRecord::Base
has_one :users_status has_one :users_status
#end #end
after_create :be_user_score after_create :be_user_score
before_destroy :down_user_score after_destroy :down_user_score
validates_presence_of :user validates_presence_of :user
validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id] validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id]
@ -79,6 +80,7 @@ class Watcher < ActiveRecord::Base
if self.watchable_type == 'Principal' if self.watchable_type == 'Principal'
#影响力得分 #影响力得分
UserScore.influence(:followed_by, self.user,self.watchable,self, { watcher_id: self.id }) UserScore.influence(:followed_by, self.user,self.watchable,self, { watcher_id: self.id })
update_follow(self.watchable,1)
end end
end end
@ -87,6 +89,7 @@ class Watcher < ActiveRecord::Base
#取消关注 #取消关注
if self.watchable_type == 'Principal' if self.watchable_type == 'Principal'
UserScore.influence(:cancel_followed, self.user,self.watchable,self, { watcher_id: self.id }) UserScore.influence(:cancel_followed, self.user,self.watchable,self, { watcher_id: self.id })
update_follow(self.watchable,1)
end end
end end

View File

@ -23,7 +23,7 @@
<% else%> <% else%>
<%= content_tag "div", content_tag("p", rolesToLanguage(member.roles.sort.collect(&:to_s)).join(', ')), :class => "clear avatar_name" %> <%= content_tag "div", content_tag("p", rolesToLanguage(member.roles.sort.collect(&:to_s)).join(', ')), :class => "clear avatar_name" %>
<div class="clear avatar_user"> <div class="clear avatar_user">
<p> <p> <!--user_scores(member.user,2,@project).total_score).to_i -->
<%= l(:label_user_for_project_grade) %>: <span style="color:#ec6300"><%= format("%.2f" ,UserGrade.find_by_user_id_and_project_id(member[:user_id], @project.id).grade).to_i %></span> <%= l(:label_user_for_project_grade) %>: <span style="color:#ec6300"><%= format("%.2f" ,UserGrade.find_by_user_id_and_project_id(member[:user_id], @project.id).grade).to_i %></span>
</p> </p>
</div> </div>

View File

@ -128,7 +128,7 @@
<% if @project.project_type !=1 %> <% if @project.project_type !=1 %>
<%= l(:label_project_grade)%>: <%= l(:label_project_grade)%>:
<span > <span >
<%= link_to(format("%.2f" , project_scores(@project) ).to_i, <%= link_to(format("%.2f" , red_project_scores(@project) ).to_i,
{:controller => 'projects', {:controller => 'projects',
:action => 'show_projects_score', :action => 'show_projects_score',
:remote => true, :id => @project.id}, :style=>"color: #EC6300;") %> :remote => true, :id => @project.id}, :style=>"color: #EC6300;") %>

View File

@ -1,6 +1,7 @@
<%= l(:label_user_grade)%>: <%= l(:label_user_grade)%>:
<!-- user.user_score_attr.total_score --> <!-- user.user_score_attr.total_score -->
<%= link_to(format("%.2f" ,user_scores(user,1).total_score ).to_i, {:controller => 'users', <!-- user_scores(user,1).total_score -->
<%= link_to(format("%.2f" ,get_option_number(user,1).total_score ).to_i, {:controller => 'users',
:action => 'show_new_score', :action => 'show_new_score',
:remote => true, :remote => true,
:id => user.id :id => user.id

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140801034242) do ActiveRecord::Schema.define(:version => 20140811022947) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -772,6 +772,13 @@ ActiveRecord::Schema.define(:version => 20140801034242) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
create_table "project_scores", :force => true do |t|
t.string "project_id"
t.integer "score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "project_statuses", :force => true do |t| create_table "project_statuses", :force => true do |t|
t.integer "changesets_count" t.integer "changesets_count"
t.integer "watchers_count" t.integer "watchers_count"