use boolean flags when using boolean columns

This commit is contained in:
Andy Allan 2008-11-07 13:24:18 +00:00
parent 1140237cae
commit 7058d836f7
10 changed files with 24 additions and 24 deletions

View file

@ -120,7 +120,7 @@ class ApiController < ApplicationController
end
# FIXME um why is this area using a different order for the lat/lon from above???
@nodes = Node.find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => "visible = 1", :limit => APP_CONFIG['max_number_of_nodes']+1)
@nodes = Node.find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => {:visible => true}, :limit => APP_CONFIG['max_number_of_nodes']+1)
# get all the nodes, by tag not yet working, waiting for change from NickB
# need to be @nodes (instance var) so tests in /spec can be performed
#@nodes = Node.search(bbox, params[:tag])
@ -187,15 +187,15 @@ class ApiController < ApplicationController
end
end
relations = Relation.find_for_nodes(visible_nodes.keys, :conditions => "visible = 1") +
Relation.find_for_ways(way_ids, :conditions => "visible = 1")
relations = Relation.find_for_nodes(visible_nodes.keys, :conditions => {:visible => true}) +
Relation.find_for_ways(way_ids, :conditions => {:visible => true})
# we do not normally return the "other" partners referenced by an relation,
# e.g. if we return a way A that is referenced by relation X, and there's
# another way B also referenced, that is not returned. But we do make
# an exception for cases where an relation references another *relation*;
# in that case we return that as well (but we don't go recursive here)
relations += Relation.find_for_relations(relations.collect { |r| r.id }, :conditions => "visible = 1")
relations += Relation.find_for_relations(relations.collect { |r| r.id }, :conditions => {:visible => true})
# this "uniq" may be slightly inefficient; it may be better to first collect and output
# all node-related relations, then find the *not yet covered* way-related ones etc.

View file

@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
def authorize_web
if session[:user]
@user = User.find(session[:user], :conditions => "visible = 1")
@user = User.find(session[:user], :conditions => {:visible => true})
elsif session[:token]
@user = User.authenticate(:token => session[:token])
session[:user] = @user.id

View file

@ -54,7 +54,7 @@ class DiaryEntryController < ApplicationController
def list
if params[:display_name]
@this_user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
@this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
if @this_user
@title = @this_user.display_name + "'s diary"
@ -77,7 +77,7 @@ class DiaryEntryController < ApplicationController
def rss
if params[:display_name]
user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
if user
@entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
@ -100,7 +100,7 @@ class DiaryEntryController < ApplicationController
end
def view
user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
if user
@entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])

View file

