2015-08-14 10:19:59 +08:00
|
|
|
|
class CourseMessage < ActiveRecord::Base
|
2015-12-11 17:02:34 +08:00
|
|
|
|
# status说明: status在课程不同的类型,区分不同的功能 status = 9 作品的提交记录
|
2016-05-19 11:32:58 +08:00
|
|
|
|
# ApplyResource status:
|
|
|
|
|
# 0: 发送申请 1:回复允许申请 2:拒绝申请消息
|
2015-09-28 15:35:08 +08:00
|
|
|
|
# HomeworkCommon:status:
|
2016-04-29 17:55:57 +08:00
|
|
|
|
# nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败; 5:申请引用作业, 6:申请结果
|
2016-04-29 15:46:26 +08:00
|
|
|
|
# apply_user_id: 申请者的用户id
|
2016-12-16 11:01:58 +08:00
|
|
|
|
# StudentWorksScoresAppeal: status:
|
|
|
|
|
# 1: 申诉中, 2:申诉撤销, 3:申诉成功, 4:申诉被拒绝
|
2016-04-29 15:46:26 +08:00
|
|
|
|
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status, :apply_user_id, :apply_result
|
2015-08-14 10:19:59 +08:00
|
|
|
|
|
|
|
|
|
# 多态 虚拟关联
|
|
|
|
|
belongs_to :course_message ,:polymorphic => true
|
|
|
|
|
belongs_to :course
|
|
|
|
|
belongs_to :user
|
2015-08-24 22:47:48 +08:00
|
|
|
|
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
|
|
|
|
|
2015-08-14 10:19:59 +08:00
|
|
|
|
validates :user_id,presence: true
|
|
|
|
|
validates :course_id,presence: true
|
|
|
|
|
validates :course_message_id,presence: true
|
|
|
|
|
validates :course_message_type, presence: true
|
2016-05-06 18:47:38 +08:00
|
|
|
|
#validates_length_of :content, :maximum => 100
|
2015-08-24 22:47:48 +08:00
|
|
|
|
after_create :add_user_message
|
|
|
|
|
|
|
|
|
|
def add_user_message
|
2015-10-20 17:27:06 +08:00
|
|
|
|
#unless self.course_message_type == 'JoinCourseRequest'
|
2015-12-11 17:02:34 +08:00
|
|
|
|
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? && self.status != 9
|
2015-10-20 17:27:06 +08:00
|
|
|
|
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
|
|
|
|
end
|
|
|
|
|
#end
|
2015-08-24 22:47:48 +08:00
|
|
|
|
end
|
2015-08-14 10:19:59 +08:00
|
|
|
|
end
|