X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/8c5638d6968be3286414f04b8dee2261ada84e76..8a57904398175d9143cec737282f5066793bdbc3:/app/models/changeset.rb diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 85621dce2..446ca351d 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -4,6 +4,23 @@ class Changeset < ActiveRecord::Base belongs_to :user has_many :changeset_tags, :foreign_key => 'id' + + has_many :nodes + has_many :ways + has_many :relations + has_many :old_nodes + has_many :old_ways + has_many :old_relations + + validates_presence_of :user_id, :created_at + validates_inclusion_of :open, :in => [ true, false ] + + # Use a method like this, so that we can easily change how we + # determine whether a changeset is open, without breaking code in at + # least 6 controllers + def is_open? + return open + end def self.from_xml(xml, create=false) begin @@ -23,13 +40,16 @@ class Changeset < ActiveRecord::Base end end rescue Exception => ex - print "noes "+ ex.to_s + "\n" cs = nil end return cs end + def tags_as_hash + return tags + end + def tags unless @tags @tags = {} @@ -54,6 +74,7 @@ class Changeset < ActiveRecord::Base Changeset.transaction do # fixme update modified_at time? + # FIXME there is no modified_at time, should it be added self.save! end @@ -70,4 +91,43 @@ class Changeset < ActiveRecord::Base end end end + + def to_xml + doc = OSM::API.new.get_xml_doc + doc.root << to_xml_node() + return doc + end + + def to_xml_node(user_display_name_cache = nil) + el1 = XML::Node.new 'changeset' + el1['id'] = self.id.to_s + + user_display_name_cache = {} if user_display_name_cache.nil? + + if user_display_name_cache and user_display_name_cache.key?(self.user_id) + # use the cache if available + elsif self.user.data_public? + user_display_name_cache[self.user_id] = self.user.display_name + else + user_display_name_cache[self.user_id] = nil + end + + el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil? + + self.tags.each do |k,v| + el2 = XML::Node.new('tag') + el2['k'] = k.to_s + el2['v'] = v.to_s + el1 << el2 + end + + el1['created_at'] = self.created_at.xmlschema + el1['open'] = self.open.to_s + + # FIXME FIXME FIXME: This does not include changes yet! There is + # currently no changeset_id column in the tables as far as I can tell, + # so this is just a scaffold to build on, not a complete to_xml + + return el1 + end end