课程发布通知消息提示

This commit is contained in:
huang 2015-08-14 10:19:59 +08:00
parent 6334df531e
commit a5c941f48c
5 changed files with 53 additions and 2 deletions

View File

@ -37,6 +37,7 @@ class Course < ActiveRecord::Base
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
has_many :course_activities
has_many :course_messages
acts_as_taggable
acts_as_nested_set :order => 'name', :dependent => :destroy

View File

@ -0,0 +1,12 @@
class CourseMessage < ActiveRecord::Base
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed
# 多态 虚拟关联
belongs_to :course_message ,:polymorphic => true
belongs_to :course
belongs_to :user
validates :user_id,presence: true
validates :course_id,presence: true
validates :course_message_id,presence: true
validates :course_message_type, presence: true
end

View File

@ -31,6 +31,9 @@ class News < ActiveRecord::Base
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# end
# 课程消息
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
#end
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy
@ -51,7 +54,7 @@ class News < ActiveRecord::Base
:author_key => :author_id
acts_as_watchable
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:add_author_as_watcher, :send_mail
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_course_messge, :add_author_as_watcher, :send_mail
after_destroy :delete_kindeditor_assets
@ -130,6 +133,18 @@ class News < ActiveRecord::Base
end
end
#课程通知 消息发送
#消息发送原则:除了消息的发布者,课程的其它成员都能收到消息提醒
def act_as_course_messge
if self.course
self.course.members.each do |m|
if m.user_id != self.author_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
end
end
end
end
# Time 2015-03-31 13:50:54
# Author lizanle
# Description 删除news后删除对应的资源

View File

@ -0,0 +1,13 @@
class CreateCourseMessages < ActiveRecord::Migration
def change
create_table :course_messages do |t|
t.integer :user_id
t.integer :course_id
t.integer :course_message_id
t.string :course_message_type
t.integer :viewed
t.timestamps
end
end
end

View File

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :course_message do
user_id 1
course_id 1
course_message_id 1
course_message_type "MyString"
viewed 1
end
end