Conflicts:
	app/controllers/account_controller.rb
president
linchun 11 years ago
commit 9c5066b81c

@ -42,6 +42,24 @@ group :ldap do
gem "net-ldap", "~> 0.3.1"
end
group :test do
# shoulda的版本做了改动
#gem "shoulda", "~> 3.3.2"
gem "shoulda", "> 3.3.2"
gem "mocha", "~> 0.13.3"
gem 'capybara', '~> 2.0.0'
gem 'nokogiri', '< 1.6.0'
end
platforms :mri, :mingw do
group :rmagick do
# RMagick 2 supports ruby 1.9
# RMagick 1 would be fine for ruby 1.8 but Bundler does not support
# different requirements for the same gem on different platforms
gem "rmagick", ">= 2.0.0"
end
end
# Optional gem for OpenID authentication
group :openid do
gem "ruby-openid", "~> 2.1.4", :require => "openid"

@ -52,6 +52,15 @@ GEM
rails (>= 3, < 5)
arel (3.0.2)
builder (3.0.0)
capybara (2.0.3)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 1.0.0)
childprocess (0.5.3)
ffi (~> 1.0, >= 1.0.11)
coderay (1.0.9)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
@ -64,6 +73,7 @@ GEM
execjs (1.4.0)
multi_json (~> 1.0)
fastercsv (1.5.0)
ffi (1.9.3-x86-mingw32)
hike (1.2.3)
i18n (0.6.1)
journey (1.0.4)
@ -74,10 +84,14 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.4)
mime-types (1.23)
mocha (0.13.3)
metaclass (~> 0.0.1)
multi_json (1.7.6)
mysql2 (0.3.11-x86-mingw32)
net-ldap (0.3.1)
nokogiri (1.5.11-x86-mingw32)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
@ -104,15 +118,28 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.4)
rake (10.3.2)
rdoc (3.12.2)
json (~> 1.4)
rmagick (2.13.2)
ruby-openid (2.1.8)
rubyzip (1.1.4)
sass (3.2.7)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
selenium-webdriver (2.42.0)
childprocess (>= 0.5.0)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0.4)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.6.1)
activesupport (>= 3.0.0)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
@ -127,6 +154,9 @@ GEM
uglifier (1.0.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
websocket (1.0.7)
xpath (1.0.0)
nokogiri (~> 1.3)
PLATFORMS
x86-mingw32
@ -137,17 +167,22 @@ DEPENDENCIES
acts-as-taggable-on (= 2.4.1)
better_errors!
builder (= 3.0.0)
capybara (~> 2.0.0)
coderay (~> 1.0.6)
coffee-rails (~> 3.2.1)
fastercsv (~> 1.5.0)
i18n (~> 0.6.0)
jquery-rails (~> 2.0.2)
mocha (~> 0.13.3)
mysql2 (~> 0.3.11)
net-ldap (~> 0.3.1)
nokogiri (< 1.6.0)
rack-mini-profiler!
rack-openid
rails (= 3.2.13)
rmagick (>= 2.0.0)
ruby-openid (~> 2.1.4)
sass-rails (~> 3.2.3)
seems_rateable!
shoulda (> 3.3.2)
uglifier (>= 1.0.3)

@ -143,16 +143,17 @@ class AccountController < ApplicationController
end
#added by bai
unless @user.id.nil?
ue = @user.extensions
ue.identity = params[:identity]
ue.technical_title = params[:technical_title]
ue.gender = params[:gender]
ue.student_id = params[:no]
ue.location = params[:province]
ue.location_city = params[:city]
@user.save
if @user.id != nil
ue = @user.user_extensions ||= UserExtensions.new
#ue = UserExtensions.create(:identity => params[:identity].to_i,:technical_title => params[:technical_title], :gender => params[:gender].to_i, :user_id => @user.id, :student_id => )
ue.identity = params[:identity].to_i
ue.technical_title = params[:technical_title]
ue.gender = params[:gender].to_i
ue.user_id = @user.id
ue.student_id = params[:no]
ue.location = params[:province] if params[:province] != nil
ue.location_city = params[:city] if params[:city] != nil
ue.save
end
end

@ -59,6 +59,8 @@ class AttachmentsController < ApplicationController
:type => detect_content_type(@attachment),
:disposition => (@attachment.image? ? 'inline' : 'attachment')
end
rescue => e
redirect_to "http://forge.trustie.net/file_not_found.html"
end
#更新资源文件类型

@ -1,4 +1,5 @@
class HomeworkAttachController < ApplicationController
include CoursesHelper
###############################
#判断当前角色权限时需先找到当前操作的project
before_filter :find_project_by_bid_id, :only => [:new]
@ -77,6 +78,15 @@ class HomeworkAttachController < ApplicationController
if bid.homeworks.where("user_id = ?",User.current).count == 0
user_id = params[:user_id]
bid_id = params[:bid_id]
if params[:homework_attach]
if params[:homework_attach][:project_id]
project_id = params[:homework_attach][:project_id]
else
project_id = 0
end
else
project_id = 0
end
sta = 0
name = params[:new_form][:name]
description = params[:new_form][:description]
@ -85,7 +95,8 @@ class HomeworkAttachController < ApplicationController
:state => sta,
:name => name,
:description => description,
:bid_id => bid_id
:bid_id => bid_id,
:project_id => project_id
}
@ -177,8 +188,18 @@ class HomeworkAttachController < ApplicationController
if User.current.admin? || User.current.member_of?(course)
name = params[:homework_name]
description = params[:homework_description]
if params[:homework_attach]
if params[:homework_attach][:project_id]
project_id = params[:homework_attach][:project_id]
else
project_id = 0
end
else
project_id = 0
end
@homework.name = name
@homework.description = description
@homework.project_id = project_id
if params[:attachments]
@homework.save_attachments(params[:attachments])
end
@ -196,7 +217,7 @@ class HomeworkAttachController < ApplicationController
def destroy
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current == @homework
if User.current.admin? || User.current == @homework.user
if @homework.destroy
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
@ -237,6 +258,9 @@ class HomeworkAttachController < ApplicationController
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
@totle_score = score_for_homework @homework
@teaher_score = teacher_score_for_homework @homework
else
render_403 :message => :notice_not_authorized
end
@ -268,6 +292,9 @@ class HomeworkAttachController < ApplicationController
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
@totle_score = score_for_homework @homework
@teaher_score = teacher_score_for_homework @homework
respond_to do |format|
format.js
end

