Legislation Process page
This commit is contained in:
@@ -3,6 +3,7 @@ class Legislation::Process < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
has_many :draft_versions, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id'
|
||||
has_one :final_draft_version, -> { where final_version: true }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id'
|
||||
has_many :questions, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id'
|
||||
|
||||
validates :title, presence: true
|
||||
@@ -18,7 +19,38 @@ class Legislation::Process < ActiveRecord::Base
|
||||
validates :allegations_end_date, presence: true
|
||||
validates :final_publication_date, presence: true
|
||||
|
||||
scope :open, -> {where("start_date <= ? and end_date >= ?", Time.current, Time.current) }
|
||||
scope :next, -> {where("start_date > ?", Time.current) }
|
||||
scope :past, -> {where("end_date < ?", Time.current) }
|
||||
scope :open, -> {where("start_date <= ? and end_date >= ?", Date.current, Date.current) }
|
||||
scope :next, -> {where("start_date > ?", Date.current) }
|
||||
scope :past, -> {where("end_date < ?", Date.current) }
|
||||
|
||||
def open_phase?(phase)
|
||||
today = Date.current
|
||||
|
||||
case phase
|
||||
when :debate
|
||||
today >= debate_start_date && today <= debate_end_date
|
||||
when :draft_publication
|
||||
today >= draft_publication_date
|
||||
when :allegations
|
||||
today >= allegations_start_date && today <= allegations_end_date
|
||||
when :final_version_publication
|
||||
today >= final_publication_date
|
||||
end
|
||||
end
|
||||
|
||||
def show_phase?(phase)
|
||||
# show past phases even if they're finished
|
||||
today = Date.current
|
||||
|
||||
case phase
|
||||
when :debate
|
||||
today >= debate_start_date
|
||||
when :draft_publication
|
||||
today >= draft_publication_date
|
||||
when :allegations
|
||||
today >= allegations_start_date
|
||||
when :final_version_publication
|
||||
today >= final_publication_date
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user