在转发表forwards记录发送帖子、通知
This commit is contained in:
parent
a451680cf8
commit
991613d760
|
@ -1856,6 +1856,10 @@ class UsersController < ApplicationController
|
|||
course_ids.each do |course_id|
|
||||
if Course.find(course_id).news.map(&:id).exclude?(news.id)
|
||||
course_news = News.create(:course_id => course_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1)
|
||||
#record forward to table forwards if new record is valid
|
||||
if course_news.valid?
|
||||
news.forwards << Forward.new(:to_type => course_news.class.name, :to_id => course_news.id)
|
||||
end
|
||||
news.attachments.each do |attach|
|
||||
course_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
|
||||
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
|
||||
|
@ -1872,6 +1876,10 @@ class UsersController < ApplicationController
|
|||
project = Project.find(project_id)
|
||||
if project.news.map(&:id).exclude?(news.id)
|
||||
message = Message.create(:board_id => project.boards.first.id, :subject => news.title, :content => news.description, :author_id => User.current.id)
|
||||
# record forward to table forwards if new record is valid
|
||||
if message.valid?
|
||||
news.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
|
||||
end
|
||||
news.attachments.each do |attach|
|
||||
message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
|
||||
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
|
||||
|
@ -1885,6 +1893,10 @@ class UsersController < ApplicationController
|
|||
news = News.find(params[:send_id])
|
||||
field_id = params[:subfield]
|
||||
org_news = News.create(:org_subfield_id => field_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1)
|
||||
# record forward to table forwards if new record is valid
|
||||
if org_news.valid?
|
||||
news.forwards << Forward.new(:to_type => org_news.class.name, :to_id => org_news.id)
|
||||
end
|
||||
news.attachments.each do |attach|
|
||||
org_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
|
||||
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
|
||||
|
@ -1900,6 +1912,10 @@ class UsersController < ApplicationController
|
|||
course = Course.find(course_id)
|
||||
if course.news.map(&:id).exclude?(@message.id)
|
||||
message = Message.create(:board_id => course.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
|
||||
# record forward to table forwards if new record is valid
|
||||
if message.valid?
|
||||
@message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
|
||||
end
|
||||
@message.attachments.each do |attach|
|
||||
message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
|
||||
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
|
||||
|
@ -1916,6 +1932,10 @@ class UsersController < ApplicationController
|
|||
project = Project.find(project_id)
|
||||
if project.news.map(&:id).exclude?(@message.id)
|
||||
message = Message.create(:board_id => project.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
|
||||
# record forward to table forwards if new record is valid
|
||||
if message.valid?
|
||||
@message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
|
||||
end
|
||||
@message.attachments.each do |attach|
|
||||
message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
|
||||
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
|
||||
|
@ -1932,6 +1952,10 @@ class UsersController < ApplicationController
|
|||
@message.save
|
||||
board = OrgSubfield.find(field_id).boards.first
|
||||
mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
|
||||
# record forward to table forwards if new record is valid
|
||||
if mes.valid?
|
||||
@message.forwards << Forward.new(:to_type => mes.class.name, :to_id => mes.id)
|
||||
end
|
||||
@message.attachments.each do |attach|
|
||||
mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
|
||||
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
|
||||
|
|
|
@ -28,7 +28,7 @@ class Attachment < ActiveRecord::Base
|
|||
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
|
||||
# 被ForgeActivity虚拟关联
|
||||
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
|
||||
has_many :forwards, :as => :from
|
||||
has_many :forwards, :as => :from, :dependent => :destroy
|
||||
# 课程动态
|
||||
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
|
||||
# end
|
||||
|
|
|
@ -45,6 +45,8 @@ class Message < ActiveRecord::Base
|
|||
|
||||
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy
|
||||
|
||||
#转发表
|
||||
has_many :forwards, :as => :from, :dependent => :destroy
|
||||
after_destroy :delete_org_activities
|
||||
|
||||
acts_as_searchable :columns => ['subject', 'content'],
|
||||
|
|
|
@ -37,6 +37,9 @@ class News < ActiveRecord::Base
|
|||
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy
|
||||
#end
|
||||
|
||||
#转发表
|
||||
has_many :forwards, :as => :from, :dependent => :destroy
|
||||
|
||||
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy
|
||||
|
||||
validates_presence_of :title, :description
|
||||
|
|
Loading…
Reference in New Issue