27 lines
753 B
Ruby
27 lines
753 B
Ruby
class AppliedContest < ActiveRecord::Base
|
|
include ContestsHelper
|
|
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
|
|
|
|
# 仅仅给竞赛管理人员发送消息
|
|
def send_appliled_message
|
|
case self.role
|
|
when '13'
|
|
role = 1
|
|
when '14'
|
|
role = 2
|
|
when '15'
|
|
role = 3
|
|
end
|
|
contest_managers(self.contest).each do |member|
|
|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :role => role)
|
|
end
|
|
# end
|
|
end
|
|
end
|