seminar2/app/models/seminar_signup.rb

59 lines
1.7 KiB
Ruby
Raw Normal View History

2016-06-29 06:57:45 +00:00
# encoding: utf-8
class SeminarSignup
include Mongoid::Document
include Mongoid::Timestamps
field :status
field :name # become Last Name for TICC
field :tel, type: String # become First Name for TICC
2016-06-29 06:57:45 +00:00
field :unit, localize: true
field :phone, type: String
field :fax, type: String
field :email, type: String
field :address, localize: true
field :password
field :note, localize: true
2021-03-29 14:27:08 +00:00
field :serial_number
2016-06-29 06:57:45 +00:00
belongs_to :seminar_main
has_many :seminar_signup_values
has_many :seminar_signup_contributes
accepts_nested_attributes_for :seminar_signup_values, allow_destroy: true
accepts_nested_attributes_for :seminar_signup_contributes, allow_destroy: true
2021-03-29 14:27:08 +00:00
scope :sort_ordered, ->{ order_by(:created_at=>1) }
before_create do
unit = self.unit_translations.values.select{|v| v.present?}.first
self.unit_translations = I18n.available_locales.map{|l| [l.to_s,unit]}.to_h
2021-03-29 14:27:08 +00:00
s = SeminarMain.find(self.seminar_main)
s.last_serial_number += 1
self.serial_number = s.last_serial_number
s.save(:validate=>false)
end
after_destroy do
seminar_main = self.seminar_main
seminar_reviews = seminar_main.seminar_reviews
id = self.id.to_s
seminar_reviews.each do |sr|
if sr.all_seminar_signup_ids.include?(id)
sr.seminar_signup_ids.delete(id)
sr.remove_seminar_signup_ids.delete(id)
sr.default_seminar_signup_ids.delete(id)
sr.save
end
end
if seminar_main.unassigned_seminar_signup_ids.delete(id)
seminar_main.save
end
end
2021-03-29 14:27:08 +00:00
def display_serial_number
display_format_string(self.serial_number,4)
end
def display_format_string(num, str_length)
return format("%0#{str_length}d", num)
end
2016-06-29 06:57:45 +00:00
end