@ -9,9 +9,12 @@ class PraiseTreadController < ApplicationController
if request.get?
@obj_id = params[:obj_id]
@obj_type = params[:obj_type]
@horizontal = params[:horizontal]
@horizontal = params[:horizontal].downcase == "false" ? false:true
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
praise_tread_plus(@obj_type,@obj_id,1)
unless @obj.author_id == User.current.id
praise_tread_plus(@obj_type,@obj_id,1)
end
end
end
@ -45,9 +48,12 @@ class PraiseTreadController < ApplicationController
if request.get?
@obj_id = params[:obj_id]
@obj_type = params[:obj_type]
@horizontal = params[:horizontal]
@horizontal = params[:horizontal].downcase == "false" ? false:true
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
praise_tread_plus(@obj_type,@obj_id,0)
unless @obj.author_id == User.current.id
praise_tread_plus(@obj_type,@obj_id,0)
end
end
end

@ -32,12 +32,14 @@ class UsersController < ApplicationController
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score]
#edit has been deleted by huang, 2013-9-23
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index]
before_filter :auth_user_extension, only: :show
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
@ -94,6 +96,10 @@ class UsersController < ApplicationController
def show_score
end
def show_new_score
end
# end
##added by fq
@ -767,7 +773,30 @@ class UsersController < ApplicationController
end
# end
def topic_new_score_index
end
def project_new_score_index
end
def activity_new_score_index
end
def influence_new_score_index
end
def score_new_index
end
def update_score
@user = User.find(params[:id])
end
private
def find_user