@ -12,7 +12,7 @@ class TraceController < ApplicationController
# from display name, pick up user id if one user's traces only
display_name = params[:display_name]
if target_user.nil? and !display_name.blank?
target_user = User.find(:first, :conditions => [ "visible = 1 and display_name = ?", display_name])
target_user = User.find(:first, :conditions => [ "visible = ? and display_name = ?", true, display_name])
end
# set title
@ -33,15 +33,15 @@ class TraceController < ApplicationController
# 4 - user's traces, not logged in as that user = all user's public traces
if target_user.nil? # all traces
if @user
conditions = ["(gpx_files.public = 1 OR gpx_files.user_id = ?)", @user.id] #1
conditions = ["(gpx_files.public = ? OR gpx_files.user_id = ?)", true, @user.id] #1
else
conditions = ["gpx_files.public = 1"] #2
conditions = ["gpx_files.public = ?", true] #2
end
else
if @user and @user == target_user
conditions = ["gpx_files.user_id = ?", @user.id] #3 (check vs user id, so no join + can't pick up non-public traces by changing name)
else
conditions = ["gpx_files.public = 1 AND gpx_files.user_id = ?", target_user.id] #4
conditions = ["gpx_files.public = ? AND gpx_files.user_id = ?", true, target_user.id] #4
end
end
@ -51,7 +51,7 @@ class TraceController < ApplicationController
conditions << @tag
end
conditions[0] += " AND gpx_files.visible = 1"
conditions[0] += " AND gpx_files.visible = 1" #FIXME: use boolean true as parameter to active record
@trace_pages, @traces = paginate(:traces,
:include => [:user, :tags],

View file

@ -76,7 +76,7 @@ class UserController < ApplicationController
def lost_password
@title = 'lost password'
if params[:user] and params[:user][:email]
user = User.find_by_email(params[:user][:email], :conditions => "visible = 1")
user = User.find_by_email(params[:user][:email], :conditions => {:visible => true})
if user
token = user.tokens.create
@ -216,7 +216,7 @@ class UserController < ApplicationController
end
def view
@this_user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
@this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
if @this_user
@title = @this_user.display_name
@ -229,7 +229,7 @@ class UserController < ApplicationController
def make_friend
if params[:display_name]
name = params[:display_name]
new_friend = User.find_by_display_name(name, :conditions => "visible = 1")
new_friend = User.find_by_display_name(name, :conditions => {:visible => true})
friend = Friend.new
friend.user_id = @user.id
friend.friend_user_id = new_friend.id
@ -251,7 +251,7 @@ class UserController < ApplicationController
def remove_friend
if params[:display_name]
name = params[:display_name]
friend = User.find_by_display_name(name, :conditions => "visible = 1")
friend = User.find_by_display_name(name, :conditions => {:visible => true})
if @user.is_friends_with?(friend)
Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
flash[:notice] = "#{friend.display_name} was removed from your friends."

View file

@ -87,7 +87,7 @@ class WayController < ApplicationController
if way.visible
nd_ids = way.nds + [-1]
nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
nodes = Node.find(:all, :conditions => ["visible = ? AND id IN (#{nd_ids.join(',')})", true])
# Render
doc = OSM::API.new.get_xml_doc

View file

@ -53,7 +53,7 @@ class Node < ActiveRecord::Base
#conditions = keys.join(' AND ')
find_by_area(min_lat, min_lon, max_lat, max_lon,
:conditions => 'visible = 1',
:conditions => {:visible => true},
:limit => APP_CONFIG['max_number_of_nodes']+1)
end
@ -150,9 +150,9 @@ class Node < ActiveRecord::Base
def delete_with_history!(new_node, user)
if self.visible
check_consistency(self, new_node, user)
if WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", :conditions => [ "current_ways.visible = 1 AND current_way_nodes.node_id = ?", self.id ])
if WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", :conditions => [ "current_ways.visible = ? AND current_way_nodes.node_id = ?", true, self.id ])
raise OSM::APIPreconditionFailedError.new
elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='node' and member_id=? ", self.id])
elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='node' and member_id=? ", true, self.id])
raise OSM::APIPreconditionFailedError.new
else
self.changeset_id = new_node.changeset_id

View file

@ -322,7 +322,7 @@ class Relation < ActiveRecord::Base
def delete_with_history!(new_relation, user)
if self.visible
check_consistency(self, new_relation, user)
if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='relation' and member_id=? ", self.id ])
if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='relation' and member_id=? ", true, self.id ])
raise OSM::APIPreconditionFailedError.new
else
self.changeset_id = new_relation.changeset_id

View file

@ -81,7 +81,7 @@ class User < ActiveRecord::Base
if self.home_lon and self.home_lat
gc = OSM::GreatCircle.new(self.home_lat, self.home_lon)
bounds = gc.bounds(radius)
nearby = User.find(:all, :conditions => "visible = 1 and home_lat between #{bounds[:minlat]} and #{bounds[:maxlat]} and home_lon between #{bounds[:minlon]} and #{bounds[:maxlon]} and data_public = 1 and id != #{self.id}")
nearby = User.find(:all, :conditions => ["visible = ? and home_lat between #{bounds[:minlat]} and #{bounds[:maxlat]} and home_lon between #{bounds[:minlon]} and #{bounds[:maxlon]} and data_public = ? and id != #{self.id}", true, true])
nearby.delete_if { |u| gc.distance(u.home_lat, u.home_lon) > radius }
nearby.sort! { |u1,u2| gc.distance(u1.home_lat, u1.home_lon) <=> gc.distance(u2.home_lat, u2.home_lon) }
else

View file

@ -274,7 +274,7 @@ class Way < ActiveRecord::Base
check_consistency(self, new_way, user)
if self.visible
if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id",
:conditions => [ "visible = 1 AND member_type='way' and member_id=? ", self.id])
:conditions => [ "visible = ? AND member_type='way' and member_id=? ", true, self.id])
raise OSM::APIPreconditionFailedError
else
self.changeset_id = new_way.changeset_id