打分初步

This commit is contained in:
yanxd 2014-06-06 17:33:42 +08:00
parent 8b176c0027
commit dfde06248c
3 changed files with 111 additions and 6 deletions

View File

@ -45,3 +45,9 @@ app\controller\welcome_controller.rb
end
end
================================================================================
================================================================================
0606新坑
user_scores表结构有问题需要运行
bundle exec rake db:migrate:down VERSION=20140410021724
bundle exec rake db:migrate:up VERSION=20140410021724

View File

@ -33,4 +33,101 @@ class UserScore < ActiveRecord::Base
def self.find_min_issue
self.minimum(:file)
end
# 以上类方法目测没用,反正也报错
# ===============================================================================
# 前略·协同得分
# operate - 更新操作 类型 symbol
# user - 计分用户
#
# Examples
#
# UserScore.joint(:post_message, User.current, nil)
# # => true #当前用户发帖计分操作成功
#
# Returns boolean. 返回积分保存结果
def self.joint(operate, current_user, target_user, options={})
user_obj = (user.kind_of?User) ? user : User.find_by_id(user)
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
Rails.logger.error "[UserScore#skill] ===> #{operate} is not define."
return false
end
end
private
def get_users(current_user, target_user)
cUser = nil
tUser = nil
@current_user, @target_user = cUser, tUser
end
end

View File

@ -923,11 +923,13 @@ ActiveRecord::Schema.define(:version => 20140605025247) do
add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id"
create_table "user_scores", :force => true do |t|
t.integer "user_id"
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "activity"
t.integer "user_id", :null => false
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "user_statuses", :force => true do |t|