积分修改

This commit is contained in:
z9hang 2014-07-24 18:05:37 +08:00
parent 6b441760c4
commit 4542b9e21a
11 changed files with 197 additions and 14 deletions

View File

@ -338,14 +338,44 @@ module UserScoreHelper
end
#====================================================================================================
def get_option_number(user,type)
def get_option_number(user,type,project_id=nil)
if project_id.nil?
option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}'");
if option_number.nil?
option_number = OptionNumber.new
option_number.user_id = user.id
option_number.score_type =type
else
option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}' and project_id = '#{project_id}'");
end
option_number
result = nil
if option_number.nil? || option_number.count == 0
result = OptionNumber.new
result.user_id = user.id
result.memo = 0
result.messages_for_issues = 0
result.issues_status = 0
result.replay_for_message = 0
result.replay_for_memo = 0
result.follow = 0
result.tread = 0
result.praise_by_one = 0
result.praise_by_two = 0
result.praise_by_three = 0
result.tread_by_one = 0
result.tread_by_two = 0
result.tread_by_three = 0
result.changeset = 0
result.document = 0
result.attachment = 0
result.issue_done_ratio = 0
result.post_issue = 0
result.total_score = 0
result.score_type =type
unless project_id.nil?
result.project_id = project_id
end
else
result = option_number.first
end
result
end
#更新分数
@ -374,7 +404,7 @@ module UserScoreHelper
#更新发帖数
def update_memo_number(user,type)
option_number = get_option_number(user,type)
option_number.memo = Message.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count
option_number.memo = Message.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count
update_score(option_number)
end
@ -401,7 +431,7 @@ module UserScoreHelper
#更新对帖子的回复数量
def update_replay_for_memo(user,type)
option_number = get_option_number(user,type)
option_number.replay_for_memo = Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").count
option_number.replay_for_memo = Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count + Memo.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count
update_score(option_number)
end
@ -412,5 +442,97 @@ module UserScoreHelper
update_score(option_number)
end
#更新踩别人帖子的数量
#更新帖子踩各项数量
def update_tread(user,type)
option_number = get_option_number(user,type)
option_number.tread = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0 and user_id = '#{user.id}'").all.count
pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0").all
result = []
result1 = []
result2 = []
pts.each do |pt|
obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id)
if obj.nil?
next
end
target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project
if level == 1 && target_user.id = user.id
result << pt
elsif level == 2 && target_user.id = user.id
result1 << pt
elsif level == 3 && target_user.id = user.id
result2 << pt
end
end
option_number.tread_by_one = result.count
option_number.tread_by_two = result1.count
option_number.tread_by_three = result2.count
update_score(option_number)
end
#更新帖子顶数量
def update_praise(user,type)
option_number = get_option_number(user,type)
pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 1").all
result = []
result1 = []
result2 = []
pts.each do |pt|
obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id)
if obj.nil?
next
end
target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project
if level == 1 && target_user.id = user.id
result << pt
elsif level == 2 && target_user.id = user.id
result1 << pt
elsif level == 3 && target_user.id = user.id
result2 << pt
end
end
option_number.praise_by_one = result.count
option_number.praise_by_two = result1.count
option_number.praise_by_three = result2.count
update_score(option_number)
end
#更新提交代码次数
def update_changeset(user,type)
option_number = get_option_number(user,type)
option_number.changeset = Changeset.includes(:user).where("user_id = '#{user.id}'").all.count
update_score(option_number)
end
#更新文档提交次数
def update_document(user,type)
option_number = get_option_number(user,type)
option_number.document = Document.includes(:user).where("user_id = '#{user.id}'").all.count
update_score(option_number)
end
#更新附件提交数量
def update_attachment(user,type)
option_number = get_option_number(user,type)
option_number.attachment = Attachment.includes(:author).where("author_id = '#{user.id}'").all.count
update_score(option_number)
end
#更新缺陷完成度次数
def update_issue_done_ratio(user,type)
option_number = get_option_number(user,type)
option_number.issue_done_ratio = Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count
update_score(option_number)
end
#更新发布缺陷次数
def update_post_issue(user,type)
option_number = get_option_number(user,type)
option_number.post_issue = Issue.includes(:author).where("author_id = '#{user.id}'").all.count
update_score(option_number)
end
end

View File

@ -18,6 +18,7 @@
class Issue < ActiveRecord::Base
include Redmine::SafeAttributes
include Redmine::Utils::DateCalculation
include UserScoreHelper
belongs_to :project
belongs_to :tracker
@ -1507,17 +1508,20 @@ class Issue < ActiveRecord::Base
#缺陷完成度更新
if self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id })
#update_issue_done_ratio(User.current,1)
end
#缺陷状态更改
if self.status_id_changed?
#协同得分
UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id})
#update_issues_status(self.author , 1)
end
end
#发布缺陷
def be_user_score_new_issue
UserScore.project(:post_issue, User.current,self, { issue_id: self.id })
update_post_issue(self.author,1)
end

