Sha256: 5685c5ae55715c8f537f280b0c5af78406d375843e6abd387635921c363c758d
Contents?: true
Size: 1.33 KB
Versions: 25
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true module Decidim module Proposals # A class used to find proposals filtered by components and a date range class FilteredProposals < Decidim::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 proposals = Decidim::Proposals::Proposal.where(component: @components) proposals = proposals.where("created_at >= ?", @start_at) if @start_at.present? proposals = proposals.where("created_at <= ?", @end_at) if @end_at.present? proposals end end end end
Version data entries
25 entries across 25 versions & 1 rubygems