Sha256: 8ceef9ff67948c84819990bbcae288f61882768493b3f50d0d9b7c6e1eeabc7c

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # A class used to find meetings filtered by components and a date range
    class FilteredMeetings < 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 Projects scoped to an array of components and filtered
      # by a range of dates.
      def query
        meetings = Decidim::Meetings::Meeting.not_hidden.where(component: @components)
        meetings = meetings.where("created_at >= ?", @start_at) if @start_at.present?
        meetings = meetings.where("created_at <= ?", @end_at) if @end_at.present?
        meetings
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-meetings-0.24.3 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.6 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.24.2 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.5 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.24.1 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.24.0 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.24.0.rc2 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.4 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.24.0.rc1 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.3 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.2 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.1 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.1.rc1 app/queries/decidim/meetings/filtered_meetings.rb
decidim-meetings-0.23.0 app/queries/decidim/meetings/filtered_meetings.rb