diff --git a/app/models/board.rb b/app/models/board.rb index 67d59e599..b66719edf 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -19,6 +19,7 @@ class Board < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project,:touch => true belongs_to :course,:touch=>true + belongs_to :org_subfield, :touch => true has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC" has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC" belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index 6a31203b0..0747114ca 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -4,7 +4,22 @@ class OrgSubfield < ActiveRecord::Base has_many :files has_many :org_subfield_messages, :dependent => :destroy has_many :messages, :through => :org_subfield_messages + has_many :boards, :dependent => :destroy acts_as_attachable + after_create :create_board_sync + # 创建资源栏目讨论区 + 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 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 230532d71..e4a23373d 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1728,6 +1728,7 @@ zh: label_hot_project: '热门项目' label_borad_project: 项目讨论区 label_borad_course: 课程讨论区 + label_borad_org_subfield: 资源栏目讨论区 view_borad_course: 课程讨论 label_memo_create_succ: 发布成功 label_memo_create_fail: 发布失败 diff --git a/db/migrate/20151230015225_add_quotes_to_messages.rb b/db/migrate/20151230015225_add_quotes_to_messages.rb new file mode 100644 index 000000000..4e19725d5 --- /dev/null +++ b/db/migrate/20151230015225_add_quotes_to_messages.rb @@ -0,0 +1,4 @@ +class AddQuotesToMessages < ActiveRecord::Migration + def change + end +end diff --git a/db/migrate/20151230015410_add_org_subfield_id_to_boards.rb b/db/migrate/20151230015410_add_org_subfield_id_to_boards.rb new file mode 100644 index 000000000..853238813 --- /dev/null +++ b/db/migrate/20151230015410_add_org_subfield_id_to_boards.rb @@ -0,0 +1,5 @@ +class AddOrgSubfieldIdToBoards < ActiveRecord::Migration + def change + add_column :boards, :org_subfield_id, :integer + end +end diff --git a/db/migrate/20151230015904_set_board_for_org_subfields.rb b/db/migrate/20151230015904_set_board_for_org_subfields.rb new file mode 100644 index 000000000..cad6526a0 --- /dev/null +++ b/db/migrate/20151230015904_set_board_for_org_subfields.rb @@ -0,0 +1,11 @@ +# encoding: utf-8 +class SetBoardForOrgSubfields < ActiveRecord::Migration + def up + OrgSubfield.where("field_type='Post'").each do |field| + Board.create(:org_subfield_id => field.id, :name => "资源栏目讨论区", :project_id => -1, :description => field.name) + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index fab2d5700..925192317 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151224090313) do +ActiveRecord::Schema.define(:version => 20151230015904) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -198,6 +198,7 @@ ActiveRecord::Schema.define(:version => 20151224090313) do t.integer "last_message_id" t.integer "parent_id" t.integer "course_id" + t.integer "org_subfield_id" end add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id" @@ -1045,6 +1046,7 @@ ActiveRecord::Schema.define(:version => 20151224090313) do t.boolean "locked", :default => false t.integer "sticky", :default => 0 t.integer "reply_id" + t.integer "quotes" end add_index "messages", ["author_id"], :name => "index_messages_on_author_id"