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 field :sign_up, :type => Boolean, :default => false field :note, localize: true 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 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