@ -27,7 +27,7 @@ class ZipdownController < ApplicationController
else
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
end
send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile
send_file zipfile, :filename => obj.name+".zip", :type => detect_content_type(zipfile) if zipfile
#rescue NameError, ActiveRecord::RecordNotFound => e
#logger.error "[ZipDown] ===> #{e}"
@ -39,7 +39,7 @@ class ZipdownController < ApplicationController
homework = HomeworkAttach.find params[:homework]
if homework != nil && (User.current.admin? || User.current.member_of?(homework.bid.courses.first))
zipfile = zip_homework_by_user homework
send_file zipfile, :filename => homework.name, :type => detect_content_type(zipfile) if zipfile
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
else
render_403 :message => :notice_not_authorized
end
@ -88,7 +88,7 @@ class ZipdownController < ApplicationController
#length = attach.storage_path.length
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
end
zipping "#{homeattach.user.name.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
zipping "#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
#user_attaches_paths
end

@ -182,4 +182,71 @@ module CoursesHelper
def users_for_homework homework
homework.nil? ? [] : (homework.users + [homework.user])
end
#获取指定作业的最终评分
#最终评分 = 学生评分的平均分 * 0.4 +教师评分 * 0.6
def score_for_homework homework
if homework.bid.is_evaluation == 1 || homework.bid.is_evaluation == nil
return format("%.2f",(teacher_score_for_homework(homework).to_f * 0.6 + student_score_for_homework(homework).to_f * 0.4))
else
return teacher_score_for_homework homework
end
end
#获取作业的互评得分
def student_score_for_homework homework
member = searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first
student_stars = homework.rates(:quality).where("rater_id <> #{member.user_id}").select("stars")
student_stars_count = 0
student_stars.each do |star|
student_stars_count = student_stars_count + star.stars
end
return format("%.2f",student_stars_count / (student_stars.count == 0 ? 1 : student_stars.count))
end
#获取作业的教师评分
def teacher_score_for_homework homework
member = searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first
teacher_stars = homework.rates(:quality).where("rater_id = #{member.user_id}").select("stars").first
return format("%.2f",teacher_stars == nil ? 0 : teacher_stars.stars)
end
#获取指定作业的得分
def project_score project
issue_count = project.issues.count
issue_journal_count = project.issue_changes.count
issue_score = issue_count * 0.2
issue_journal_score = issue_journal_count * 0.1
finall_issue_score = issue_score + issue_journal_score
new_count = project.news.count
new_score = new_count * 0.1
finall_new_score = new_score
document_count = project.documents.count
file_score = document_count * 0.1
finall_file_score = file_score
changeset_count = project.changesets.count
code_submit_score = changeset_count * 0.3
finall_code_submit_score = code_submit_score
board_message_count = 0
project.boards.each do |board|
board_message_count += board.messages_count
end
topic_score = board_message_count * 0.1
#finall_topic_score = topic_score
finall_project_score = finall_issue_score + finall_new_score + finall_file_score + finall_code_submit_score + topic_score
format("%.2f",finall_project_score)
end
#获取指定作业的参与人员
#返回结果:张三、李四、王五
def homework_user_of_homework homework,is_teacher
homework_users = ""
homework.users.each do |user|
homework_users = homework_users + (is_teacher ? user.realname : user.name)
if user != homework.users.last
homework_users = homework_users + ""
end
end
return homework_users
end
end

@ -54,4 +54,24 @@ module HomeworkAttachHelper
raise RuntimeError, 'unknow type, Please input you type into this helper.'
end
end
def user_projects_option
cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
memberships = User.current.memberships.all(:conditions => cond)
projects = memberships.map(&:project)
not_have_project = []
not_have_project << "<<NULL>>"
not_have_project << 0
type = []
type << not_have_project
projects.each do |project|
if project != nil
option = []
option << project.name
option << project.id
type << option
end
end
type
end
end

@ -70,7 +70,7 @@ module JournalsHelper
content << textilizable(journal, :notes)
css_classes = "wiki"
css_classes << " editable" if editable
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes ,:style => "width:580px")
end
def link_to_in_place_notes_editor(text, field_id, url, options={})

@ -370,7 +370,7 @@ class Attachment < ActiveRecord::Base
type = self.container_type
types = %w|Document News Version Project Issue Message WikiPage|
if types.include?(type)
UserScore.project(:push_file, User.current, { attachment_id: self.id })
UserScore.project(:push_file, User.current,self, { attachment_id: self.id })
end
end
end

