2015-12-24 10:40:00 +08:00
|
|
|
|
class OrgDocumentComment < ActiveRecord::Base
|
2016-05-24 09:40:16 +08:00
|
|
|
|
# status: 1 模式二中置顶 0:模式二中正常显示
|
2016-10-11 14:08:44 +08:00
|
|
|
|
attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title, :sticky, :locked, :status, :root_id
|
2015-12-24 10:40:00 +08:00
|
|
|
|
include Redmine::SafeAttributes
|
2016-01-14 10:58:11 +08:00
|
|
|
|
include ApplicationHelper
|
2015-12-24 10:40:00 +08:00
|
|
|
|
belongs_to :organization
|
|
|
|
|
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
|
|
|
|
|
has_many :editor_of_documents, :dependent => :destroy
|
2016-09-23 16:44:49 +08:00
|
|
|
|
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
|
|
|
|
has_one :praise_tread_cache, as: :object, dependent: :destroy
|
2015-12-24 10:40:00 +08:00
|
|
|
|
acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc"
|
|
|
|
|
acts_as_attachable
|
|
|
|
|
has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy
|
|
|
|
|
after_create :document_save_as_org_activity
|
2016-01-12 15:53:15 +08:00
|
|
|
|
after_update :update_activity
|
|
|
|
|
|
|
|
|
|
#动态的更新
|
|
|
|
|
def update_activity
|
|
|
|
|
org_activity = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", id).first
|
|
|
|
|
if org_activity
|
|
|
|
|
org_activity.updated_at = Time.now
|
|
|
|
|
org_activity.save
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-12-24 10:40:00 +08:00
|
|
|
|
|
|
|
|
|
def document_save_as_org_activity
|
|
|
|
|
if(self.parent().nil?)
|
|
|
|
|
self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization')
|
|
|
|
|
else
|
|
|
|
|
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", self.root.id).first
|
|
|
|
|
act.update_attributes(:updated_at => self.updated_at)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def project
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-07 16:02:00 +08:00
|
|
|
|
def creator_user
|
|
|
|
|
self.creator
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def created_time
|
|
|
|
|
self.created_at
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def content_detail
|
|
|
|
|
self.content
|
|
|
|
|
end
|
2015-12-24 10:40:00 +08:00
|
|
|
|
end
|