Sha256: c773b2a620a4a52e3f456dc51a7f2fb27fac0fbbddc7a1056daf2d0cfdadf8bf

Contents?: true

Size: 1.35 KB

Versions: 63

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Decidim
  module Sortitions
    # A class used to find sortitions filtered by components and a date range
    class FilteredSortitions < Rectify::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # components - An array of Decidim::Component
      # start_at - A date to filter resources created after it
      # end_at - A date to filter resources created before it.
      def self.for(components, start_at = nil, end_at = nil)
        new(components, start_at, end_at).query
      end

      # Initializes the class.
      #
      # components - An array of Decidim::Component
      # start_at - A date to filter resources created after it
      # end_at - A date to filter resources created before it.
      def initialize(components, start_at = nil, end_at = nil)
        @components = components
        @start_at = start_at
        @end_at = end_at
      end

      # Finds the Proposals scoped to an array of components and filtered
      # by a range of dates.
      def query
        sortitions = Decidim::Sortitions::Sortition.where(component: @components)
        sortitions = sortitions.where("created_at >= ?", @start_at) if @start_at.present?
        sortitions = sortitions.where("created_at <= ?", @end_at) if @end_at.present?
        sortitions
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
decidim-sortitions-0.17.2 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.18.0 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.17.1 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.16.1 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.17.0 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.16.0 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.15.2 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.15.1 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.15.0 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.14.4 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.14.3 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.14.2 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.14.1 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.13.1 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.12.2 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.13.0 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.12.1 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.13.0.pre1 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.12.0 app/queries/decidim/sortitions/filtered_sortitions.rb
decidim-sortitions-0.11.2 app/queries/decidim/sortitions/filtered_sortitions.rb