Class: Decidim::Meetings::MeetingSearch

Inherits:
ResourceSearch
  • Object
show all
Defined in:
decidim-meetings/app/services/decidim/meetings/meeting_search.rb

Overview

This class handles search and filtering of meetings. Needs a ‘current_feature` param with a `Decidim::Feature` in order to find the meetings.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MeetingSearch

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.



13
14
15
# File 'decidim-meetings/app/services/decidim/meetings/meeting_search.rb', line 13

def initialize(options = {})
  super(Meeting.all, options)
end

Instance Method Details

#search_dateObject

Handle the date filter



25
26
27
28
29
30
31
# File 'decidim-meetings/app/services/decidim/meetings/meeting_search.rb', line 25

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

#search_search_textObject

Handle the search_text filter



18
19
20
21
22
# File 'decidim-meetings/app/services/decidim/meetings/meeting_search.rb', line 18

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