2020-02-04 11:24:13 +00:00
|
|
|
class OlympiaStudentDataField
|
2020-02-03 15:24:43 +00:00
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
# encoding: utf-8
|
|
|
|
include OrbitTag::Taggable
|
2020-03-18 08:12:08 +00:00
|
|
|
include OrbitCategory::Categorizable
|
2020-02-03 15:24:43 +00:00
|
|
|
field :StudentIdentity , type: String , default: ''
|
2020-03-18 08:12:08 +00:00
|
|
|
field :StudentName , type: String , default: ''
|
2020-02-03 15:24:43 +00:00
|
|
|
field :StudentSex , type: String , default: ''
|
2020-03-18 08:12:08 +00:00
|
|
|
field :StudentIDNO , type: String , default: ''
|
|
|
|
field :StudentBirthYear , type: Fixnum , default: Time.now.year
|
2020-02-03 15:24:43 +00:00
|
|
|
field :StudentBirthMonth , type: Fixnum , default: Time.now.month
|
|
|
|
field :StudentBirthDay , type: Fixnum , default: Time.now.day
|
2020-03-18 08:12:08 +00:00
|
|
|
field :StudentClass , type: String , default: ''
|
2020-02-03 15:24:43 +00:00
|
|
|
field :StudentPhone , type: String , default: ''
|
|
|
|
field :StudentCode , type: String , default: ''
|
|
|
|
field :StudentAddress , type: String , default: ''
|
|
|
|
field :StudentArea , type: String , default: ''
|
2020-02-04 11:24:13 +00:00
|
|
|
field :remove_image , type: Boolean , default: false
|
2020-02-03 15:24:43 +00:00
|
|
|
field :approved , type: Boolean , default: true
|
|
|
|
field :olympia_school_data_fields_id , type: String , default: ''
|
2020-02-05 13:44:49 +00:00
|
|
|
field :sign_up_setting_id , type: String , default: SignUpSetting.where(:active=>true).last.id.to_s
|
2020-02-04 11:24:13 +00:00
|
|
|
has_many :olympia_student_images , :dependent => :destroy , autosave: true
|
|
|
|
after_save :check_file
|
2020-02-05 07:37:10 +00:00
|
|
|
after_create do |record|
|
|
|
|
if !record.olympia_school_data_fields_id.blank?
|
|
|
|
@school = OlympiaSchoolDataFields.find(record.olympia_school_data_fields_id) rescue nil
|
|
|
|
if !@school.nil?
|
2020-02-05 13:44:49 +00:00
|
|
|
@school.enrollment += 1
|
2020-02-05 07:37:10 +00:00
|
|
|
@school.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
after_destroy do |record|
|
|
|
|
if !record.olympia_school_data_fields_id.blank?
|
|
|
|
@school = OlympiaSchoolDataFields.find(record.olympia_school_data_fields_id) rescue nil
|
|
|
|
if !@school.nil?
|
2020-02-05 13:44:49 +00:00
|
|
|
@school.enrollment -= 1
|
2020-02-05 07:37:10 +00:00
|
|
|
@school.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-03 15:24:43 +00:00
|
|
|
after_initialize do
|
|
|
|
if !self.new_record?
|
|
|
|
if self.approved.nil?
|
|
|
|
self.approved = true
|
|
|
|
self.save!
|
|
|
|
end
|
|
|
|
end
|
2020-02-04 11:24:13 +00:00
|
|
|
end
|
|
|
|
def check_file
|
|
|
|
if self.remove_image
|
|
|
|
self.olympia_student_images = []
|
|
|
|
self.remove_image = false
|
|
|
|
self.save
|
|
|
|
end
|
|
|
|
end
|
2020-02-03 15:24:43 +00:00
|
|
|
end
|