This commit is contained in:
BoHung Chiu 2022-01-20 15:57:13 +08:00
parent 758d10607a
commit aba01c8239
2 changed files with 26 additions and 18 deletions

View File

@ -176,7 +176,8 @@ class SeminarMain
end
end
after_initialize do
unless self.new_record?
unless self.new_record? || @triggered_initialize
@triggered_initialize = true
save_flag = false
seminar_reviews = self.seminar_reviews
if seminar_reviews.present?

View File

@ -20,31 +20,38 @@ class SeminarReview
field :seminar_session_ids
belongs_to :seminar_main
after_initialize do
unless self.new_record?
unless self.new_record? || @triggered_initialize
@triggered_initialize = true
save_flag = false
destroy_flag = false
if (self.reviewer_id.class == Array rescue false)
reviewer_ids = self.reviewer_id[1..-1]
reviewer_ids.each do |reviewer_id|
self.class.create(:reviewer_id=>reviewer_id,:seminar_main=>self.seminar_main)
self.class.create(:reviewer_id=>reviewer_id,:seminar_main_id=>self.seminar_main_id)
end
self.reviewer_id = self.reviewer_id.first
save_flag = true
elsif self[:reviewer_id].nil?
self.destroy
destroy_flag = true
end
if (self.session_ids.nil? rescue true)
session_ids = []
self.default_topics.each_with_index do |t,i|
next if t != "seminar_signup_contributes.description"
session_ids << self.default_topics_values[i]
if !destroy_flag
if (self.session_ids.nil? rescue true)
session_ids = []
self.default_topics.each_with_index do |t,i|
next if t != "seminar_signup_contributes.description"
session_ids << self.default_topics_values[i]
end
session_ids = session_ids.flatten.map{|i| i.to_i}
self.session_ids = session_ids
save_flag = true
end
session_ids = session_ids.flatten.map{|i| i.to_i}
self.session_ids = session_ids
save_flag = true
if self.seminar_session_ids.nil? && self.session_ids.class == Array
self.seminar_session_ids = SeminarSession.where(:seminar_main_id=>self.seminar_main_id,:key.in=>self.session_ids).pluck(:id) rescue nil
save_flag = true
end
self.save(:validate=>false) if save_flag
end
if self.seminar_session_ids.nil? && self.session_ids.class == Array
self.seminar_session_ids = self.seminar_main.seminar_sessions.where(:key.in=>self.session_ids).pluck(:id) rescue nil
save_flag = true
end
self.save(:validate=>false) if save_flag
end
end
before_save do
@ -60,12 +67,12 @@ class SeminarReview
default_seminar_signup_ids += SeminarSignupContribute.where(:id.in=>seminar_signup_contribute_ids).pluck(:seminar_signup_id)
elsif fn == "seminar_signup_contributes"
seminar_signup_ids_from_contribute = SeminarSignupContribute.where(:description.in=>self.default_topics_values[i].to_a).pluck(:seminar_signup_id)
seminar_signup_ids_from_contribute = seminar_signup_ids_from_contribute & (self.seminar_main.seminar_signups.pluck(:id) rescue [])
seminar_signup_ids_from_contribute = seminar_signup_ids_from_contribute & (SeminarSignup.where(:seminar_main_id=>self.seminar_main_id).pluck(:id) rescue [])
default_seminar_signup_ids += seminar_signup_ids_from_contribute
self.session_ids = self.session_ids.concat(self.default_topics_values[i].map{|v| v.to_i})
end
end
self.seminar_session_ids = self.seminar_main.seminar_sessions.where(:key.in=>self.session_ids.to_a).pluck(:id) rescue []
self.seminar_session_ids = SeminarSession.where(:seminar_main_id=>self.seminar_main_id,:key.in=>self.session_ids.to_a).pluck(:id) rescue []
default_seminar_signup_ids.uniq!
default_seminar_signup_ids = default_seminar_signup_ids.map{|s| s.to_s}
self.default_seminar_signup_ids = default_seminar_signup_ids