2016-06-29 06:57:45 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
class SeminarSignup
|
|
|
|
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2022-10-22 10:43:36 +00:00
|
|
|
HiddenFields = ['seminar_signup_id','_id', 'created_at', 'updated_at','seminar_main_id',"serial_number","final_session","final_sessions","preferred_sessions",'seminar_session_id',"seminar_session_ids","preferred_session","sort_number","abstract_number","presentation_type", "filename"]
|
2022-06-14 08:13:28 +00:00
|
|
|
DefaultEnableFields = ['status','name','tel','phone','email','password','recaptcha']
|
2021-04-24 10:41:50 +00:00
|
|
|
field :sort_number , type: Integer, default: 10000
|
|
|
|
|
2016-06-29 06:57:45 +00:00
|
|
|
field :status
|
2019-11-26 15:52:52 +00:00
|
|
|
field :name # become Last Name for TICC
|
|
|
|
field :tel, type: String # become First Name for TICC
|
2022-08-20 06:16:39 +00:00
|
|
|
field :unit, localize: true #Only localize for preserving old record
|
2016-06-29 06:57:45 +00:00
|
|
|
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
|
2021-04-24 10:41:50 +00:00
|
|
|
field :final_session #only store old data , not used
|
|
|
|
field :final_sessions
|
|
|
|
field :preferred_sessions, type: Array, default: []
|
2016-06-29 06:57:45 +00:00
|
|
|
belongs_to :seminar_main
|
2021-04-24 10:41:50 +00:00
|
|
|
field :seminar_session_id #only store old data , not used
|
|
|
|
field :seminar_session_ids, type: Array, default: []
|
2021-04-03 16:23:52 +00:00
|
|
|
has_many :seminar_signup_values, :autosave => true, :dependent => :destroy
|
|
|
|
has_many :seminar_signup_contributes, :autosave => true, :dependent => :destroy
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
accepts_nested_attributes_for :seminar_signup_values, allow_destroy: true
|
|
|
|
accepts_nested_attributes_for :seminar_signup_contributes, allow_destroy: true
|
2021-04-24 10:41:50 +00:00
|
|
|
scope :sort_ordered, ->{ order_by(:sort_number=>1,:created_at=>1) }
|
2023-01-11 09:46:06 +00:00
|
|
|
after_destroy do
|
|
|
|
if defined?(OrbitHelper::SharedMutex)
|
|
|
|
OrbitHelper::SharedMutex.synchronize do
|
|
|
|
seminar_id = self.seminar_main_id.to_s
|
|
|
|
signup_count = OrbitHelper::SharedHash['seminar'][:counter][seminar_id]
|
|
|
|
if signup_count
|
|
|
|
signup_count -= 1
|
|
|
|
OrbitHelper::SharedHash['seminar'][:counter][seminar_id] = signup_count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-24 13:06:49 +00:00
|
|
|
before_create do
|
|
|
|
unit = self.unit_translations.values.select{|v| v.present?}.first
|
2022-08-20 06:16:39 +00:00
|
|
|
tmp_unit_translations = self.unit_translations
|
|
|
|
self.unit_translations = I18n.available_locales.map do |l|
|
|
|
|
l = l.to_s
|
|
|
|
tmp = tmp_unit_translations[l]
|
|
|
|
[l, (tmp ? tmp : unit)]
|
|
|
|
end.to_h
|
2021-04-03 16:23:52 +00:00
|
|
|
if self.serial_number.nil?
|
2023-01-16 09:57:07 +00:00
|
|
|
last_serial_number = SeminarMain.where(:id=>self.seminar_main_id).max(:last_serial_number).to_i
|
|
|
|
self.serial_number = last_serial_number + 1
|
|
|
|
SeminarMain.where(:id=>self.seminar_main_id).update_all({"$inc"=>{"last_serial_number"=>1}})
|
2021-04-03 16:23:52 +00:00
|
|
|
end
|
2021-03-24 13:06:49 +00:00
|
|
|
end
|
2021-03-17 07:33:31 +00:00
|
|
|
after_destroy do
|
|
|
|
seminar_main = self.seminar_main
|
2021-04-03 16:23:52 +00:00
|
|
|
if seminar_main.present?
|
|
|
|
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
|
2023-09-27 09:07:44 +00:00
|
|
|
seminar_main.seminar_signups.delete(self) #avoid resave
|
2021-04-03 16:23:52 +00:00
|
|
|
if seminar_main.unassigned_seminar_signup_ids.delete(id)
|
|
|
|
seminar_main.save
|
2021-03-17 07:33:31 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-03 16:23:52 +00:00
|
|
|
seminar_session = SeminarSession.where(:id=>self.seminar_session_id).first
|
|
|
|
if seminar_session
|
|
|
|
seminar_session.seminar_signup_ids.delete(self.id.to_s)
|
|
|
|
seminar_session.save
|
2021-03-17 07:33:31 +00:00
|
|
|
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
|
2021-04-24 10:41:50 +00:00
|
|
|
def set_preferred_sessions
|
|
|
|
self.preferred_sessions = self.seminar_signup_contributes.pluck(:preferred_session)
|
|
|
|
self.save
|
|
|
|
end
|
2021-11-18 09:59:20 +00:00
|
|
|
def get_display_fields
|
|
|
|
seminar = self.seminar_main
|
|
|
|
if seminar.nil?
|
|
|
|
return []
|
|
|
|
else
|
|
|
|
locale = I18n.locale.to_s
|
|
|
|
except_fields = ["password", "recaptcha"]
|
|
|
|
all_fields = []
|
|
|
|
if seminar.seminar_signup_field_sets.count != 0
|
|
|
|
all_fields = seminar.seminar_signup_field_sets.map do |set|
|
|
|
|
field_name = set.field_name
|
|
|
|
next if set.disabled || except_fields.include?(field_name)
|
|
|
|
value = self.send(field_name) rescue nil
|
2022-08-20 06:16:39 +00:00
|
|
|
localize = self.fields[field_name].options[:localize]
|
|
|
|
next if value.nil? && !localize
|
2021-11-18 09:59:20 +00:00
|
|
|
if field_name == "status"
|
|
|
|
value = I18n.t("seminar.registration_status_#{value}")
|
2022-08-20 06:16:39 +00:00
|
|
|
elsif localize && field_name != "unit"
|
2021-11-18 09:59:20 +00:00
|
|
|
values = self.send("#{field_name}_translations").select{|k,v| v.present?}
|
|
|
|
value = ""
|
|
|
|
if values.count == 0
|
|
|
|
next
|
|
|
|
elsif values.count == 1
|
|
|
|
value = values.values.first
|
|
|
|
else
|
|
|
|
last_idx = values.count - 1
|
|
|
|
values.each_with_index do |(l, v), i|
|
|
|
|
value += (I18n.t(l) + ": " + v )
|
|
|
|
if i != last_idx
|
|
|
|
value += "<br>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"field_name"=>field_name,
|
|
|
|
"title"=>set.name[locale],
|
|
|
|
"value"=> value
|
|
|
|
}
|
|
|
|
end.compact
|
|
|
|
else
|
|
|
|
field_names = self.class::DefaultEnableFields
|
|
|
|
all_fields = field_names.map do |field_name|
|
|
|
|
next if except_fields.include?(field_name)
|
|
|
|
value = self.send(field_name) rescue nil
|
|
|
|
next if value.nil?
|
|
|
|
field_name_trans = I18n.t("seminar_signup.#{field_name}")
|
|
|
|
if field_name == "status"
|
|
|
|
I18n.t("seminar.registration_status_#{value}")
|
|
|
|
elsif self.fields[field_name].options[:localize]
|
|
|
|
values = self.send("#{field_name}_translations").select{|k,v| v.present?}
|
|
|
|
value = ""
|
|
|
|
if values.count == 0
|
|
|
|
next
|
|
|
|
elsif values.count == 1
|
|
|
|
value = values.values.first
|
|
|
|
else
|
|
|
|
last_idx = values.count - 1
|
|
|
|
values.each_with_index do |(l, v), i|
|
|
|
|
value += (I18n.t(l) + ": " + v )
|
|
|
|
if i != last_idx
|
|
|
|
value += "<br>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"field_name"=>field_name,
|
|
|
|
"title"=> field_name_trans,
|
|
|
|
"value"=> value
|
|
|
|
}
|
|
|
|
end.compact
|
|
|
|
end
|
|
|
|
seminar.seminar_signup_fields.asc(:_id).each do |rf|
|
|
|
|
seminar_signup_value = rf.seminar_signup_values.where(:seminar_signup_id=>self.id).last
|
|
|
|
if seminar_signup_value
|
|
|
|
value = seminar_signup_value.get_field_value rescue nil
|
|
|
|
if value
|
|
|
|
all_fields << value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return all_fields
|
|
|
|
end
|
|
|
|
end
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|