Sha256: ca3b9c739bf01ff41969c3c7257495ff495a77e49e1377e97abfdfc75021d50f

Contents?: true

Size: 1020 Bytes

Versions: 10

Compression:

Stored size: 1020 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 << ["Reviewed", 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

10 entries across 10 versions & 1 rubygems

Version Path
cms-fortress-1.1.8 app/models/cms/page_workflow.rb
cms-fortress-1.1.7 app/models/cms/page_workflow.rb
cms-fortress-1.1.6 app/models/cms/page_workflow.rb
cms-fortress-1.1.5 app/models/cms/page_workflow.rb
cms-fortress-1.1.4 app/models/cms/page_workflow.rb
cms-fortress-1.1.3 app/models/cms/page_workflow.rb
cms-fortress-1.1.2 app/models/cms/page_workflow.rb
cms-fortress-1.1.1 app/models/cms/page_workflow.rb
cms-fortress-1.1.0 app/models/cms/page_workflow.rb
cms-fortress-1.0.12 app/models/cms/page_workflow.rb