Class: Decidim::ParticipatoryProcesses::ParticipatoryProcessSearch

Inherits:
Decidim::ParticipatorySpaceSearch show all
Defined in:
decidim-participatory_processes/app/services/decidim/participatory_processes/participatory_process_search.rb

Overview

Service that encapsulates all logic related to filtering participatory processes.

Instance Method Summary collapse

Methods inherited from Decidim::ParticipatorySpaceSearch

#base_query, #search_area_id, #search_scope_id

Constructor Details

#initialize(options = {}) ⇒ ParticipatoryProcessSearch

Returns a new instance of ParticipatoryProcessSearch.


7
8
9
10
# File 'decidim-participatory_processes/app/services/decidim/participatory_processes/participatory_process_search.rb', line 7

def initialize(options = {})
  base_relation = options.has_key?(:base_relation) ? options.delete(:base_relation) : ParticipatoryProcess.all
  super(base_relation, options)
end

Instance Method Details

#search_dateObject


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'decidim-participatory_processes/app/services/decidim/participatory_processes/participatory_process_search.rb', line 12

def search_date
  case date
  when "active"
    query.active.order(start_date: :desc)
  when "past"
    query.past.order(end_date: :desc)
  when "upcoming"
    query.upcoming.order(start_date: :asc)
  else # Assume 'all'
    timezone = ActiveSupport::TimeZone.find_tzinfo(Time.zone.name).identifier
    query.order(Arel.sql("ABS(start_date - (CURRENT_DATE at time zone '#{timezone}')::date)"))
  end
end