seminar/app/models/seminar_main.rb

86 lines
3.2 KiB
Ruby

class SeminarMain
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Impression
# encoding: utf-8
include OrbitCategory::Categorizable
include Slug
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
belongs_to :seminar_item
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
has_many :seminar_submission_fields, :autosave => true, :dependent => :destroy
has_many :seminar_signup_fields, :autosave => true, :dependent => :destroy
has_many :seminar_reviews, :autosave => true, :dependent => :destroy
has_many :seminar_signup_field_sets, autosave: true, dependent: :destroy
has_many :seminar_submission_field_sets, autosave: true, dependent: :destroy
has_many :seminar_signup_field_customs, :autosave => true, :dependent => :destroy
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
accepts_nested_attributes_for :seminar_submission_fields, :allow_destroy => true
accepts_nested_attributes_for :seminar_signup_fields, :allow_destroy => true
accepts_nested_attributes_for :seminar_reviews, :allow_destroy => true
accepts_nested_attributes_for :seminar_signup_field_sets, :allow_destroy => true
accepts_nested_attributes_for :seminar_submission_field_sets, :allow_destroy => true
accepts_nested_attributes_for :seminar_signup_field_customs, :allow_destroy => true
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