olympiamanagement/app/models/olympia_student_data_field.rb

60 lines
2.0 KiB
Ruby

class OlympiaStudentDataField
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitModel::Impression
# encoding: utf-8
include OrbitTag::Taggable
include OrbitCategory::Categorizable
field :StudentIdentity , type: String , default: ''
field :StudentName , type: String , default: ''
field :StudentSex , type: String , default: ''
field :StudentIDNO , type: String , default: ''
field :StudentBirthYear , type: Fixnum , default: Time.now.year
field :StudentBirthMonth , type: Fixnum , default: Time.now.month
field :StudentBirthDay , type: Fixnum , default: Time.now.day
field :StudentClass , type: String , default: ''
field :StudentPhone , type: String , default: ''
field :StudentCode , type: String , default: ''
field :StudentAddress , type: String , default: ''
field :StudentArea , type: String , default: ''
field :remove_image , type: Boolean , default: false
field :approved , type: Boolean , default: true
field :olympia_school_data_fields_id , type: String , default: ''
field :sign_up_setting_id , type: String , default: SignUpSetting.where(:active=>true).last.id.to_s
has_many :olympia_student_images , :dependent => :destroy , autosave: true
after_save :check_file
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?
@school.enrollment += 1
@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?
@school.enrollment -= 1
@school.save
end
end
end
after_initialize do
if !self.new_record?
if self.approved.nil?
self.approved = true
self.save!
end
end
end
def check_file
if self.remove_image
self.olympia_student_images = []
self.remove_image = false
self.save
end
end
end