2020-01-29 11:26:44 +00:00
|
|
|
class OlympiaSchoolDataFields
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include OrbitModel::Status
|
|
|
|
include OrbitModel::Impression
|
|
|
|
# encoding: utf-8
|
|
|
|
include OrbitTag::Taggable
|
|
|
|
include OrbitCategory::Categorizable
|
|
|
|
field :account_number , type: String , default: ''
|
|
|
|
field :password , type: String , default: ''
|
|
|
|
field :school_name , type: String , default: ''
|
|
|
|
field :school_code , type: String , default: ''
|
|
|
|
field :school_address , type: String , default: ''
|
|
|
|
field :class_number , type: Fixnum , default: 0
|
|
|
|
field :enrollment_limited , type: Fixnum , default: 0
|
|
|
|
field :school_contact_person_name , type: String , default: ''
|
|
|
|
field :department_job_title , type: String , default: ''
|
|
|
|
field :office_tel_number , type: String , default: ''
|
|
|
|
field :fax , type: String , default: ''
|
|
|
|
field :mobile_number , type: String , default: ''
|
|
|
|
field :email , type: String , default: ''
|
2020-02-02 11:25:42 +00:00
|
|
|
field :enrollment , type: Fixnum , default: 0
|
2020-01-31 10:52:53 +00:00
|
|
|
field :approved , type: Boolean , default: true
|
|
|
|
field :sign_up_setting_id , type: String , default: SignUpSetting.last.id.to_s
|
2020-02-05 07:37:10 +00:00
|
|
|
after_destroy do |record|
|
|
|
|
OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id,:sign_up_setting_id=>SignUpSetting.last.id).destroy_all
|
|
|
|
end
|
2020-01-31 10:52:53 +00:00
|
|
|
after_initialize do
|
|
|
|
if !self.new_record?
|
|
|
|
if self.approved.nil?
|
|
|
|
self.approved = true
|
2020-02-02 11:25:42 +00:00
|
|
|
self.save!
|
2020-01-31 10:52:53 +00:00
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
if self.enrollment.nil? || self.enrollment.class != Fixnum
|
2020-01-31 10:52:53 +00:00
|
|
|
self.enrollment = 0
|
2020-02-02 11:25:42 +00:00
|
|
|
self.save!
|
|
|
|
end
|
2020-02-05 07:37:10 +00:00
|
|
|
if self.enrollment == 0 #check enrollment student number
|
|
|
|
self.enrollment = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>self.id,:sign_up_setting_id=>SignUpSetting.last.id).length
|
|
|
|
self.save!
|
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
if self.enrollment_limited.nil?
|
|
|
|
self.enrollment_limited = 0
|
|
|
|
self.save!
|
2020-01-31 10:52:53 +00:00
|
|
|
end
|
|
|
|
if self.sign_up_setting_id.nil?
|
|
|
|
self.sign_up_setting_id = SignUpSetting.last.id.to_s
|
2020-02-02 11:25:42 +00:00
|
|
|
self.save!
|
2020-01-31 10:52:53 +00:00
|
|
|
end
|
|
|
|
sign_up_setting = SignUpSetting.find(self.sign_up_setting_id) rescue nil
|
|
|
|
if sign_up_setting.nil?
|
|
|
|
self.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-29 11:26:44 +00:00
|
|
|
end
|