2016-12-22 15:08:15 +08:00
|
|
|
class AppliedContest < ActiveRecord::Base
|
2016-12-22 17:13:10 +08:00
|
|
|
include ContestsHelper
|
2016-12-22 15:08:15 +08:00
|
|
|
belongs_to :contest
|
|
|
|
belongs_to :user
|
|
|
|
#status :0 新建 1 已批准 2 拒绝
|
|
|
|
attr_accessible :role, :status, :contest_id, :user_id
|
|
|
|
|
|
|
|
has_many :applied_messages, :class_name => 'AppliedMessage', :as => :applied, :dependent => :destroy
|
|
|
|
after_create :send_appliled_message
|
|
|
|
|
2016-12-28 11:30:31 +08:00
|
|
|
# 仅仅给竞赛管理人员发送消息
|
2016-12-22 15:08:15 +08:00
|
|
|
def send_appliled_message
|
2016-12-22 17:13:10 +08:00
|
|
|
case self.role
|
|
|
|
when '13'
|
|
|
|
role = 1
|
|
|
|
when '14'
|
|
|
|
role = 2
|
|
|
|
when '15'
|
|
|
|
role = 3
|
|
|
|
end
|
|
|
|
contest_managers(self.contest).each do |member|
|
2016-12-28 11:30:31 +08:00
|
|
|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :role => role)
|
2016-12-22 15:08:15 +08:00
|
|
|
end
|
|
|
|
# end
|
|
|
|
end
|
|
|
|
end
|