Sha256: 26f8a4d283deda3ba732c5042e51957f481923ee44f27060b912b009ed12d0c5

Contents?: true

Size: 936 Bytes

Versions: 12

Compression:

Stored size: 936 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    # Service that encapsulates all logic related to filtering participatory processes.
    class ParticipatoryProcessSearch < ParticipatorySpaceSearch
      def initialize(options = {})
        base_relation = options.has_key?(:base_relation) ? options.delete(:base_relation) : ParticipatoryProcess.all
        super(base_relation, options)
      end

      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)").to_s)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.26.10 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.9 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.8 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.7 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.5 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.4 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.3 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.2 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.1 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.0 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.0.rc2 app/services/decidim/participatory_processes/participatory_process_search.rb
decidim-participatory_processes-0.26.0.rc1 app/services/decidim/participatory_processes/participatory_process_search.rb