Class: AccreditedOrganization

Inherits:
ApplicationRecord show all
Defined in:
app/models/accredited_organization.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Class Method Details

.find_within_max_distance(long, lat, max_distance = AccreditedRepresentation::Constants::DEFAULT_MAX_DISTANCE) ⇒ AccreditedOrganization::ActiveRecord_Relation

Find all [AccreditedOrganizations] that are located within a distance of a specific location

Parameters:

  • long (Float)

    longitude of the location of interest

  • lat (Float)

    latitude of the location of interest

  • max_distance (Float) (defaults to: AccreditedRepresentation::Constants::DEFAULT_MAX_DISTANCE)

    the maximum search distance in meters

Returns:

  • (AccreditedOrganization::ActiveRecord_Relation)

    an ActiveRecord_Relation of all organizations matching the search criteria



34
35
36
37
38
39
40
# File 'app/models/accredited_organization.rb', line 34

def self.find_within_max_distance(long, lat, max_distance = AccreditedRepresentation::Constants::DEFAULT_MAX_DISTANCE)
  query = 'ST_DWithin(ST_SetSRID(ST_MakePoint(:long, :lat), 4326)::geography,' \
          'accredited_organizations.location, :max_distance)'
  params = { long:, lat:, max_distance: }

  where(query, params)
end

.max_per_pageObject

This method needs to exist on the model so [Common::Collection] doesn’t blow up when trying to paginate



50
51
52
# File 'app/models/accredited_organization.rb', line 50

def self.max_per_page
  AccreditedRepresentation::Constants::MAX_PER_PAGE
end

Instance Method Details

#registration_numbersArray<String>

return all registration_numbers associated with the organization

Returns:

  • (Array<String>)


45
46
47
# File 'app/models/accredited_organization.rb', line 45

def registration_numbers
  accredited_individuals.pluck(:registration_number)
end