aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm29
1 files changed, 28 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index c1a5d65c9..e387f3105 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -9,6 +9,8 @@ use mySociety::EmailUtil;
use mySociety::Gaze;
use mySociety::Locale;
use mySociety::MaPit;
+use IO::String;
+use RABX;
# Child must have confirmed, id, email, state(!) columns
# If parent/child, child table must also have name and text
@@ -85,9 +87,14 @@ sub email_alerts ($) {
if ($row->{item_text}) {
$data{problem_url} = $url . "/report/" . $row->{id};
$data{data} .= $row->{item_name} . ' : ' if $row->{item_name} && !$row->{item_anonymous};
+ # comment out untill we've populated the geocode field
+ # $data{data} .= _get_address_from_gecode( $row->{geocode} ) if exists $row->{geocode} and $ref =~ /ward|council/;
$data{data} .= $row->{item_text} . "\n\n------\n\n";
} else {
$data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}\n\n";
+ # comment out untill we've populated the geocode field
+ # $data{data} .= _get_address_from_gecode( $row->{geocode} ) if exists $row->{geocode} and $ref =~ /ward|council/;
+ # $data{data} .= "\n\n------\n\n";
}
if (!$data{alert_user_id}) {
%data = (%data, %$row);
@@ -134,7 +141,7 @@ sub email_alerts ($) {
};
my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'";
my %data = ( template => $template, data => '', alert_id => $alert->id, alert_email => $alert->user->email, lang => $alert->lang, cobrand => $alert->cobrand, cobrand_data => $alert->cobrand_data );
- my $q = "select problem.id, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users
+ my $q = "select problem.id, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users
where nearby.problem_id = problem.id
and problem.user_id = users.id
and problem.state in ($states)
@@ -151,6 +158,9 @@ sub email_alerts ($) {
parameter => $row->{id},
} );
$data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}\n\n";
+ # comment out untill we've populated the geocode field
+ # $data{data} .= _get_address_from_gecode( $row->{geocode} ) . "\n\n" if exists $row->{geocode};
+ # $data{data} .= "\n\n------\n\n";
}
_send_aggregated_alert_email(%data) if $data{data};
}
@@ -210,4 +220,21 @@ sub _send_aggregated_alert_email(%) {
}
}
+sub _get_address_from_gecode {
+ my $geocode = shift;
+
+ return '' unless defined $geocode;
+ my $h = new IO::String($geocode);
+ my $data = RABX::wire_rd($h);
+
+ my $address = $data->{resourceSets}[0]{resources}[0]{address};
+ my @address;
+ push @address, $address->{addressLine} if $address->{addressLine} ne 'Street';
+ push @address, $address->{locality};
+ my $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s\n\n"),
+ join( ', ', @address ) );
+
+ return $str;
+}
+
1;