2014-09-02 18:07:02 +05:30
|
|
|
class BroadcastMessage < ActiveRecord::Base
|
2016-11-03 12:29:30 +05:30
|
|
|
include CacheMarkdownField
|
2015-04-26 12:48:37 +05:30
|
|
|
include Sortable
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
cache_markdown_field :message, pipeline: :broadcast_message
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
validates :message, presence: true
|
2014-09-02 18:07:02 +05:30
|
|
|
validates :starts_at, presence: true
|
2015-12-23 02:04:40 +05:30
|
|
|
validates :ends_at, presence: true
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
validates :color, allow_blank: true, color: true
|
|
|
|
validates :font, allow_blank: true, color: true
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
default_value_for :color, '#E75E40'
|
|
|
|
default_value_for :font, '#FFFFFF'
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def self.current
|
2016-04-02 18:10:28 +05:30
|
|
|
Rails.cache.fetch("broadcast_message_current", expires_in: 1.minute) do
|
|
|
|
where("ends_at > :now AND starts_at <= :now", now: Time.zone.now).last
|
|
|
|
end
|
2016-01-19 16:12:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def active?
|
|
|
|
started? && !ended?
|
|
|
|
end
|
|
|
|
|
|
|
|
def started?
|
|
|
|
Time.zone.now >= starts_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def ended?
|
|
|
|
ends_at < Time.zone.now
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|