Module: EffectiveMembershipsDirectory

Extended by:
ActiveSupport::Concern
Included in:
Effective::MembershipDirectory
Defined in:
app/models/concerns/effective_memberships_directory.rb

Overview

This is a search model for the MembershipDirectories screen

EffectiveMembershipsDirectory Mark your directory search model with include EffectiveMembershipsDirectory

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#categoriesObject



35
36
37
# File 'app/models/concerns/effective_memberships_directory.rb', line 35

def categories
  EffectiveMemberships.Category.membership_directory.all
end

#collectionObject

Base collection to search. Can be configured per tenant.



40
41
42
43
44
45
# File 'app/models/concerns/effective_memberships_directory.rb', line 40

def collection
  Effective::Membership.deep.sorted
    .in_good_standing
    .without_archived_owners
    .with_category(categories)
end

#membershipsObject

The unpaginated results of the search



71
72
73
# File 'app/models/concerns/effective_memberships_directory.rb', line 71

def memberships
  @memberships || collection
end

#per_pageObject



53
54
55
# File 'app/models/concerns/effective_memberships_directory.rb', line 53

def per_page
  24
end

#present?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/concerns/effective_memberships_directory.rb', line 57

def present?
  term.present? || first_name.present? || last_name.present? || title.present? || category.present?
end

#results(page: nil) ⇒ Object

The paginated results



76
77
78
79
80
81
# File 'app/models/concerns/effective_memberships_directory.rb', line 76

def results(page: nil)
  page = (page || 1).to_i
  offset = [(page - 1), 0].max * per_page

  memberships.limit(per_page).offset(offset)
end

#search!Object

Search and assigns the collection Assigns the entire collection() if there are no search terms Otherwise validate the search terms



64
65
66
67
68
# File 'app/models/concerns/effective_memberships_directory.rb', line 64

def search!
  @memberships = build_collection()
  @memberships = @memberships.none if present? && !valid?
  @memberships
end

#search_any_columnsObject

Search Users and Organizations for only these fields. Passed into search_any. Return nil for all. Should this include email?



49
50
51
# File 'app/models/concerns/effective_memberships_directory.rb', line 49

def search_any_columns
  [:title, :name, :first_name, :middle_name, :last_name]
end