2016-06-29 06:57:45 +00:00
|
|
|
class SeminarMain
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
include OrbitModel::Impression
|
|
|
|
# encoding: utf-8
|
|
|
|
include OrbitCategory::Categorizable
|
|
|
|
include Slug
|
|
|
|
|
2020-06-26 03:56:02 +00:00
|
|
|
field :signup_note, localize: true
|
2016-06-29 06:57:45 +00:00
|
|
|
field :title, as: :slug_title, type: String, localize: true
|
|
|
|
field :speaker, localize: true
|
|
|
|
field :content, localize: true
|
|
|
|
field :act_place, localize: true
|
|
|
|
|
|
|
|
field :seminar_start_date, :type => Date, :default => Time.now
|
|
|
|
field :seminar_end_date, :type => Date, :default => Time.now
|
|
|
|
|
|
|
|
field :signup_start_date, :type => Date, :default => Time.now
|
|
|
|
field :signup_end_date, :type => Date, :default => Time.now
|
|
|
|
|
|
|
|
field :contribute_start_date, :type => Date
|
|
|
|
field :contribute_end_date, :type => Date
|
|
|
|
|
|
|
|
field :contribute_file_count, type: String
|
|
|
|
|
|
|
|
field :registration_status , :type => Array #C: 投稿者 G:一般
|
|
|
|
|
|
|
|
field :create_user_id
|
|
|
|
field :update_user_id
|
2021-03-17 07:33:31 +00:00
|
|
|
field :reviewer_ids
|
|
|
|
field :reviewer_show_ids
|
|
|
|
field :unassigned_seminar_signup_ids
|
|
|
|
field :review_start_date, :type => Date
|
|
|
|
field :review_end_date, :type => Date
|
2016-06-29 06:57:45 +00:00
|
|
|
belongs_to :seminar_item
|
2021-03-17 07:33:31 +00:00
|
|
|
belongs_to :organizer , :class_name=>"MemberProfile", :foreign_key => :organizer_id
|
2016-06-29 06:57:45 +00:00
|
|
|
has_many :seminar_links, :autosave => true, :dependent => :destroy
|
|
|
|
has_many :seminar_files, :autosave => true, :dependent => :destroy
|
|
|
|
has_many :seminar_item_contents, :autosave => true, :dependent => :destroy
|
|
|
|
has_many :seminar_signups, :autosave => true, :dependent => :destroy
|
2019-11-26 15:52:52 +00:00
|
|
|
has_many :seminar_submission_fields, :autosave => true, :dependent => :destroy
|
2016-06-29 06:57:45 +00:00
|
|
|
has_many :seminar_signup_fields, :autosave => true, :dependent => :destroy
|
2019-10-04 16:11:39 +00:00
|
|
|
has_many :seminar_reviews, :autosave => true, :dependent => :destroy
|
2019-11-26 15:52:52 +00:00
|
|
|
has_many :seminar_signup_field_sets, autosave: true, dependent: :destroy
|
|
|
|
has_many :seminar_submission_field_sets, autosave: true, dependent: :destroy
|
2020-01-12 06:39:32 +00:00
|
|
|
has_many :seminar_email_sets, autosave: true, dependent: :destroy
|
2019-11-26 15:52:52 +00:00
|
|
|
has_many :seminar_signup_field_customs, :autosave => true, :dependent => :destroy
|
2016-06-29 06:57:45 +00:00
|
|
|
accepts_nested_attributes_for :seminar_links, :allow_destroy => true
|
|
|
|
accepts_nested_attributes_for :seminar_files, :allow_destroy => true
|
|
|
|
accepts_nested_attributes_for :seminar_item_contents, :allow_destroy => true
|
|
|
|
accepts_nested_attributes_for :seminar_signups, :allow_destroy => true
|
2019-11-26 15:52:52 +00:00
|
|
|
accepts_nested_attributes_for :seminar_submission_fields, :allow_destroy => true
|
2016-06-29 06:57:45 +00:00
|
|
|
accepts_nested_attributes_for :seminar_signup_fields, :allow_destroy => true
|
2019-10-04 16:11:39 +00:00
|
|
|
accepts_nested_attributes_for :seminar_reviews, :allow_destroy => true
|
2019-11-26 15:52:52 +00:00
|
|
|
accepts_nested_attributes_for :seminar_signup_field_sets, :allow_destroy => true
|
|
|
|
accepts_nested_attributes_for :seminar_submission_field_sets, :allow_destroy => true
|
2020-01-12 06:39:32 +00:00
|
|
|
accepts_nested_attributes_for :seminar_email_sets, :allow_destroy => true
|
2019-11-26 15:52:52 +00:00
|
|
|
accepts_nested_attributes_for :seminar_signup_field_customs, :allow_destroy => true
|
2021-03-17 07:33:31 +00:00
|
|
|
before_save do
|
|
|
|
module_app_key = "seminar"
|
|
|
|
add_module_app_member_ids = []
|
|
|
|
remove_module_app_member_ids = []
|
|
|
|
if self.reviewer_ids_changed?
|
|
|
|
new_reviewer_ids = self.reviewer_ids.to_a - self.reviewer_ids_was.to_a
|
|
|
|
remove_reviewer_ids = self.reviewer_ids_was.to_a - self.reviewer_ids.to_a
|
|
|
|
new_reviewer_ids.each do |reviewer_id|
|
|
|
|
SeminarReview.create(:reviewer_id=>reviewer_id,:seminar_main=>self)
|
|
|
|
add_module_app_member_ids << reviewer_id
|
|
|
|
end
|
|
|
|
remove_reviewer_ids.each do |reviewer_id|
|
|
|
|
SeminarReview.where(:reviewer_id=>reviewer_id,:seminar_main=>self).destroy
|
|
|
|
remove_module_app_member_ids << reviewer_id
|
|
|
|
end
|
|
|
|
unassigned_seminar_signup_ids = self.seminar_signup_ids.map{|s| s.to_s}
|
|
|
|
seminar_reviews = self.seminar_reviews
|
|
|
|
seminar_reviews.each do |sr|
|
|
|
|
unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids
|
|
|
|
end
|
|
|
|
self.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids
|
|
|
|
end
|
|
|
|
if self.organizer_id_changed?
|
|
|
|
if self.organizer_id_was.present?
|
|
|
|
remove_module_app_member_ids << self.organizer_id_was
|
|
|
|
end
|
|
|
|
if self.organizer_id.present?
|
|
|
|
add_module_app_member_ids << self.organizer_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
remove_module_app_member_ids.delete(self.organizer_id)
|
2021-03-17 09:16:08 +00:00
|
|
|
self.reviewer_ids.each{|r| remove_module_app_member_ids.delete(r)} rescue nil
|
2021-03-17 07:33:31 +00:00
|
|
|
remove_module_app_member_ids.each do |m_id|
|
|
|
|
user = User.where(:member_profile_id=>m_id).first
|
|
|
|
begin
|
|
|
|
user.extra_link_module_app_keys.delete(module_app_key)
|
|
|
|
user.save
|
|
|
|
rescue
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
add_module_app_member_ids.each do |m_id|
|
|
|
|
user = User.where(:member_profile_id=>m_id).first
|
|
|
|
begin
|
|
|
|
user.extra_link_module_app_keys << module_app_key
|
|
|
|
user.save
|
|
|
|
rescue
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
before_create do
|
|
|
|
self.unassigned_seminar_signup_ids = []
|
|
|
|
end
|
|
|
|
after_initialize do
|
|
|
|
unless self.new_record?
|
|
|
|
save_flag = false
|
|
|
|
seminar_reviews = self.seminar_reviews
|
|
|
|
if seminar_reviews.present?
|
|
|
|
if self["reviewer_ids"].nil?
|
|
|
|
self["reviewer_ids"] = seminar_reviews.pluck(:reviewer_id).flatten.select{|s| !s.nil?}.to_a
|
|
|
|
save_flag = true
|
|
|
|
end
|
|
|
|
if seminar_reviews.count != 0 && self.review_start_date.nil? && self.review_end_date.nil?
|
|
|
|
seminar_review = seminar_reviews.first
|
|
|
|
self.review_start_date = seminar_review.review_start_date rescue nil
|
|
|
|
self.review_end_date = seminar_review.review_end_date rescue nil
|
|
|
|
unless (self.review_start_date.nil? && self.review_end_date.nil?)
|
|
|
|
save_flag = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.unassigned_seminar_signup_ids.nil?
|
|
|
|
self.unassigned_seminar_signup_ids = self.seminar_signup_ids.map{|s| s.to_s}
|
|
|
|
save_flag = true
|
|
|
|
end
|
|
|
|
self.save if save_flag
|
|
|
|
end
|
|
|
|
end
|
2016-06-29 06:57:45 +00:00
|
|
|
def self.time_range(date1 = null, date2 = null)
|
|
|
|
|
|
|
|
if !date1.blank?
|
|
|
|
|
|
|
|
r = "#{date1.strftime('%Y-%m-%d')}"
|
|
|
|
|
|
|
|
if date2
|
|
|
|
r += " - #{date2.strftime('%Y-%m-%d')}"
|
|
|
|
else
|
|
|
|
r += " - #{I18n.t(:no_deadline)}"
|
|
|
|
end
|
|
|
|
|
|
|
|
r
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_attribute_value(attribute_field, signup_id)
|
|
|
|
SeminarSignupValue.find_by(seminar_signup_field_id: attribute_field.id, seminar_signup_id: signup_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_attribute_values(attribute_type=nil)
|
|
|
|
@attribute_values = attribute_type.seminar_signup_values rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_value_from_field_id(field_id,attribute_type=nil)
|
|
|
|
values = get_attribute_values(attribute_type)
|
|
|
|
value = values.detect {|value| value.seminar_signup_field_id == field_id} rescue nil
|
|
|
|
value ? value : nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|