Sha256: 343a4d5724d20f87e39c7dbad0cc2d84cd8be07980964e70c9754cbde84bcc2d

Contents?: true

Size: 993 Bytes

Versions: 50

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    # 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.
    class FilteredParticipatoryProcessGroups < Rectify::Query
      def initialize(filter = "active")
        @filter = filter
      end

      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
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.26.7 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.5 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.4 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.3 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.2 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.1 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.0 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.0.rc2 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.26.0.rc1 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.25.2 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.25.1 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.25.0 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.25.0.rc4 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.25.0.rc3 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.25.0.rc2 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.25.0.rc1 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.24.3 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.23.6 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.24.2 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb
decidim-participatory_processes-0.23.5 app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb