socialforge/app/models/applied_contest.rb

29 lines
815 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
else
role = 4
end
contest_managers(self.contest).each do |member|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :applied_user_id => self.user_id, :role => role)
end
# end
end
end