2019-10-04 16:11:39 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require "orbit_form_helper"
|
|
|
|
class SeminarReview
|
|
|
|
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
2021-03-17 07:33:31 +00:00
|
|
|
field :review_start_date, :type => Date, :default => Time.now #Already move to seminar_main
|
|
|
|
field :review_end_date, :type => Date, :default => Time.now #Already move to seminar_main
|
2019-10-04 16:11:39 +00:00
|
|
|
field :reviewer_id
|
2021-03-17 07:33:31 +00:00
|
|
|
field :seminar_signup_ids, :type => Array, :default => []
|
|
|
|
field :remove_seminar_signup_ids, :type => Array, :default => []
|
2021-04-24 10:41:50 +00:00
|
|
|
field :seminar_signup_contribute_ids, :type => Array, :default => []
|
|
|
|
field :remove_seminar_signup_contribute_ids, :type => Array, :default => []
|
2021-03-17 07:33:31 +00:00
|
|
|
field :default_seminar_signup_ids, :type => Array, :default => []
|
|
|
|
field :default_topics, :type => Array, :default => []
|
|
|
|
field :default_topics_values, :type => Array, :default => []
|
2021-04-03 16:23:52 +00:00
|
|
|
field :final_session
|
|
|
|
field :session_ids
|
|
|
|
field :seminar_session_ids
|
2019-10-04 16:11:39 +00:00
|
|
|
belongs_to :seminar_main
|
2021-03-17 07:33:31 +00:00
|
|
|
after_initialize do
|
2022-01-20 07:57:13 +00:00
|
|
|
unless self.new_record? || @triggered_initialize
|
|
|
|
@triggered_initialize = true
|
2021-04-03 16:23:52 +00:00
|
|
|
save_flag = false
|
2022-01-20 07:57:13 +00:00
|
|
|
destroy_flag = false
|
2021-04-03 16:23:52 +00:00
|
|
|
if (self.reviewer_id.class == Array rescue false)
|
|
|
|
reviewer_ids = self.reviewer_id[1..-1]
|
|
|
|
reviewer_ids.each do |reviewer_id|
|
2022-01-20 07:57:13 +00:00
|
|
|
self.class.create(:reviewer_id=>reviewer_id,:seminar_main_id=>self.seminar_main_id)
|
2021-03-17 07:33:31 +00:00
|
|
|
end
|
2021-04-03 16:23:52 +00:00
|
|
|
self.reviewer_id = self.reviewer_id.first
|
|
|
|
save_flag = true
|
2022-01-20 07:57:13 +00:00
|
|
|
elsif self[:reviewer_id].nil?
|
|
|
|
self.destroy
|
|
|
|
destroy_flag = true
|
2021-04-03 16:23:52 +00:00
|
|
|
end
|
2022-01-20 07:57:13 +00:00
|
|
|
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
|
2021-04-03 16:23:52 +00:00
|
|
|
end
|
2022-01-20 07:57:13 +00:00
|
|
|
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
|
2021-04-03 16:23:52 +00:00
|
|
|
end
|
2021-03-17 07:33:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
before_save do
|
|
|
|
default_seminar_signup_ids = []
|
2021-04-03 16:23:52 +00:00
|
|
|
self.session_ids = []
|
2021-03-17 07:33:31 +00:00
|
|
|
self.default_topics.each_with_index do |topic,i|
|
|
|
|
fn,id = (topic.split(".") rescue [])
|
|
|
|
next if fn.nil?
|
|
|
|
if fn == "seminar_signup_fields"
|
|
|
|
default_seminar_signup_ids += SeminarSignupValue.where(:seminar_signup_field_id=>id,:val.in=>self.default_topics_values[i].to_a).pluck(:seminar_signup_id)
|
2021-03-24 13:06:49 +00:00
|
|
|
elsif fn == "seminar_submission_fields"
|
2021-03-17 07:33:31 +00:00
|
|
|
seminar_signup_contribute_ids = SeminarSubmissionValue.where(:seminar_submission_field_id=>id,:val.in=>self.default_topics_values[i].to_a).pluck(:seminar_signup_contribute)
|
|
|
|
default_seminar_signup_ids += SeminarSignupContribute.where(:id.in=>seminar_signup_contribute_ids).pluck(:seminar_signup_id)
|
2021-03-24 13:06:49 +00:00
|
|
|
elsif fn == "seminar_signup_contributes"
|
2021-04-03 16:23:52 +00:00
|
|
|
seminar_signup_ids_from_contribute = SeminarSignupContribute.where(:description.in=>self.default_topics_values[i].to_a).pluck(:seminar_signup_id)
|
2022-01-20 07:57:13 +00:00
|
|
|
seminar_signup_ids_from_contribute = seminar_signup_ids_from_contribute & (SeminarSignup.where(:seminar_main_id=>self.seminar_main_id).pluck(:id) rescue [])
|
2021-04-03 16:23:52 +00:00
|
|
|
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})
|
2021-03-17 07:33:31 +00:00
|
|
|
end
|
|
|
|
end
|
2022-01-20 07:57:13 +00:00
|
|
|
self.seminar_session_ids = SeminarSession.where(:seminar_main_id=>self.seminar_main_id,:key.in=>self.session_ids.to_a).pluck(:id) rescue []
|
2021-03-17 07:33:31 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
def review
|
|
|
|
MemberProfile.find(self.reviewer_id) rescue nil
|
|
|
|
end
|
2021-04-03 16:23:52 +00:00
|
|
|
def get_all_seminar_signup_ids(mode = nil)
|
2021-04-24 10:41:50 +00:00
|
|
|
if (self.default_topics.include?("seminar_signup_contributes.description") && self.seminar_main.assign_mode != 0) || mode != 0
|
2021-04-04 12:33:09 +00:00
|
|
|
final_assign_signup_ids = SeminarSession.where(:id.in=>self.seminar_session_ids).pluck(:seminar_signup_ids).flatten.map{|id| id.to_s} rescue []
|
2021-04-24 10:41:50 +00:00
|
|
|
default_seminar_signup_ids = SeminarSession.where(:id.in=>self.seminar_session_ids).pluck(:default_seminar_signup_ids).flatten
|
|
|
|
default_seminar_signup_ids = SeminarSignup.where(:seminar_session_id=>nil,:id.in=>default_seminar_signup_ids).pluck(:id).map{|id| id.to_s} rescue []
|
|
|
|
result = final_assign_signup_ids + default_seminar_signup_ids + self.seminar_signup_ids - self.remove_seminar_signup_ids
|
2021-04-04 12:43:24 +00:00
|
|
|
result = result.uniq
|
2021-04-03 16:23:52 +00:00
|
|
|
else
|
2021-04-04 12:43:24 +00:00
|
|
|
result = all_seminar_signup_ids
|
2021-04-03 16:23:52 +00:00
|
|
|
end
|
2021-04-04 12:43:24 +00:00
|
|
|
result
|
2021-04-03 16:23:52 +00:00
|
|
|
end
|
2021-03-17 07:33:31 +00:00
|
|
|
def all_seminar_signup_ids
|
2021-04-04 12:43:24 +00:00
|
|
|
result = self.seminar_signup_ids - self.remove_seminar_signup_ids + self.default_seminar_signup_ids
|
|
|
|
result.uniq
|
2021-03-17 07:33:31 +00:00
|
|
|
end
|
|
|
|
def append_default_signup_id(signup_id)
|
|
|
|
sid = signup_id.to_s
|
|
|
|
unless self.default_seminar_signup_ids.include?(sid)
|
|
|
|
self.default_seminar_signup_ids << sid
|
|
|
|
end
|
|
|
|
end
|
2021-04-24 10:41:50 +00:00
|
|
|
def fix_assign
|
|
|
|
seminar_signups = SeminarSignup.where(:id.in=>self.seminar_signup_ids)
|
|
|
|
self.seminar_signup_ids = seminar_signups.pluck(:id).map{|id| id.to_s}
|
|
|
|
seminar_signups = seminar_signups.to_a
|
|
|
|
self.seminar_signup_contribute_ids = seminar_signups.map{|ss| ss.seminar_signup_contribute_ids}.flatten.map{|id| id.to_s}
|
|
|
|
|
|
|
|
remove_seminar_signups = SeminarSignup.where(:id.in=>self.remove_seminar_signup_ids)
|
|
|
|
self.remove_seminar_signup_ids = remove_seminar_signups.pluck(:id).map{|id| id.to_s}
|
|
|
|
remove_seminar_signups = remove_seminar_signups.to_a
|
|
|
|
self.remove_seminar_signup_contribute_ids = remove_seminar_signups.map{|ss| ss.seminar_signup_contribute_ids}.flatten.map{|id| id.to_s}
|
|
|
|
|
|
|
|
self.save
|
|
|
|
end
|
|
|
|
def clear_all_assign
|
|
|
|
self.seminar_signup_ids = []
|
|
|
|
self.remove_seminar_signup_ids = []
|
|
|
|
self.seminar_signup_contribute_ids = []
|
|
|
|
self.remove_seminar_signup_contribute_ids = []
|
|
|
|
self.save
|
|
|
|
end
|
2019-10-04 16:11:39 +00:00
|
|
|
end
|