aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/general_controller.rb21
-rw-r--r--app/models/public_body.rb23
-rw-r--r--app/views/general/_frontpage_bodies_list.html.erb5
3 files changed, 26 insertions, 23 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index beefef4e6..e138ec120 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -12,28 +12,7 @@ class GeneralController < ApplicationController
# New, improved front page!
def frontpage
medium_cache
- # get some example searches and public bodies to display
- # either from config, or based on a (slow!) query if not set
- body_short_names = AlaveteliConfiguration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ")
@locale = self.locale_from_params()
- locale_condition = 'public_body_translations.locale = ?'
- conditions = [locale_condition, @locale]
- I18n.with_locale(@locale) do
- if body_short_names.empty?
- # This is too slow
- @popular_bodies = PublicBody.visible.find(:all,
- :order => "info_requests_count desc",
- :limit => 32,
- :conditions => conditions,
- :joins => :translations
- )
- else
- conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")"
- @popular_bodies = PublicBody.find(:all,
- :conditions => conditions,
- :joins => :translations)
- end
- end
# Get some successful requests
begin
query = 'variety:response (status:successful OR status:partially_successful)'
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index db6359f6b..4b19ec95e 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -723,6 +723,29 @@ class PublicBody < ActiveRecord::Base
'y_max' => 100,
'totals' => original_totals}
end
+ def self.popular_bodies(locale)
+ # get some example searches and public bodies to display
+ # either from config, or based on a (slow!) query if not set
+ body_short_names = AlaveteliConfiguration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ")
+ locale_condition = 'public_body_translations.locale = ?'
+ conditions = [locale_condition, locale]
+ bodies = []
+ I18n.with_locale(locale) do
+ if body_short_names.empty?
+ # This is too slow
+ bodies = visible.find(:all,
+ :order => "info_requests_count desc",
+ :limit => 32,
+ :conditions => conditions,
+ :joins => :translations
+ )
+ else
+ conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")"
+ bodies = find(:all, :conditions => conditions, :joins => :translations)
+ end
+ end
+ return bodies
+ end
private
diff --git a/app/views/general/_frontpage_bodies_list.html.erb b/app/views/general/_frontpage_bodies_list.html.erb
index 75daea41d..44321f14a 100644
--- a/app/views/general/_frontpage_bodies_list.html.erb
+++ b/app/views/general/_frontpage_bodies_list.html.erb
@@ -1,10 +1,11 @@
-<% if @popular_bodies.size > 0 %>
+<%- popular_bodies = PublicBody.popular_bodies(@locale) %>
+<% if popular_bodies.size > 0 %>
<div id="examples_0">
<h3><%= _("Who can I request information from?") %></h3>
<%= _("{{site_name}} covers requests to {{number_of_authorities}} authorities, including:",
:site_name => site_name, :number_of_authorities => PublicBody.visible.count) %>
<ul>
- <% for popular_body in @popular_bodies %>
+ <% for popular_body in popular_bodies %>
<li><%=public_body_link(popular_body)%>
<%= n_('{{count}} request', '{{count}} requests', popular_body.info_requests_count, :count => popular_body.info_requests_count) %>
</li>