diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Council.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 76 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 48 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 131 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/Bing.pm | 2 |
6 files changed, 152 insertions, 131 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index 771603c22..b513ac930 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -23,7 +23,7 @@ there are no councils then return false. sub load_and_check_councils_and_wards : Private { my ( $self, $c ) = @_; - my @area_types = ( $c->cobrand->area_types(), @$mySociety::VotingArea::council_child_types ); + my @area_types = ( $c->cobrand->area_types(), $c->cobrand->area_types_children() ); $c->stash->{area_types} = \@area_types; $c->forward('load_and_check_councils'); } @@ -69,6 +69,10 @@ sub load_and_check_councils : Private { mySociety::MaPit::call( 'point', "4326/$short_longitude,$short_latitude", type => \@area_types ); } + if ($all_councils->{error}) { + $c->stash->{location_error} = $all_councils->{error}; + return; + } # Let cobrand do a check my ( $success, $error_msg ) = diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 4ff0b922b..fc195432d 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -14,11 +14,12 @@ use mySociety::PostcodeUtil; =head1 country Returns the country that this cobrand operates in, as an ISO3166-alpha2 code. +Default is none. =cut sub country { - return 'GB'; + return ''; } =head1 problems_clause @@ -237,17 +238,11 @@ sub front_stats_data { =head2 disambiguate_location -Returns disambiguating information available +Returns any disambiguating information available. Defaults to none. =cut -sub disambiguate_location { - return { - country => 'uk', - bing_culture => 'en-GB', - bing_country => 'United Kingdom' - }; -} +sub disambiguate_location { return {}; } =head2 cobrand_data_for_generic_update @@ -417,7 +412,7 @@ adverts =cut -sub allow_crosssell_adverts { return 1; } +sub allow_crosssell_adverts { return 0; } =head2 allow_photo_display @@ -444,35 +439,6 @@ Given a QUERY, return LAT/LON and/or ERROR. sub geocode_postcode { my ( $self, $s ) = @_; - - if ($s =~ /^\d+$/) { - return { - error => 'FixMyStreet is a UK-based website that currently works in England, Scotland, and Wales. Please enter either a postcode, or a Great British street name and area.' - }; - } elsif (mySociety::PostcodeUtil::is_valid_postcode($s)) { - my $location = mySociety::MaPit::call('postcode', $s); - if ($location->{error}) { - return { - error => $location->{code} =~ /^4/ - ? _('That postcode was not recognised, sorry.') - : $location->{error} - }; - } - my $island = $location->{coordsyst}; - if (!$island) { - return { - error => _("Sorry, that appears to be a Crown dependency postcode, which we don't cover.") - }; - } elsif ($island eq 'I') { - return { - error => _("We do not currently cover Northern Ireland, I'm afraid.") - }; - } - return { - latitude => $location->{wgs84_lat}, - longitude => $location->{wgs84_lon}, - }; - } return {}; } @@ -642,6 +608,7 @@ The MaPit types this site handles =cut sub area_types { qw(ZZZ) } +sub area_types_children { qw() } sub area_min_generation { '' } =head2 contact_name, contact_email @@ -707,16 +674,6 @@ Remove councils whose reports go to another council sub remove_redundant_councils { my $self = shift; my $all_councils = shift; - - # Ipswich & St Edmundsbury are responsible for everything in their - # areas, not Suffolk - delete $all_councils->{2241} - if $all_councils->{2446} # - || $all_councils->{2443}; - - # Norwich is responsible for everything in its areas, not Norfolk - delete $all_councils->{2233} # - if $all_councils->{2391}; } =item filter_all_council_ids_list @@ -738,21 +695,12 @@ Remove extra information from council names for tidy URIs =cut sub short_name { - my $self = shift; - my ($area, $info) = @_; - # Special case Durham as it's the only place with two councils of the same name - return 'Durham+County' if $area->{name} eq 'Durham County Council'; - return 'Durham+City' if $area->{name} eq 'Durham City Council'; - - my $name = $area->{name}; - $name =~ s/ (Borough|City|District|County) Council$//; - $name =~ s/ Council$//; - $name =~ s/ & / and /; - $name =~ s{/}{_}g; - $name = URI::Escape::uri_escape_utf8($name); - $name =~ s/%20/+/g; - return $name; - + my $self = shift; + my ($area, $info) = @_; + my $name = $area->{name}; + $name = URI::Escape::uri_escape_utf8($name); + $name =~ s/%20/+/g; + return $name; } =item is_council diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index d838ec84b..d44c58f37 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -1,8 +1,5 @@ package FixMyStreet::Cobrand::FixMyStreet; -use base 'FixMyStreet::Cobrand::Default'; - -sub area_types { return qw(DIS LBO MTD UTA CTY COI); } -sub area_min_generation { 10 } +use base 'FixMyStreet::Cobrand::UK'; # FixMyStreet should return all cobrands sub restriction { @@ -13,21 +10,6 @@ sub admin_base_url { return 'https://secure.mysociety.org/admin/bci/'; } -sub get_council_sender { - my ( $self, $area_id, $area_info ) = @_; - - my $send_method; - - my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; - $send_method = $council_config->send_method if $council_config; - - return $send_method if $send_method; - - return 'London' if $area_info->{type} eq 'LBO'; - - return 'Email'; -} - sub all_reports_style { return 'detailed'; } sub generate_problem_banner { @@ -56,33 +38,7 @@ sub generate_problem_banner { return $banner; } -sub process_extras { - my $self = shift; - my $ctx = shift; - my $area_id = shift; - my $extra = shift; - my $fields = shift || []; - - if ( $area_id == 2482 ) { - my @fields = ( 'fms_extra_title', @$fields ); - for my $field ( @fields ) { - my $value = $ctx->request->param( $field ); +sub allow_crosssell_adverts { return 1; } - if ( !$value ) { - $ctx->stash->{field_errors}->{ $field } = _('This information is required'); - } - push @$extra, { - name => $field, - description => uc( $field), - value => $value || '', - }; - } - - if ( $ctx->request->param('fms_extra_title') ) { - $ctx->stash->{fms_extra_title} = $ctx->request->param('fms_extra_title'); - $ctx->stash->{extra_name_info} = 1; - } - } -} 1; diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm new file mode 100644 index 000000000..f160d193e --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -0,0 +1,131 @@ +package FixMyStreet::Cobrand::UK; +use base 'FixMyStreet::Cobrand::Default'; + +use mySociety::VotingArea; + +sub country { return 'GB'; } +sub area_types { return qw(DIS LBO MTD UTA CTY COI); } +sub area_types_children { return @$mySociety::VotingArea::council_child_types } +sub area_min_generation { 10 } + +sub disambiguate_location { + return { + country => 'uk', + bing_culture => 'en-GB', + bing_country => 'United Kingdom' + }; +} + +sub get_council_sender { + my ( $self, $area_id, $area_info ) = @_; + + my $send_method; + + my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; + $send_method = $council_config->send_method if $council_config; + + return $send_method if $send_method; + + return 'London' if $area_info->{type} eq 'LBO'; + + return 'Email'; +} + +sub process_extras { + my $self = shift; + my $ctx = shift; + my $area_id = shift; + my $extra = shift; + my $fields = shift || []; + + if ( $area_id == 2482 ) { + my @fields = ( 'fms_extra_title', @$fields ); + for my $field ( @fields ) { + my $value = $ctx->request->param( $field ); + + if ( !$value ) { + $ctx->stash->{field_errors}->{ $field } = _('This information is required'); + } + push @$extra, { + name => $field, + description => uc( $field), + value => $value || '', + }; + } + + if ( $ctx->request->param('fms_extra_title') ) { + $ctx->stash->{fms_extra_title} = $ctx->request->param('fms_extra_title'); + $ctx->stash->{extra_name_info} = 1; + } + } +} + +sub geocode_postcode { + my ( $self, $s ) = @_; + + if ($s =~ /^\d+$/) { + return { + error => 'FixMyStreet is a UK-based website that currently works in England, Scotland, and Wales. Please enter either a postcode, or a Great British street name and area.' + }; + } elsif (mySociety::PostcodeUtil::is_valid_postcode($s)) { + my $location = mySociety::MaPit::call('postcode', $s); + if ($location->{error}) { + return { + error => $location->{code} =~ /^4/ + ? _('That postcode was not recognised, sorry.') + : $location->{error} + }; + } + my $island = $location->{coordsyst}; + if (!$island) { + return { + error => _("Sorry, that appears to be a Crown dependency postcode, which we don't cover.") + }; + } elsif ($island eq 'I') { + return { + error => _("We do not currently cover Northern Ireland, I'm afraid.") + }; + } + return { + latitude => $location->{wgs84_lat}, + longitude => $location->{wgs84_lon}, + }; + } + return {}; +} + +sub remove_redundant_councils { + my $self = shift; + my $all_councils = shift; + + # Ipswich & St Edmundsbury are responsible for everything in their + # areas, not Suffolk + delete $all_councils->{2241} + if $all_councils->{2446} # + || $all_councils->{2443}; + + # Norwich is responsible for everything in its areas, not Norfolk + delete $all_councils->{2233} # + if $all_councils->{2391}; +} + +sub short_name { + my $self = shift; + my ($area, $info) = @_; + # Special case Durham as it's the only place with two councils of the same name + return 'Durham+County' if $area->{name} eq 'Durham County Council'; + return 'Durham+City' if $area->{name} eq 'Durham City Council'; + + my $name = $area->{name}; + $name =~ s/ (Borough|City|District|County) Council$//; + $name =~ s/ Council$//; + $name =~ s/ & / and /; + $name =~ s{/}{_}g; + $name = URI::Escape::uri_escape_utf8($name); + $name =~ s/%20/+/g; + return $name; + +} + +1; + diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 82cf3f343..23f84e76f 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -1,5 +1,5 @@ package FixMyStreet::Cobrand::UKCouncils; -use base 'FixMyStreet::Cobrand::Default'; +use base 'FixMyStreet::Cobrand::UK'; use strict; use warnings; @@ -7,9 +7,6 @@ use warnings; use Carp; use URI::Escape; -sub area_types { return qw(DIS LBO MTD UTA CTY COI); } -sub area_min_generation { 10 } - sub is_council { 1; } @@ -94,19 +91,4 @@ sub recent_photos { return $self->problems->recent_photos( $num, $lat, $lon, $dist ); } -sub get_council_sender { - my ( $self, $area_id, $area_info ) = @_; - - my $send_method; - - my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; - $send_method = $council_config->send_method if $council_config; - - return $send_method if $send_method; - - return 'London' if $area_info->{type} eq 'LBO'; - - return 'Email'; -} - 1; diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 3bbb9dcdc..148ad5f43 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -56,7 +56,7 @@ sub string { foreach (@$results) { my $address = $_->{name}; - next unless $_->{address}->{countryRegion} eq $params->{bing_country}; + next if $params->{bing_country} && $_->{address}->{countryRegion} ne $params->{bing_country}; if ($params->{bing_country} eq 'United Kingdom' && $_->{address}{adminDistrict} eq 'Northern Ireland') { $ni = 1; next; |