View File

@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Journal < ActiveRecord::Base
include UserScoreHelper
belongs_to :journalized, :polymorphic => true
# added as a quick fix to allow eager loading of the polymorphic association
# since always associated to an issue, for now
@ -161,6 +162,7 @@ class Journal < ActiveRecord::Base
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分加分
UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id })
update_messges_for_issue(User.current,1)
end
end
# 减少用户分数 -by zjc

View File

@ -16,9 +16,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class JournalDetail < ActiveRecord::Base
include UserScoreHelper
belongs_to :journal
before_save :normalize_values
after_create :be_user_score
private
def normalize_values
@ -38,4 +39,15 @@ class JournalDetail < ActiveRecord::Base
v
end
end
def be_user_score
#更新缺陷完成度
if self.prop_key = 'done_ratio'
update_issue_done_ratio(User.current,1)
#更新缺陷状态
elsif self.prop_key = 'status_id'
update_issues_status(User.current , 1)
end
end
end

View File

@ -3,6 +3,7 @@
# 注意reply_id 是提到人的id不是留言id, Base中叫做 at_user
class JournalsForMessage < ActiveRecord::Base
include Redmine::SafeAttributes
include UserScoreHelper
safe_attributes "jour_type", # 留言所属类型
"jour_id", # 留言所属类型的id
"notes", # 留言内容
@ -132,6 +133,7 @@ class JournalsForMessage < ActiveRecord::Base
if self.reply_id != 0
#协同得分加分
UserScore.joint(:reply_message, User.current,User.find(self.reply_id),self, { journals_for_messages_id: self.id })
update_replay_for_message(User.current,1)
end
end
# 更新用户分数 -by zjc

View File

@ -1,5 +1,6 @@
class Memo < ActiveRecord::Base
include Redmine::SafeAttributes
include UserScoreHelper
belongs_to :forum
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
@ -148,9 +149,11 @@ class Memo < ActiveRecord::Base
#新建memo且无parent的为发帖
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id })
update_memo_number(User.current,1)
#新建memo且有parent的为回帖
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id })
update_replay_for_memo(User.current,1)
end
end

View File

@ -17,6 +17,8 @@
class Message < ActiveRecord::Base
include Redmine::SafeAttributes
include UserScoreHelper
belongs_to :board
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
@ -149,9 +151,11 @@ class Message < ActiveRecord::Base
#新建message且无parent的为发帖
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self, { message_id: self.id })
update_memo_number(User.current,1)
#新建message且有parent的为回帖
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { message_id: self.id })
update_replay_for_memo(User.current,1)
end
end
#减少用户分数

View File

@ -0,0 +1,4 @@
class OptionNumber < ActiveRecord::Base
attr_accessible :attachment, :changeset, :document, :follow, :issue_done_ratio, :issues_status, :memo, :messages_for_issues, :post_issue, :praise_by_one, :praise_by_three, :praise_by_two, :replay_for_memo, :replay_for_message, :score_type, :total_score, :tread, :tread_by_one, :tread_by_three, :tread_by_two, :user_id
end

View File

@ -92,7 +92,7 @@ default:
domain: smtp.gmail.com
authentication: :plain
user_name: trustieforge@gmail.com
password: '!@#$%^&*()'
password: '!@#$%^&*('
# Absolute path to the directory where attachments are stored.
# The default is the 'files' directory in your Redmine instance.

View File

@ -0,0 +1,29 @@
class CreateOptionNumbers < ActiveRecord::Migration
def change
create_table :option_numbers do |t|
t.string :user_id
t.integer :memo
t.integer :messages_for_issues
t.integer :issues_status
t.integer :replay_for_message
t.integer :replay_for_memo
t.integer :follow
t.integer :tread
t.integer :praise_by_one
t.integer :praise_by_two
t.integer :praise_by_three
t.integer :tread_by_one
t.integer :tread_by_two
t.integer :tread_by_three
t.integer :changeset
t.integer :document
t.integer :attachment
t.integer :issue_done_ratio
t.integer :post_issue
t.integer :score_type
t.integer :total_score
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140723082637) do
ActiveRecord::Schema.define(:version => 20140724080319) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -717,7 +717,7 @@ ActiveRecord::Schema.define(:version => 20140723082637) do
end
create_table "option_numbers", :force => true do |t|
t.string "user_id"
t.integer "user_id"
t.integer "memo"
t.integer "messages_for_issues"
t.integer "issues_status"
@ -740,6 +740,7 @@ ActiveRecord::Schema.define(:version => 20140723082637) do
t.integer "total_score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "project_id"
end
create_table "praise_tread_caches", :force => true do |t|