diff options
author | Rikard <rikard@morus.se> | 2012-10-24 08:45:53 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2013-09-05 18:43:51 +0100 |
commit | 865d9f6cada5e5ac437738889fd145825d825e06 (patch) | |
tree | 392c555cb5c371d4fc7f8dbf92279a4af7de5064 /perllib/FixMyStreet/Cobrand/FixaMinGata.pm | |
parent | 991ed7a90e3fbfdab04f06f699bf7587ad858834 (diff) |
Added Swedish locale dir and files, and also the Cobrand FixaMinGata (Swedish version of fixmystreet in the making
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/FixaMinGata.pm')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixaMinGata.pm | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm new file mode 100644 index 000000000..c7d5ea7a1 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm @@ -0,0 +1,260 @@ +package FixMyStreet::Cobrand::FixaMinGata; +use base 'FixMyStreet::Cobrand::Default'; + +use strict; +use warnings; + +use Carp; +use mySociety::MaPit; +use FixMyStreet::Geocode::OSM; + +sub path_to_web_templates { + my $self = shift; + return [ FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify ]; +} + +sub country { + return 'SE'; +} + +sub languages { [ 'en-gb,English,en_GB', 'sv,Swedish,sv_SE' ] } +sub language_override { 'sv' } + +sub enter_postcode_text { + my ( $self ) = @_; + return _('Enter a nearby postcode, or street name and area'); +} + +# Is also adding language parameter +sub disambiguate_location { + return { + lang => 'sv', + country => 'se', # Is this the right format? /Rikard + }; +} + +sub area_types { + [ 'KOM' ]; +} + +sub admin_base_url { + return 'http://www.fixamingata.se/admin/'; +} + +# If lat/lon are present in the URL, OpenLayers will use that to centre the map. +# Need to specify a zoom to stop it defaulting to null/0. +sub uri { + my ( $self, $uri ) = @_; + + $uri->query_param( zoom => 3 ) + if $uri->query_param('lat') && !$uri->query_param('zoom'); + + return $uri; +} + +sub geocode_postcode { + my ( $self, $s ) = @_; + # Most people write Swedish postcodes like this: + #+ XXX XX, so let's remove the space + # Is this the right place to do this? //Rikard + $s =~ s/\ //g; # Rikard, remove space in postcode + if ($s =~ /^\d{5}$/) { + my $location = mySociety::MaPit::call('postcode', $s); + if ($location->{error}) { + return { + error => $location->{code} =~ /^4/ + ? _('That postcode was not recognised, sorry.') + : $location->{error} + }; + } + return { + latitude => $location->{wgs84_lat}, + longitude => $location->{wgs84_lon}, + }; + } + return {}; +} + +# Vad gör den här funktionen? Är "Sverige" rätt här? +sub geocoded_string_check { + my ( $self, $s ) = @_; + return 1 if $s =~ /, Sverige/; + return 0; +} + +sub find_closest { + my ( $self, $latitude, $longitude ) = @_; + return FixMyStreet::Geocode::OSM::closest_road_text( $self, $latitude, $longitude ); +} + +# Used by send-reports, calling find_closest, calling OSM geocoding +sub guess_road_operator { + my ( $self, $inforef ) = @_; + + my $highway = $inforef->{highway} || "unknown"; + my $refs = $inforef->{ref} || "unknown"; + # What should we put in place of "Statens vegvesen"? "Trafikverket" + return "Statens vegvesen" + if $highway eq "trunk" || $highway eq "primary"; + + for my $ref (split(/;/, $refs)) { + return "Statens vegvesen" + if $ref =~ m/E ?\d+/ || $ref =~ m/Fv\d+/i; + } + return ''; +} + +sub remove_redundant_councils { + my $self = shift; + my $all_councils = shift; + + # Oslo is both a kommune and a fylke, we only want to show it once + # Jag tror inte detta är applicerbart på Sverige ;-) //Rikard + #delete $all_councils->{301} # + # if $all_councils->{3}; +} + +sub filter_all_council_ids_list { + my $self = shift; + my @all_councils_ids = @_; + + # as above we only want to show Oslo once + # Rikard kommenterar ut detta. + # return grep { $_ != 301 } @all_councils_ids; + # Rikard: + return @all_councils_ids; # Är detta rätt? //Rikard +} + +sub short_name { + my $self = shift; + my ($area, $info) = @_; + + # Rikard kommenterar ut följande tills vidare... + #if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) { + # my $parent = $info->{$area->{parent_area}}->{name}; + # return URI::Escape::uri_escape_utf8("$area->{name}, $parent"); + #} + + my $name = $area->{name}; + $name =~ s/ & / and /; + $name = URI::Escape::uri_escape_utf8($name); + $name =~ s/%20/+/g; + return $name; +} + +# Vad ska vi göra för svenska förhållanden här??? //Rikard +sub council_rss_alert_options { + my $self = shift; + my $all_councils = shift; + my $c = shift; + + my ( @options, @reported_to_options, $fylke, $kommune ); + + foreach ( values %$all_councils ) { + if ( $_->{type} eq 'NKO' ) { + $kommune = $_; + } + else { + $fylke = $_; + } + } + + if ( $fylke->{id} == 3 ) { # Oslo + my $short_name = $self->short_name($fylke, $all_councils); + ( my $id_name = $short_name ) =~ tr/+/_/; + + push @options, + { + type => 'council', + id => sprintf( 'council:%s:%s', $fylke->{id}, $id_name ), + rss_text => + sprintf( _('RSS feed of problems within %s'), $fylke->{name} ), + text => sprintf( _('Problems within %s'), $fylke->{name} ), + uri => $c->uri_for( '/rss/reports', $short_name ), + }; + } + else { + my $short_kommune_name = $self->short_name($kommune, $all_councils); + ( my $id_kommune_name = $short_kommune_name ) =~ tr/+/_/; + + my $short_fylke_name = $self->short_name($fylke, $all_councils); + ( my $id_fylke_name = $short_fylke_name ) =~ tr/+/_/; + + push @options, + { + type => 'area', + id => sprintf( 'area:%s:%s', $kommune->{id}, $id_kommune_name ), + rss_text => + sprintf( _('RSS feed of %s'), $kommune->{name} ), + text => $kommune->{name}, + uri => $c->uri_for( '/rss/area', $short_kommune_name ), + }, + { + type => 'area', + id => sprintf( 'area:%s:%s', $fylke->{id}, $id_fylke_name ), + rss_text => + sprintf( _('RSS feed of %s'), $fylke->{name} ), + text => $fylke->{name}, + uri => $c->uri_for( '/rss/area', $short_fylke_name ), + }; + + push @reported_to_options, + { + type => 'council', + id => sprintf( 'council:%s:%s', $kommune->{id}, $id_kommune_name ), + rss_text => + sprintf( _('RSS feed of %s'), $kommune->{name} ), + text => $kommune->{name}, + uri => $c->uri_for( '/rss/reports', $short_kommune_name ), + }, + { + type => 'council', + id => sprintf( 'council:%s:%s', $fylke->{id}, $id_fylke_name ), + rss_text => + sprintf( _('RSS feed of %s'), $fylke->{name} ), + text => $fylke->{name}, + uri => $c->uri_for( '/rss/reports/', $short_fylke_name ), + }; + } + + return ( + \@options, @reported_to_options + ? \@reported_to_options + : undef + ); + +} + +# Vad ska vi göra för svenska förhållanden här??? //Rikard +sub reports_council_check { + my ( $self, $c, $council ) = @_; + + if ($council eq 'Oslo') { + + # There are two Oslos (kommune and fylke), we only want one of them. + $c->stash->{council} = mySociety::MaPit::call('area', 3); + return 1; + + } elsif ($council =~ /,/) { + + # Some kommunes have the same name, use the fylke name to work out which. + my ($kommune, $fylke) = split /\s*,\s*/, $council; + my $area_types = $c->cobrand->area_types; + my $areas_k = mySociety::MaPit::call('areas', $kommune, type => $area_types); + my $areas_f = mySociety::MaPit::call('areas', $fylke, type => $area_types); + if (keys %$areas_f == 1) { + ($fylke) = values %$areas_f; + foreach (values %$areas_k) { + if ($_->{name} eq $kommune && $_->{parent_area} == $fylke->{id}) { + $c->stash->{council} = $_; + return 1; + } + } + } + # If we're here, we've been given a bad name. + $c->detach( 'redirect_index' ); + + } +} + +1; |