diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-02-20 14:50:47 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-02-20 16:39:56 +0000 |
commit | c79b9b54210cc5483bed03783417fbeb6ed422cb (patch) | |
tree | 587cb3eba33f205a0bbe1f5ba3b6bc34bb59c6ed | |
parent | 2e6b053a4b40876b200ccaa5e800168b097a7046 (diff) |
[UK] Output NI grid references to NI councils.
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 24 | ||||
-rw-r--r-- | perllib/Utils.pm | 5 | ||||
-rw-r--r-- | t/app/model/problem.t | 12 |
3 files changed, 27 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 10d395684..cc0cc5242 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -295,16 +295,6 @@ sub send_reports { : _('The user could not locate the problem on a map, but to see the area around the location they entered'); $h{closest_address} = ''; - # If we are in the UK include eastings and northings, and nearest stuff - $h{easting_northing} = ''; - if ( $cobrand->country eq 'GB' ) { - - ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude} ); - - # email templates don't have conditionals so we need to farmat this here - $h{easting_northing} = "Easting/Northing: $h{easting}/$h{northing}\n\n"; - } - if ( $row->used_map ) { $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row ); } @@ -407,6 +397,20 @@ sub send_reports { next; } + # If we are in the UK include eastings and northings, and nearest stuff + $h{easting_northing} = ''; + if ( $cobrand->country eq 'GB' ) { + + my $coordsyst = 'G'; + $coordsyst = 'I' if grep { /FixMyStreet::SendReport::NI/ } keys %reporters; + ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst ); + + # email templates don't have conditionals so we need to format this here + $h{easting_northing} = "Easting/Northing"; + $h{easting_northing} .= " (IE)" if $coordsyst eq 'I'; + $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n"; + } + if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING')) { # on a staging server send emails to ourselves rather than the bodies %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI|EmptyHomes)/ } keys %reporters; diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 87e0bd7c9..243b98800 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -25,12 +25,13 @@ Takes the WGS84 latitude and longitude and returns OSGB36 easting and northing. =cut sub convert_latlon_to_en { - my ( $latitude, $longitude ) = @_; + my ( $latitude, $longitude, $coordsyst ) = @_; + $coordsyst ||= 'G'; local $SIG{__WARN__} = sub { die $_[0] }; my ( $easting, $northing ) = mySociety::Locale::in_gb_locale { - mySociety::GeoUtil::wgs84_to_national_grid( $latitude, $longitude, 'G' ); + mySociety::GeoUtil::wgs84_to_national_grid( $latitude, $longitude, $coordsyst ); }; return ( $easting, $northing ); diff --git a/t/app/model/problem.t b/t/app/model/problem.t index c40e9e022..94ac153d2 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -18,8 +18,8 @@ my $problem_rs = FixMyStreet::App->model('DB::Problem'); my $problem = $problem_rs->new( { postcode => 'EH99 1SP', - latitude => '51.5016605453401', - longitude => '-0.142497580865087', + latitude => '51.5', + longitude => '-0.1', areas => 1, title => '', detail => '', @@ -498,6 +498,7 @@ foreach my $test ( { to => qr'Ballymoney Borough Council', body => $body_ids{14279}, category => 'Graffiti', + longitude => -9.5, }, { %common, desc => 'directs NI correctly, 2', @@ -507,6 +508,7 @@ foreach my $test ( { to => qr'Roads Service \(Western\)" <roads', body => $body_ids{14279}, category => 'Street lighting', + longitude => -9.5, }, { %common, desc => 'does not send to unconfirmed contact', @@ -543,6 +545,7 @@ foreach my $test ( { category => $test->{ category } || 'potholes', name => $test->{ name }, cobrand => $test->{ cobrand } || 'fixmystreet', + longitude => $test->{longitude} || '-0.1', } ); FixMyStreet::override_config $override, sub { @@ -558,6 +561,11 @@ foreach my $test ( { like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report'; like $email->body, qr/Subject: A Title/, 'more email body checking'; like $email->body, $test->{ dear }, 'Salutation looks correct'; + if ($test->{longitude}) { + like $email->body, qr{Easting/Northing \(IE\): 95938/28531}; + } else { + like $email->body, qr{Easting/Northing: }; + } if ( $test->{multiple} ) { like $email->body, qr/This email has been sent to several councils /, 'multiple body text correct'; |