153 lines
6.4 KiB
Ruby
153 lines
6.4 KiB
Ruby
class VenueManagementMain
|
|
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 :land_number, localize: true
|
|
field :land_area, localize: true
|
|
field :building_area, localize: true
|
|
field :area, localize: true
|
|
field :land_zoning, localize: true
|
|
field :act_place, localize: true
|
|
field :manager_ids, type: Array,default: []
|
|
field :contractor_ids, type: Array,default: []
|
|
field :coordinator_ids, type: Array,default: []
|
|
field :venue_management_start_date, :type => Date, :default => Time.now
|
|
field :venue_management_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 :inviting_history , :type => Integer
|
|
field :contract_history , :type => Integer
|
|
field :memorabilia, :type => Integer
|
|
field :create_user_id
|
|
field :update_user_id
|
|
|
|
belongs_to :venue_management_item
|
|
|
|
has_many :venue_management_invitings, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_memorabilias, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_bills, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_contracts, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_item_contents, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_signups, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_submission_fields, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_signup_fields, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_reviews, :autosave => true, :dependent => :destroy
|
|
has_many :venue_management_signup_field_sets, autosave: true, dependent: :destroy
|
|
has_many :venue_management_submission_field_sets, autosave: true, dependent: :destroy
|
|
has_many :venue_management_email_sets, autosave: true, dependent: :destroy
|
|
has_many :venue_management_signup_field_customs, :autosave => true, :dependent => :destroy
|
|
accepts_nested_attributes_for :venue_management_memorabilias, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_item_contents, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_signups, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_submission_fields, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_signup_fields, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_reviews, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_signup_field_sets, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_submission_field_sets, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_email_sets, :allow_destroy => true
|
|
accepts_nested_attributes_for :venue_management_signup_field_customs, :allow_destroy => true
|
|
include VenueLinkFile
|
|
after_initialize do
|
|
unless self.new_record?
|
|
if self.inviting_history.nil?
|
|
self.inviting_history = self.venue_management_invitings.count rescue 0
|
|
self.save(:validate=>false)
|
|
self.class.all.each do |record|
|
|
record.inviting_history = record.venue_management_invitings.count rescue 0
|
|
record.contract_history = record.venue_management_contracts.count rescue 0
|
|
record.memorabilia = record.venue_management_memorabilias.count rescue 0
|
|
record.save(:validate=>false)
|
|
end
|
|
end
|
|
if self.contract_history.nil?
|
|
self.contract_history = self.venue_management_contracts.count rescue 0
|
|
self.save(:validate=>false)
|
|
end
|
|
if self.memorabilia.nil?
|
|
self.memorabilia = self.venue_management_memorabilias.count rescue 0
|
|
self.save(:validate=>false)
|
|
end
|
|
end
|
|
end
|
|
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 contractors
|
|
last_contract = self.venue_management_contracts.desc(:id).first
|
|
last_contract.contractors rescue []
|
|
end
|
|
def display_contractors
|
|
last_contract = self.venue_management_contracts.desc(:id).first
|
|
contractors = last_contract.contractors rescue []
|
|
contractors.map{|m| m.name}.join(" , ")
|
|
end
|
|
def display_tags
|
|
last_inviting = self.venue_management_invitings.desc(:id).first
|
|
last_inviting.tags.map{|t| t.name}.join(" , ") rescue ""
|
|
end
|
|
def display_event_during
|
|
last_contract = self.venue_management_contracts.desc(:id).first
|
|
if last_contract.nil?
|
|
"" #self.class.time_range(self.venue_management_start_date, self.venue_management_end_date)
|
|
else
|
|
self.class.time_range(last_contract.contract_start_date, last_contract.contract_end_date)
|
|
end
|
|
end
|
|
def display_signup_during
|
|
last_inviting = self.venue_management_invitings.desc(:id).first
|
|
if last_inviting.nil?
|
|
"" #self.class.time_range(self.signup_start_date, self.signup_end_date)
|
|
else
|
|
self.class.time_range(last_inviting.start_date, last_inviting.end_date)
|
|
end
|
|
end
|
|
def manager_emails
|
|
MemberProfile.where(:id.in => self.manager_ids).collect{|v| v.email}
|
|
end
|
|
|
|
def get_attribute_value(attribute_field, signup_id)
|
|
VenueManagementSignupValue.find_by(venue_management_signup_field_id: attribute_field.id, venue_management_signup_id: signup_id)
|
|
end
|
|
|
|
def get_attribute_values(attribute_type=nil)
|
|
@attribute_values = attribute_type.venue_management_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.venue_management_signup_field_id == field_id} rescue nil
|
|
value ? value : nil
|
|
end
|
|
def case_no
|
|
''
|
|
end
|
|
def newest_case_no
|
|
last_contract = self.venue_management_contracts.desc(:id).first
|
|
newest_case_no = last_contract.venue_management_inviting.case_no rescue ""
|
|
return ( newest_case_no.blank? ? I18n.t(:empty) : newest_case_no)
|
|
end
|
|
end
|