157 lines
5.6 KiB
Ruby
157 lines
5.6 KiB
Ruby
class Act
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
include OrbitModel::Impression
|
|
# encoding: utf-8
|
|
|
|
include OrbitCategory::Categorizable
|
|
include Slug
|
|
|
|
include OrbitModel::Status
|
|
field :image_description, type: String, localize: true
|
|
field :top_end_date, :type => DateTime
|
|
mount_uploader :image, ImageUploader
|
|
field :is_external_link, type: Boolean, default: false
|
|
field :external_link, type: String, default: ""
|
|
|
|
field :title, as: :slug_title, type: String, localize: true
|
|
field :subtitle, type: String, localize: true
|
|
|
|
field :content, localize: true
|
|
field :place, localize: true
|
|
field :create_user_id
|
|
field :update_user_id
|
|
field :postdate , :type => DateTime, :default => Time.now
|
|
field :end_date , :type => DateTime, :default => Time.now
|
|
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
|
|
|
|
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
|
|
|
|
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])}
|
|
scope :can_display_on_front, ->{any_of({:postdate.lt=>Time.now, :end_date.gt=>Time.now},{:postdate.lt=>Time.now, :end_date=>nil}).order_by(:is_top.desc, :postdate.desc, :sign_start_date.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.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
|
|
|
|
def self.remove_expired_status
|
|
self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |act|
|
|
act.is_top = false
|
|
act.top_end_date = nil
|
|
act.save
|
|
end
|
|
end
|
|
|
|
def top_text
|
|
I18n.t("top")
|
|
end
|
|
def hot_text
|
|
I18n.t("hot")
|
|
end
|
|
def hidden_text
|
|
I18n.t("hidden")
|
|
end
|
|
|
|
def statuses_with_classname
|
|
statuses = []
|
|
statuses << {"name" => top_text, "classname" => "top"} if is_top?
|
|
statuses << {"name" => hot_text, "classname" => "hot"} if is_hot?
|
|
statuses << {"name" => hidden_text, "classname" => "hidden"} if is_hidden?
|
|
statuses
|
|
end
|
|
|
|
def is_external_link?
|
|
self.is_external_link && !self.external_link.blank?
|
|
end
|
|
|
|
def signup_show
|
|
time_now = Time.now
|
|
if self.sign_up
|
|
sign_start_date_checked = (self.sign_start_date.nil? || self.sign_start_date <= time_now)
|
|
sign_end_date_checked = (self.sign_end_date.nil? || self.sign_end_date >= time_now)
|
|
if sign_start_date_checked && sign_end_date_checked
|
|
sign_up_text = ('<a href="'+ (self.is_external_link? ? self.external_link : OrbitHelper.url_to_show(self.to_param)) + '" target="_blank">' + I18n.t('act.sign_up') + '</a>').html_safe
|
|
elsif !sign_start_date_checked
|
|
sign_up_text = I18n.t('act.sign_up_not_yet')
|
|
else
|
|
sign_up_text = I18n.t('act.sign_up_overdue')
|
|
end
|
|
else
|
|
sign_up_text = I18n.t('act.sign_up_not_open')
|
|
end
|
|
end
|
|
|
|
end
|