aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/public_body_helper.rb
blob: 57c90a9bac91eabe88e33801113151c338aa0d39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module PublicBodyHelper

  # Public: The reasons a request can't be made to a PublicBody
  # The returned reasons are ordered by priority. For example, if the body no
  # longer exists there is no reason to ask for its contact details if we don't
  # have an email for it.
  #
  # public_body - Instance of a PublicBody
  #
  # Returns an Array
  def public_body_not_requestable_reasons(public_body)
    reasons = []

    if public_body.defunct?
      reasons.push _('This authority no longer exists, so you cannot make a request to it.')
    end

    if public_body.not_apply?
      reasons.push _('Freedom of Information law does not apply to this authority, so you cannot make a request to it.')
    end

    unless public_body.has_request_email?
      # Make the authority appear requestable to encourage users to help find
      # the authority's email address
      msg = link_to _("Make a request to this authority"),
                      new_request_to_body_path(:url_name => public_body.url_name),
                      :class => "link_button_green"

      reasons.push(msg)
    end

    reasons.compact
  end

  # Use tags to describe what type of authority a PublicBody is.
  #
  # public_body - Instance of a PublicBody
  #
  # Returns a string
  def type_of_authority(public_body)
      first = true
      types = public_body.tags.each.map do |tag|
          if PublicBodyCategory.get().by_tag().include?(tag.name)
              desc = PublicBodyCategory.get().singular_by_tag()[tag.name]
              if first
                  desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
                  first = false
              end
              link_to(desc, list_public_bodies_path(tag.name))
          end
      end

      types.compact!

      if types.any?
          types.to_sentence(:last_word_connector => ' and ').html_safe
      else
          _("A public authority")
      end
  end

end