fix a problem with band location vs. user location management

This commit is contained in:
Scott Comer 2014-05-17 22:09:31 -05:00
parent 9eaa34b07f
commit a1b8d78e6a
2 changed files with 35 additions and 29 deletions

View File

@ -93,33 +93,39 @@ module JamRuby
end
def self.where_latlng(relation, params, current_user=nil)
# todo scott this needs to consider score instead
# if 0 < (distance = params[:distance].to_i)
# latlng = []
# if location_city = params[:city]
# if geo = self.where(:city => params[:city]).limit(1).first
# latlng = [geo.lat, geo.lng]
# end
# elsif current_user
# if current_user.lat.nil? || current_user.lng.nil?
# if params[:remote_ip] && (geo = self.ip_lookup(params[:remote_ip]))
# geo.lat = nil if geo.lat = 0
# geo.lng = nil if geo.lng = 0
# latlng = [geo.lat, geo.lng] if geo.lat && geo.lng
# end
# else
# latlng = [current_user.lat, current_user.lng]
# end
# elsif params[:remote_ip] && (geo = self.ip_lookup(params[:remote_ip]))
# geo.lat = nil if geo.lat = 0
# geo.lng = nil if geo.lng = 0
# latlng = [geo.lat, geo.lng] if geo.lat && geo.lng
# end
# if latlng.present?
# relation = relation.where(['lat IS NOT NULL AND lng IS NOT NULL'])
# .within(distance, :origin => latlng)
# end
# end
# this is only valid to call when relation is about bands
distance = params[:distance].to_i
if distance > 0
latlng = nil
location_city = params[:city]
location_state = params[:state]
location_country = params[:country]
remote_ip = params[:remote_ip]
if location_city and location_state and location_country
geo = self.where(city: location_city, region: location_state, country: location_country).limit(1).first
if geo and geo.lat and geo.lng and (geo.lat != 0 or geo.lng != 0)
# it isn't reasonable for both to be 0...
latlng = [geo.lat, geo.lng]
end
elsif current_user and current_user.locidispid and current_user.locidispid != 0
location = GeoIpLocations.lookup(current_user.locidispid/1000000)
if location and location.latitude and location.longitude and (location.latitude != 0 or location.longitude != 0)
# it isn't reasonable for both to be 0...
latlng = [location.latitude, location.longitude]
end
elsif remote_ip
geo = self.ip_lookup(remote_ip)
if geo and geo.lat and geo.lng and (geo.lat != 0 or geo.lng != 0)
# it isn't reasonable for both to be 0...
latlng = [geo.lat, geo.lng]
end
end
if latlng
relation = relation.where(['lat IS NOT NULL AND lng IS NOT NULL']).within(distance, origin: latlng)
end
end
relation
end

View File

@ -127,7 +127,7 @@ module JamRuby
.where(['minst.instrument_id = ? AND users.id IS NOT NULL', instrument])
end
rel = MaxMindGeo.where_latlng(rel, params, current_user)
# todo scott - rel = MaxMindGeo.where_latlng(rel, params, current_user)
sel_str = 'users.*'
case ordering = self.order_param(params)
@ -295,7 +295,7 @@ module JamRuby
.where(['bgenres.genre_id = ? AND bands.id IS NOT NULL', genre])
end
# todo scott this needs some scoring filter rel = MaxMindGeo.where_latlng(rel, params, current_user)
rel = MaxMindGeo.where_latlng(rel, params, current_user)
sel_str = 'bands.*'
case ordering = self.order_param(params)