@ -19,7 +19,7 @@ class Changeset < ActiveRecord::Base
belongs_to :repository
belongs_to :user
after_save :be_user_score # user_score
#after_save :be_user_score # user_score
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
# fq
@ -63,7 +63,7 @@ class Changeset < ActiveRecord::Base
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
}
after_create :scan_for_issues
after_create :scan_for_issues,:be_user_score # user_score
before_create :before_create_cs
# fq
@ -300,11 +300,9 @@ class Changeset < ActiveRecord::Base
# update user score
def be_user_score
if self.new_record?
UserScore.project(:push_code, self.user, { changeset_id: self.id })
UserScore.project(:push_code, self.user,self, { changeset_id: self.id })
#更新用户等级
self.user.update_user_level
end
UserLevels.update_user_level(self.user)
end
end

@ -21,7 +21,7 @@ class Document < ActiveRecord::Base
belongs_to :user
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
before_save :be_user_score # user_score
after_create :be_user_score # user_score
acts_as_attachable :delete_permission => :delete_documents
@ -62,8 +62,6 @@ class Document < ActiveRecord::Base
# update user score
def be_user_score
if self.new_record?
UserScore.project(:push_document, self.user, { document_id: self.id })
end
UserScore.project(:push_document, self.user,self,{ document_id: self.id })
end
end

@ -9,6 +9,7 @@ class HomeworkAttach < ActiveRecord::Base
has_many :homework_users, :dependent => :destroy
has_many :users, :through => :homework_users
seems_rateable :allow_update => true, :dimensions => :quality
belongs_to :project
safe_attributes "bid_id",
"user_id"
@ -30,7 +31,7 @@ class HomeworkAttach < ActiveRecord::Base
result
end
def project
def project_for_homework
work = HomeworkForCourse.find_by_bid_id(self.bid_id)
if work
work.project

@ -76,8 +76,8 @@ class Issue < ActiveRecord::Base
attr_reader :current_journal
# fq
after_create :act_as_activity
before_save :be_user_score
after_create :act_as_activity,:be_user_score_new_issue
after_update :be_user_score
# after_create :be_user_score
# end
@ -1489,14 +1489,19 @@ class Issue < ActiveRecord::Base
# update user score
def be_user_score
if self.new_record?
UserScore.project(:post_issue, User.current, { issue_id: self.id })
elsif self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current, { issue_id: self.id })
#缺陷完成度更新
if self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id })
end
#缺陷状态更改
elsif self.status_id_changed?
#协同得分
UserScore.joint(:change_issue_status, User.current,nil, {issue_id: self.id})
if self.status_id_changed?
#协同得分
UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id})
end
end
#发布缺陷
def be_user_score_new_issue
UserScore.project(:post_issue, User.current,self, { issue_id: self.id })
end
end

@ -45,10 +45,10 @@ class Journal < ActiveRecord::Base
before_create :split_private_notes
# fq
after_create :act_as_activity
after_create :act_as_activity,:be_user_score
# end
before_save :be_user_score
#before_save :be_user_score
#before_destroy :down_user_score
scope :visible, lambda {|*args|
@ -158,9 +158,9 @@ class Journal < ActiveRecord::Base
# 更新用户分数 -by zjc
def be_user_score
#新建了缺陷留言且留言不为空,不为空白
if self.new_record? && !self.notes.nil? && self.notes.gsub(' ','') != ''
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分加分
UserScore.joint(:post_issue, User.current,self.issue.author, { message_id: self.id })
UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id })
end
end
# 减少用户分数 -by zjc
@ -168,7 +168,7 @@ class Journal < ActiveRecord::Base
#删除有效缺陷留言
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分减分
UserScore.joint(:delete_issue, User.current,self.issue.author, { message_id: self.id })
UserScore.joint(:delete_issue_message, User.current,self.issue.author, { message_id: self.id })
end
end
end

