socialforge/app/models/user_score.rb

134 lines
4.2 KiB
Ruby
Raw Normal View History

2014-06-04 10:08:54 +08:00
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class UserScore < ActiveRecord::Base
belongs_to :user
def self.find_max_file
self.maximum(:file)
end
def self.find_min_file
self.minimum(:file)
end
def self.find_max_issue
self.maximum(:issue)
end
def self.find_min_issue
self.minimum(:file)
end
2014-06-06 17:33:42 +08:00
# 以上类方法目测没用,反正也报错
# ===============================================================================
# 前略·协同得分
# operate - 更新操作 类型 symbol
# user - 计分用户
#
# Examples
#
# UserScore.joint(:post_message, User.current, nil)
# # => true #当前用户发帖计分操作成功
#
# Returns boolean. 返回积分保存结果
def self.joint(operate, current_user, target_user, options={})
case operate
when :post_message # current_user 发帖了
when :post_issue # current_user 对 target_user 的缺陷留言了
when :change_issue_status # current_user 更改了缺陷的状态
when :reply_message # current_user 对 target_user 留言的回复
when :reply_posting # current_user 对 target_user 帖子的回复
else
Rails.logger.error "[UserScore#joint] ===> #{operate} is not define."
return false
end
end
# 前略·影响力得分
# operate - 更新操作 类型 symbol
# user - 计分用户
#
# Examples
#
# UserScore.influence(:followed_by, user)
# # => true #当前被关注用户记分成功
#
# Returns boolean. 返回积分保存结果
def self.influence(operate, current_user, target_user, options={})
case operate
when :followed_by # current_user 关注了target_user
else
Rails.logger.error "[UserScore#influence] ===> #{operate} is not define."
return false
end
end
# 前略·技术得分
# operate - 更新操作 类型 symbol
# user - 计分用户
#
# Examples
#
# UserScore.skill(:followed_by, current_user, target_user)
# # => true #当前current_user对target_user用户帖子的记分成功
#
# Returns boolean. 返回积分保存结果
def self.skill(operate, current_user, target_user, options={})
case operate
when :treading # current_user 踩了 target_user 的帖子
when :treaded_by_user # current_user 踩了 target_user 的帖子
when :praise_by_user # current_user 顶了 target_user 的帖子
else
Rails.logger.error "[UserScore#skill] ===> #{operate} is not define."
return false
end
end
# 前略·项目得分
# operate - 更新操作 类型 symbol
# user - 计分用户
#
# Examples
#
# UserScore.project(:pull_code, current_user)
# # => true #当前current_user对项目贡献积分成功
#
# Returns boolean. 返回积分保存结果
def self.project(operate, current_user, options={})
case operate
when :push_code # current_user 提交了代码
when :push_document # current_user
when :push_file # current_user
when :update_issue # current_user
when :post_issue # current_user
else
2014-06-06 17:41:16 +08:00
Rails.logger.error "[UserScore#project] ===> #{operate} is not define."
2014-06-06 17:33:42 +08:00
return false
end
end
private
def get_users(current_user, target_user)
2014-06-06 17:41:16 +08:00
cUser = (current_user.kind_of?User) ? user : User.find_by_id(user)
tUser = (target_user.kind_of?User) ? user : User.find_by_id(user)
2014-06-06 17:33:42 +08:00
@current_user, @target_user = cUser, tUser
end
2014-06-04 10:08:54 +08:00
end