class SessionSearchForm
Constants
- VALID_STATUS_SCOPES
Public Instance Methods
Source
# File app/forms/session_search_form.rb, line 10 def academic_year = super || AcademicYear.pending def programmes=(values) super(values&.compact_blank || []) end def apply(scope) scope = filter_academic_year(scope) scope = filter_programmes(scope) scope = filter_name(scope) scope = filter_type(scope) scope = filter_status(scope) scope.order_by_earliest_date end private def filter_academic_year(scope) scope.for_academic_year(academic_year) end def filter_programmes(scope) programmes.present? ? scope.has_all_programme_types_of(programmes) : scope end def filter_name(scope) q.present? ? scope.search_by_name(q) : scope end def filter_type(scope) type.present? ? scope.joins(:location).where(locations: { type: }) : scope end def filter_status(scope) status.in?(VALID_STATUS_SCOPES) ? scope.public_send(status) : scope end VALID_STATUS_SCOPES = %w[in_progress unscheduled scheduled completed].freeze end
Source
# File app/forms/session_search_form.rb, line 16 def apply(scope) scope = filter_academic_year(scope) scope = filter_programmes(scope) scope = filter_name(scope) scope = filter_type(scope) scope = filter_status(scope) scope.order_by_earliest_date end
Source
# File app/forms/session_search_form.rb, line 28 def filter_academic_year(scope) scope.for_academic_year(academic_year) end
Source
# File app/forms/session_search_form.rb, line 36 def filter_name(scope) q.present? ? scope.search_by_name(q) : scope end
Source
# File app/forms/session_search_form.rb, line 32 def filter_programmes(scope) programmes.present? ? scope.has_all_programme_types_of(programmes) : scope end
Source
# File app/forms/session_search_form.rb, line 44 def filter_status(scope) status.in?(VALID_STATUS_SCOPES) ? scope.public_send(status) : scope end
Source
# File app/forms/session_search_form.rb, line 40 def filter_type(scope) type.present? ? scope.joins(:location).where(locations: { type: }) : scope end
Source
# File app/forms/session_search_form.rb, line 12 def programmes=(values) super(values&.compact_blank || []) end
Calls superclass method