|
|
@ -12,6 +12,9 @@ class OrganizationsController < ApplicationController |
|
|
|
|
|
|
|
# GET /organizations/1 |
|
|
|
def show |
|
|
|
if params[:slug] == 'json' |
|
|
|
json |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
# GET /organizations/new |
|
|
@ -81,6 +84,54 @@ class OrganizationsController < ApplicationController |
|
|
|
set_organization |
|
|
|
end |
|
|
|
|
|
|
|
def json |
|
|
|
orgs = Hash.new |
|
|
|
order = 0 |
|
|
|
countries = Hash.new |
|
|
|
Organization.find(:all, :joins => :locations, :order => 'locations.latitude').each { |org| |
|
|
|
location = org.locations.first |
|
|
|
if !orgs.has_key?(location.country.downcase) |
|
|
|
orgs[location.country.downcase] = Hash.new |
|
|
|
countries[location.country.downcase] = { :country => Carmen::Country.coded(location.country), :territories => Hash.new } |
|
|
|
end |
|
|
|
country = countries[location.country.downcase][:country] |
|
|
|
if !orgs[location.country.downcase].has_key?(location.territory.downcase) |
|
|
|
orgs[location.country.downcase][location.territory.downcase] = Hash.new |
|
|
|
countries[location.country.downcase][:territories][location.territory.downcase] = country.subregions.coded(location.territory) |
|
|
|
end |
|
|
|
territory = countries[location.country.downcase][:territories][location.territory.downcase] |
|
|
|
if !orgs[location.country.downcase][location.territory.downcase].has_key?(location.territory.downcase) |
|
|
|
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase] = Hash.new |
|
|
|
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:latitude] = location.latitude |
|
|
|
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:longitude] = location.longitude |
|
|
|
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:count] = 0 |
|
|
|
end |
|
|
|
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][orgs[location.country.downcase][location.territory.downcase][location.territory.downcase]['count']] = { |
|
|
|
:title => org.name, |
|
|
|
:id => org.id, |
|
|
|
:logo => org.avatar.url(:thumb), |
|
|
|
:logo_large => org.avatar.url, |
|
|
|
:location => { |
|
|
|
:street => location.street, |
|
|
|
:city => location.city, |
|
|
|
:province => location.territory, |
|
|
|
:country => country.name, |
|
|
|
:province_name => territory ? territory.name : nil, |
|
|
|
:country_name => country.name, |
|
|
|
:latitude => location.latitude, |
|
|
|
:longitude => location.longitude |
|
|
|
}, |
|
|
|
:website => org.url, |
|
|
|
:year_founded => org.year_founded, |
|
|
|
:url => url_for(org), |
|
|
|
:order => order |
|
|
|
} |
|
|
|
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:count] += 1 |
|
|
|
order += 1 |
|
|
|
} |
|
|
|
render :json => orgs.to_json |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
|
# Use callbacks to share common setup or constraints between actions. |
|
|
|
def set_organization |
|
|
|