active/app/models/act.rb

98 lines
3.5 KiB
Ruby
Raw Normal View History

2014-11-10 02:24:07 +00:00
class Act
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 :content, localize: true
field :place, localize: true
field :create_user_id
field :update_user_id
field :act_start_date , :type => DateTime, :default => Time.now
field :act_end_date , :type => DateTime, :default => Time.now
field :sign_start_date , :type => DateTime, :default => Time.now
field :sign_end_date , :type => DateTime, :default => Time.now
2015-11-20 12:08:11 +00:00
field :sign_up, :type => Boolean, :default => false
2014-11-10 02:24:07 +00:00
field :note, localize: true
2017-08-08 09:04:59 +00:00
field :has_name, :type => Boolean, :default => true
field :has_tel, :type => Boolean, :default => true
field :has_phone, :type => Boolean, :default => true
field :has_fax, :type => Boolean, :default => true
field :has_email, :type => Boolean, :default => true
field :has_idno, :type => Boolean, :default => false
field :has_sex, :type => Boolean, :default => false
field :has_birthday, :type => Boolean, :default => false
field :has_note, :type => Boolean, :default => false
field :has_organization, :type => Boolean, :default => false
field :has_title, :type => Boolean, :default => false
field :has_address, :type => Boolean, :default => false
field :has_emergency_contact_number, :type => Boolean, :default => false
field :has_emergency_contact_person, :type => Boolean, :default => false
field :has_vegetarian, :type => Boolean, :default => false
2017-08-08 11:44:37 +00:00
field :enabled_name, :type => Boolean, :default => true
field :enabled_tel, :type => Boolean, :default => true
field :enabled_phone, :type => Boolean, :default => true
field :enabled_fax, :type => Boolean, :default => true
field :enabled_email, :type => Boolean, :default => true
field :enabled_idno, :type => Boolean, :default => false
field :enabled_sex, :type => Boolean, :default => false
field :enabled_birthday, :type => Boolean, :default => false
field :enabled_note, :type => Boolean, :default => false
field :enabled_organization, :type => Boolean, :default => false
field :enabled_title, :type => Boolean, :default => false
field :enabled_address, :type => Boolean, :default => false
field :enabled_emergency_contact_number, :type => Boolean, :default => false
field :enabled_emergency_contact_person, :type => Boolean, :default => false
field :enabled_vegetarian, :type => Boolean, :default => false
2014-11-10 02:24:07 +00:00
has_many :act_links, :autosave => true, :dependent => :destroy
has_many :act_files, :autosave => true, :dependent => :destroy
has_many :act_signups, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :act_files, :allow_destroy => true
accepts_nested_attributes_for :act_links, :allow_destroy => true
accepts_nested_attributes_for :act_signups, :allow_destroy => true
scope :can_display, ->{any_of({:sign_start_date.lt=>Time.now, :sign_end_date.gt=>Time.now},{:sign_start_date.lt=>Time.now, :sign_end_date=>nil}).order_by([:is_top, :desc])}
def update_user
User.find(update_user_id) rescue nil
end
def update_user=(user)
self.update_user_id = user.id
end
def expired?
(self.sign_end_date < Time.now) rescue false
end
def self.time_range(date1 = null, date2 = null)
if !date1.blank?
r = "#{date1.strftime('%Y-%m-%d %H:%M')}"
if date2
r += " - #{date2.strftime('%Y-%m-%d %H:%M')}"
else
r += " - #{I18n.t(:no_deadline)}"
end
r
end
end
end