+ return el1
+ end
+
+ def languages
+ attribute_present?(:languages) ? read_attribute(:languages).split(",") : []
+ end
+
+ def languages=(languages)
+ write_attribute(:languages, languages.join(","))
+ end
+
+ def preferred_language
+ languages.find { |l| Language.find(:first, :conditions => { :code => l }) }
+ end
+
+ def preferred_language_from(array)
+ (languages & array.collect { |i| i.to_s }).first
+ end
+
+ def nearby(radius = 50, num = 10)
+ if self.home_lon and self.home_lat
+ gc = OSM::GreatCircle.new(self.home_lat, self.home_lon)
+ bounds = gc.bounds(radius)
+ sql_for_distance = gc.sql_for_distance("home_lat", "home_lon")
+ nearby = User.find(:all,
+ :conditions => ["id != ? AND visible = ? AND data_public = ? AND #{sql_for_distance} <= ?", id, true, true, radius], :order => sql_for_distance, :limit => num)
+ else
+ nearby = []
+ end
+ return nearby
+ end
+
+ def distance(nearby_user)
+ return OSM::GreatCircle.new(self.home_lat, self.home_lon).distance(nearby_user.home_lat, nearby_user.home_lon)
+ end
+
+ def is_friends_with?(new_friend)
+ res = false
+ @new_friend = new_friend
+ self.friends.each do |friend|
+ if friend.friend_user_id == @new_friend.id
+ return true
+ end
+ end
+ return false
+ end
+
+ def trace_public_default
+ return self.preferences.find(:first, :conditions => {:k => "gps.trace.public", :v => "default"})
+ end