socialforge/app/models/applied_project.rb

26 lines
841 B
Ruby
Raw Normal View History

class AppliedProject < ActiveRecord::Base
2016-07-28 16:22:33 +08:00
attr_accessible :project_id, :user_id, :role
belongs_to :user
belongs_to :project
2016-07-28 16:22:33 +08:00
has_many :applied_messages, :class_name => 'AppliedMessage', :as => :applied, :dependent => :destroy
after_create :send_appliled_message
2016-07-28 16:22:33 +08:00
# 仅仅给项目管理人员发送消息
def send_appliled_message
2016-07-28 16:22:33 +08:00
self.project.managers.each do |member|
2016-07-29 20:50:55 +08:00
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => true, :viewed => false, :applied_user_id => self.user_id, :role => self.role, :project_id => self.project_id)
end
# end
end
#删除用户申请
def self.deleteappiled(userid, projectid)
@applieds = AppliedProject.where("user_id = ? and project_id = ?", userid, projectid)
@applieds.each do |applied|
applied.destroy
end
end
end