2015-03-05 09:27:13 +08:00
|
|
|
class Organization < ActiveRecord::Base
|
2015-11-03 11:19:38 +08:00
|
|
|
attr_accessible :name, :description, :creator_id, :home_id, :domain, :is_public
|
|
|
|
has_many :org_members, :dependent => :destroy
|
2015-11-05 17:57:07 +08:00
|
|
|
has_many :org_projects ,:dependent => :destroy
|
|
|
|
has_many :projects,:through => :org_projects
|
2015-11-17 17:34:50 +08:00
|
|
|
has_many :courses, :through => :org_courses
|
2015-11-05 17:57:07 +08:00
|
|
|
has_many :org_document_comments, :dependent => :destroy
|
2015-12-02 17:38:41 +08:00
|
|
|
has_many :org_courses, :dependent => :destroy
|
2015-12-04 17:34:48 +08:00
|
|
|
has_many :org_subfields, :dependent => :destroy
|
2015-11-13 15:02:12 +08:00
|
|
|
has_many :users, :through => :org_members
|
2016-04-01 00:27:34 +08:00
|
|
|
has_many :files
|
2016-11-22 09:23:16 +08:00
|
|
|
has_many :org_messages, :class_name => 'OrgMessage', :dependent => :destroy
|
2016-04-01 00:27:34 +08:00
|
|
|
acts_as_attachable
|
2015-11-05 17:57:07 +08:00
|
|
|
validates_uniqueness_of :name
|
2015-12-31 16:23:10 +08:00
|
|
|
after_create :save_as_org_activity, :add_default_subfields
|
2015-11-05 17:57:07 +08:00
|
|
|
|
|
|
|
def save_as_org_activity
|
|
|
|
OrgActivity.create(:user_id => User.current.id, :org_act_id => self.id, :org_act_type => 'CreateOrganization', :container_id => self.id, :container_type => 'Organization')
|
|
|
|
end
|
2015-12-31 16:23:10 +08:00
|
|
|
|
|
|
|
def add_default_subfields
|
2016-06-03 12:42:02 +08:00
|
|
|
OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default', :priority => 1, :status => 0)
|
|
|
|
OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default', :priority => 2, :status => 2)
|
|
|
|
OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default', :priority => 3, :status => 2)
|
2015-12-31 16:23:10 +08:00
|
|
|
end
|
2016-04-29 14:46:40 +08:00
|
|
|
|
|
|
|
def switch_type
|
2016-05-31 10:31:08 +08:00
|
|
|
self.show_mode.to_i == 1
|
2016-04-29 14:46:40 +08:00
|
|
|
end
|
2016-05-13 10:50:34 +08:00
|
|
|
|
|
|
|
def allow_set_teachers
|
2016-05-31 10:31:08 +08:00
|
|
|
self.allow_teacher.to_i == 1
|
2016-05-13 10:50:34 +08:00
|
|
|
end
|
2016-05-16 18:08:05 +08:00
|
|
|
|
2016-05-17 09:02:17 +08:00
|
|
|
def secdomain_name
|
2016-05-16 18:08:05 +08:00
|
|
|
Secdomain.where("sub_type=2 and pid=?", self.id).first.try(:subname)
|
|
|
|
end
|
2015-03-05 09:27:13 +08:00
|
|
|
end
|