olympiamanagement/app/models/olympia_student_data_field.rb

60 lines
2.0 KiB
Ruby
Raw Normal View History

2020-02-04 11:24:13 +00:00
class OlympiaStudentDataField
2020-02-03 15:24:43 +00:00
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: ''
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-04 11:24:13 +00:00
field :sign_up_setting_id , type: String , default: ''
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?
@school.enrollment = @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 = @school.enrollment - 1
@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