olympiamanagement/app/models/olympia_school_data_fields.rb

49 lines
1.7 KiB
Ruby

class OlympiaSchoolDataFields
include Mongoid::Document
include Mongoid::Timestamps
# encoding: utf-8
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: ''
field :enrollment , type: Fixnum , default: 0
field :approved , type: Boolean , default: true
field :sign_up_setting_id , type: String , default: (SignUpSetting.where(:active=>true).last.id.to_s rescue "")
after_destroy do |record|
OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id).destroy_all
end
before_save do |record|
if record.account_number.blank? && !record.school_code.blank?
record.account_number = record.school_code
end
end
after_initialize do
if !self.new_record?
if self.approved.nil?
self.approved = true
self.save!
end
if self.enrollment.nil? || self.enrollment.class != Fixnum || self.enrollment < 0
self.enrollment = 0
self.save!
end
if self.enrollment_limited.nil?
self.enrollment_limited = 0
self.save!
end
if self.sign_up_setting_id.nil?
self.sign_up_setting_id = SignUpSetting.where(:active=>true).last.id.to_s
self.save!
end
end
end
end