OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/app/models/announcement.rb

26 lines
622 B

class Announcement < ActiveRecord::Base
scope :active, -> { where(active: true) }
scope :current, -> { where('show_until >= ?', Date.today) }
validates :show_until, presence: true
def self.active_and_current
active.current.first
end
def self.only_one
a = first
a = create_default_announcement if a.nil?
a
end
def active_and_current?
active? && show_until && show_until >= Date.today
end
def self.create_default_announcement
Announcement.create text: 'Announcement',
show_until: Date.today + 14.days,
active: false
end
end