Sha256: b73d3e92beb358dd219d564b6b5ba4dbbc5b2c66fd0384af5d7859f2e6f58b3e

Contents?: true

Size: 1.65 KB

Versions: 40

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # This class handles search and filtering of meetings. Needs a
    # `current_feature` param with a `Decidim::Feature` in order to
    # find the meetings.
    class MeetingSearch < ResourceSearch
      # Public: Initializes the service.
      # feature     - A Decidim::Feature to get the meetings from.
      # page        - The page number to paginate the results.
      # per_page    - The number of proposals to return per page.
      def initialize(options = {})
        super(Meeting.all, options)
      end

      # Handle the search_text filter
      def search_search_text
        query
          .where(localized_search_text_in(:title), text: "%#{search_text}%")
          .or(query.where(localized_search_text_in(:description), text: "%#{search_text}%"))
      end

      # Handle the date filter
      def search_date
        if options[:date] == "upcoming"
          query.where("start_time >= ? ", Time.current).order(start_time: :asc)
        elsif options[:date] == "past"
          query.where("start_time <= ? ", Time.current).order(start_time: :desc)
        end
      end

      private

      # Internal: builds the needed query to search for a text in the organization's
      # available locales. Note that it is intended to be used as follows:
      #
      # Example:
      #   Resource.where(localized_search_text_for(:title, text: "my_query"))
      #
      # The Hash with the `:text` key is required or it won't work.
      def localized_search_text_in(field)
        options[:organization].available_locales.map { |l| "#{field} ->> '#{l}' ILIKE :text" }.join(" OR ")
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
decidim-meetings-0.6.6 app/services/decidim/meetings/meeting_search.rb
decidim-0.6.6 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.6.5 app/services/decidim/meetings/meeting_search.rb
decidim-0.6.5 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.6.4 app/services/decidim/meetings/meeting_search.rb
decidim-0.6.4 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.6.3 app/services/decidim/meetings/meeting_search.rb
decidim-0.6.3 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.6.2 app/services/decidim/meetings/meeting_search.rb
decidim-0.6.2 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.6.1 app/services/decidim/meetings/meeting_search.rb
decidim-0.6.1 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.6.0 app/services/decidim/meetings/meeting_search.rb
decidim-0.6.0 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.5.1 app/services/decidim/meetings/meeting_search.rb
decidim-0.5.1 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.5.0 app/services/decidim/meetings/meeting_search.rb
decidim-0.5.0 decidim-meetings/app/services/decidim/meetings/meeting_search.rb
decidim-meetings-0.4.4 app/services/decidim/meetings/meeting_search.rb
decidim-0.4.4 decidim-meetings/app/services/decidim/meetings/meeting_search.rb