@ -40,9 +40,9 @@ class JournalsForMessage < ActiveRecord::Base
validates :notes, presence: true
after_create :act_as_activity #huang
after_create :reset_counters!
after_create :reset_counters!,:be_user_score
after_destroy :reset_counters!
before_save :be_user_score
#before_save :be_user_score
#before_destroy :down_user_score
# default_scope { where('m_parent_id IS NULL') }
@ -105,9 +105,9 @@ class JournalsForMessage < ActiveRecord::Base
# 更新用户分数 -by zjc
def be_user_score
#新建了留言回复
if self.new_record? && self.reply_id != 0
if self.reply_id != 0
#协同得分加分
UserScore.joint(:reply_message, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id })
UserScore.joint(:reply_message, User.current,User.find(self.reply_id),self, { journals_for_messages_id: self.id })
end
end
# 更新用户分数 -by zjc

@ -75,7 +75,12 @@ class Mailer < ActionMailer::Base
return -1
end
mail :to => journals_for_message.jour.author.mail, :subject => @title
else
elsif journals_for_message.jour.class.to_s.to_sym == :Contest
if !journals_for_message.jour.author.notify_about? journals_for_message
return -1
end
mail :to => journals_for_message.jour.author.mail, :subject => @title
else
mail :to => @mail.mail, :subject => @title
end

@ -12,6 +12,7 @@ class Memo < ActiveRecord::Base
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"
acts_as_attachable
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
# acts_as_searchable :column => ['subject', 'content'],
# #:include => { :forum => :p}
@ -40,13 +41,13 @@ class Memo < ActiveRecord::Base
"parent_id",
"replies_count"
after_create :add_author_as_watcher, :reset_counters!
after_create :add_author_as_watcher, :reset_counters!,:be_user_score
# after_update :update_memos_forum
after_destroy :reset_counters!
# after_create :send_notification
# after_save :plusParentAndForum
# after_destroy :minusParentAndForum
before_save :be_user_score
#before_save :be_user_score
# scope :visible, lambda { |*args|
# includes(:forum => ).where()
# }
@ -145,11 +146,11 @@ class Memo < ActiveRecord::Base
#更新用户分数 -by zjc
def be_user_score
#新建memo且无parent的为发帖
if self.new_record? && self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil, { memo_id: self.id })
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id })
#新建memo且有parent的为回帖
elsif self.new_record? && !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author, { memo_id: self.id })
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id })
end
end

@ -53,8 +53,8 @@ class Message < ActiveRecord::Base
after_destroy :reset_counters!
# fq
after_create :act_as_activity
before_save :be_user_score
after_create :act_as_activity,:be_user_score
#before_save :be_user_score
#before_destroy :down_user_score
# end
@ -127,11 +127,11 @@ class Message < ActiveRecord::Base
#更新用户分数 -by zjc
def be_user_score
#新建message且无parent的为发帖
if self.new_record? && self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil, { message_id: self.id })
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self, { message_id: self.id })
#新建message且有parent的为回帖
elsif self.new_record? && !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author, { message_id: self.id })
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { message_id: self.id })
end
end
#减少用户分数

@ -2,7 +2,7 @@ class PraiseTread < ActiveRecord::Base
attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread
belongs_to :user
belongs_to :praise_tread_object, polymorphic: true
before_save :be_user_score
after_create :be_user_score
def self.find_object_by_type_and_id(type,id)
@obj = nil
@ -28,17 +28,17 @@ class PraiseTread < ActiveRecord::Base
#更新用户分数 - by zjc
def be_user_score
#踩贴吧或讨论区帖子
if self.new_record? && 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 == 'Memo' || 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, { praise_tread_id: self.id })
UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id })
#顶贴吧或讨论区帖子
elsif self.new_record? && 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 == 'Memo' || 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,{ praise_tread_id: self.id })
UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
#更新用户等级
target_user.update_user_level
UserLevels.update_user_level(target_user)
end
end
end

@ -30,6 +30,7 @@ class Project < ActiveRecord::Base
# Specific overidden Activities
belongs_to :homework_attach
has_many :time_entry_activities
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'

@ -17,6 +17,6 @@ class ProjectInfo < ActiveRecord::Base
#更新用户等级
def update_user_level
self.user.update_user_level
UserLevels.update_user_level(self.user)
end
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save