2015-12-24 10:40:00 +08:00
|
|
|
class OrgSubfield < ActiveRecord::Base
|
|
|
|
belongs_to :organization, :foreign_key => :organization_id
|
2016-01-13 15:17:13 +08:00
|
|
|
has_one :subfield_subdomain_dir,:dependent => :destroy
|
2015-12-24 10:40:00 +08:00
|
|
|
has_many :org_document_comments, :dependent => :destroy
|
|
|
|
has_many :files
|
|
|
|
has_many :org_subfield_messages, :dependent => :destroy
|
|
|
|
has_many :messages, :through => :org_subfield_messages
|
2015-12-30 10:34:37 +08:00
|
|
|
has_many :boards, :dependent => :destroy
|
2016-01-20 16:24:14 +08:00
|
|
|
has_many :news, :dependent => :destroy
|
2016-04-27 17:02:44 +08:00
|
|
|
has_many :sub_domains, :dependent => :destroy
|
2015-12-24 10:40:00 +08:00
|
|
|
acts_as_attachable
|
2015-12-30 10:34:37 +08:00
|
|
|
after_create :create_board_sync
|
2016-03-09 18:06:28 +08:00
|
|
|
after_destroy :update_priority
|
2015-12-30 10:34:37 +08:00
|
|
|
# 创建资源栏目讨论区
|
|
|
|
def create_board_sync
|
|
|
|
@board = self.boards.build
|
|
|
|
#self.name=" #{l(:label_borad_course) }"
|
|
|
|
@board.name = " #{l(:label_borad_org_subfield) }"#self.name
|
|
|
|
@board.description = self.name.to_s
|
|
|
|
@board.project_id = -1
|
|
|
|
if @board.save
|
|
|
|
logger.debug "[OrgSubfield Model] ===> #{@board.to_json}"
|
|
|
|
else
|
|
|
|
logger.error "[OrgSubfield Model] ===> Auto create board when org_subfield saved, because #{@board.full_messages}"
|
|
|
|
end
|
|
|
|
end
|
2015-12-24 10:40:00 +08:00
|
|
|
|
|
|
|
def project
|
|
|
|
end
|
2016-03-09 18:06:28 +08:00
|
|
|
|
|
|
|
def update_priority
|
|
|
|
OrgSubfield.where("organization_id=? and priority>?", self.organization_id, self.priority).each do |field|
|
|
|
|
field.decrement(:priority)
|
|
|
|
field.save
|
|
|
|
end
|
|
|
|
end
|
2015-12-04 17:34:48 +08:00
|
|
|
end
|