aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/info_request.rb2
-rw-r--r--app/models/public_body.rb64
-rw-r--r--app/models/public_body_tag.rb48
3 files changed, 5 insertions, 109 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 4f997baa6..3f5224907 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -50,6 +50,8 @@ class InfoRequest < ActiveRecord::Base
has_many :censor_rules, :order => 'created_at desc'
has_many :exim_logs, :order => 'exim_log_done_id'
+ has_tag_string
+
# user described state (also update in info_request_event, admin_request/edit.rhtml)
validates_inclusion_of :described_state, :in => [
'waiting_response',
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index d54c761e6..1bd9dcc94 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -40,9 +40,10 @@ class PublicBody < ActiveRecord::Base
validates_uniqueness_of :name
has_many :info_requests, :order => 'created_at desc'
- has_many :public_body_tags
has_many :track_things, :order => 'created_at desc'
+ has_tag_string
+
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
found = PublicBody.find_all_by_url_name(name)
@@ -183,71 +184,12 @@ class PublicBody < ActiveRecord::Base
end
end
- # Given an input string of tags, sets all tags to that string.
- # XXX This immediately saves the new tags.
- def tag_string=(tag_string)
- tag_string = tag_string.strip
- # split tags apart
- tags = tag_string.split(/\s+/).uniq
-
- ActiveRecord::Base.transaction do
- for public_body_tag in self.public_body_tags
- public_body_tag.destroy
- end
- self.public_body_tags = []
- for tag in tags
- # see if is a machine tags (i.e. a tag which has a value)
- name, value = PublicBodyTag.split_tag_into_name_value(tag)
-
- public_body_tag = PublicBodyTag.new(:name => name, :value => value)
- self.public_body_tags << public_body_tag
- public_body_tag.public_body = self
- end
- end
- end
- def tag_string
- return self.public_body_tags.map { |t| t.name_and_value }.join(' ')
- end
- def has_tag?(tag)
- for public_body_tag in self.public_body_tags
- if public_body_tag.name == tag
- return true
- end
- end
- return false
- end
- class TagNotFound < StandardError
- end
- def get_tag_values(tag)
- found = false
- results = []
- for public_body_tag in self.public_body_tags
- if public_body_tag.name == tag
- found = true
- if !public_body_tag.value.nil?
- results << public_body_tag.value
- end
- end
- end
- if !found
- raise TagNotFound
- end
- return results
- end
- def add_tag_if_not_already_present(tag)
- self.tag_string = self.tag_string + " " + tag
- end
-
- # Find all public bodies with a particular tag
- def self.find_by_tag(tag)
- return PublicBodyTag.find(:all, :conditions => ['name = ?', tag] ).map { |t| t.public_body }.sort { |a,b| a.name <=> b.name }
- end
# Use tags to describe what type of thing this is
def type_of_authority(html = false)
types = []
first = true
- for tag in self.public_body_tags
+ for tag in self.tags
if PublicBodyCategories::CATEGORIES_BY_TAG.include?(tag.name)
desc = PublicBodyCategories::CATEGORY_SINGULAR_BY_TAG[tag.name]
if first
diff --git a/app/models/public_body_tag.rb b/app/models/public_body_tag.rb
deleted file mode 100644
index e24ace7d7..000000000
--- a/app/models/public_body_tag.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# == Schema Information
-# Schema version: 92
-#
-# Table name: public_body_tags
-#
-# id :integer not null, primary key
-# public_body_id :integer not null
-# name :text not null
-# created_at :datetime not null
-# value :text
-#
-
-# models/public_body_tag.rb:
-# Categories for public bodies.
-#
-# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
-# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: public_body_tag.rb,v 1.29 2009-09-17 21:10:05 francis Exp $
-
-class PublicBodyTag < ActiveRecord::Base
- strip_attributes!
-
- validates_presence_of :public_body
- validates_presence_of :name
-
- belongs_to :public_body
-
- def name_and_value
- ret = self.name
- if !self.value.nil?
- ret += ":" + self.value
- end
- return ret
- end
-
- def PublicBodyTag.split_tag_into_name_value(tag)
- sections = tag.split(/:/)
- name = sections[0]
- if sections[1]
- value = sections[1,sections.size].join(":")
- else
- value = nil
- end
- return name, value
- end
-end
-