Class: Decidim::ParticipatoryProcesses::FilteredParticipatoryProcessGroups

Inherits:
Query
  • Object
show all
Defined in:
decidim-participatory_processes/app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb

Overview

This query class filters participatory processes groups given a filter name. The filter is applied checking the start and end dates of the processes in the group.

Instance Method Summary collapse

Methods inherited from Query

#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|

Constructor Details

#initialize(filter = "active") ⇒ FilteredParticipatoryProcessGroups

Returns a new instance of FilteredParticipatoryProcessGroups.


9
10
11
# File 'decidim-participatory_processes/app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb', line 9

def initialize(filter = "active")
  @filter = filter
end

Instance Method Details

#queryObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'decidim-participatory_processes/app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb', line 13

def query
  processes = Decidim::ParticipatoryProcess.all

  processes = case @filter
              when "past"
                processes.where("decidim_participatory_processes.end_date <= ?", Date.current)
              when "upcoming"
                processes.where("decidim_participatory_processes.start_date > ?", Date.current)
              else
                processes
              end

  Decidim::ParticipatoryProcessGroup.where(id: processes.pluck(:decidim_participatory_process_group_id))
end