1 class MapBug < ActiveRecord::Base
 
   4   has_many :map_bug_comment, :foreign_key => :bug_id, :order => :date_created, :conditions => "visible = true and comment is not null"
 
   6   validates_presence_of :id, :on => :update
 
   7   validates_uniqueness_of :id
 
   8   validates_numericality_of :latitude, :only_integer => true
 
   9   validates_numericality_of :longitude, :only_integer => true
 
  10   validates_presence_of :date_created
 
  11   validates_presence_of :last_changed
 
  12   validates_presence_of :date_closed if :status == "closed"
 
  13   validates_inclusion_of :status, :in => ["open", "closed", "hidden"]
 
  15   def self.create_bug(lat, lon)
 
  16     bug = MapBug.new(:lat => lat, :lon => lon)
 
  17     raise OSM::APIBadUserInput.new("The node is outside this world") unless bug.in_world?
 
  19     bug.date_created = Time.now.getutc
 
  20     bug.last_changed = Time.now.getutc
 
  27     self.status = "closed"
 
  28     close_time = Time.now.getutc
 
  29     self.last_changed = close_time
 
  30     self.date_closed = close_time
 
  35   def flatten_comment(separator_char, upto_timestamp = :nil)
 
  38     self.map_bug_comment.each do |comment|
 
  39       next if upto_timestamp != :nil and comment.date_created > upto_timestamp
 
  40       resp += (comment_no == 1 ? "" : separator_char)
 
  41       resp += comment.comment if comment.comment
 
  43       resp += comment.commenter_name if comment.commenter_name
 
  44       resp += " " + comment.date_created.to_s + " ]"
 
  52     return status != "hidden"