active/app/models/act.rb

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