trustieforge/app/models/org_subfield.rb

39 lines
1.4 KiB
Ruby
Raw Normal View History

class OrgSubfield < ActiveRecord::Base
belongs_to :organization, :foreign_key => :organization_id
has_one :subfield_subdomain_dir,:dependent => :destroy
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
acts_as_attachable
2015-12-30 10:34:37 +08:00
after_create :create_board_sync
after_destroy :update_priority
# status 为栏目定制决定参数1 左一 2 左二 3 左三 4 右一 5 右二 6 右三 默认的 7 学霸 8 热门项目 9 精品课程 10 最新动态
2016-05-31 10:31:08 +08:00
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
def project
end
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