Sha256: 10429a65462488a2c104044e38ee953e123bc1b394adc668ea6cca8870555f24

Contents?: true

Size: 1018 Bytes

Versions: 2

Compression:

Stored size: 1018 Bytes

Contents

class Cms::PageWorkflow < ActiveRecord::Base
  self.table_name = 'cms_page_workflows'

  belongs_to :page, :foreign_key => 'cms_page_id'

  after_save do |record|
    record.page.update_attribute(:is_published, record.page_published?)
  end

  def self.statuses
    {
      0 => :draft,
      1 => :reviewed,
      # 2 => :scheduled,
      3 => :published
    }
  end

  def self.statuses_for_select(can_publish, can_review)
    ret = [["Draft", 0]]
    ret << ["Review", 1] if can_review
    ret << ["Published", 3] if can_publish
    # self.statuses.map {|k,v| [v.to_s.titleize, k]}
    ret
  end

  def self.cached_timeout_for_select
    {
      "Uncached" => 0,
      "15 minutes" => 15.minutes,
      "30 minutes" => 30.minutes,
      "1 hour" => 1.hour,
      "3 hours" => 3.hours,
      "24 hours" => 1.day,
      "15 days" => 15.days,
      "30 days" => 30.days
    }.map {|k,v| [k, v.to_i] }
  end

  def page_published?
    (status_id.eql?(3) || status_id.eql?(2)) && published_date <= Date.today
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cms-fortress-1.0.9 app/models/cms/page_workflow.rb
cms-fortress-1.0.8 app/models/cms/page_workflow.rb