aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/SendReport/Email.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/SendReport/Email.pm')
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm53
1 files changed, 37 insertions, 16 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index b69436dd7..d71700020 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -11,30 +11,46 @@ sub build_recipient_list {
my %recips;
my $all_confirmed = 1;
- foreach my $council ( keys %{ $self->councils } ) {
+ foreach my $body ( @{ $self->bodies } ) {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $council,
+ body_id => $body->id,
category => $row->category
} );
- my ($council_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
+ my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
- $council_email = essex_contact($row->latitude, $row->longitude) if $council == 2225;
- $council_email = oxfordshire_contact($row->latitude, $row->longitude) if $council == 2237 && $council_email eq 'SPECIAL';
+ $body_email = essex_contact($row->latitude, $row->longitude) if $body->areas->{2225};
+ $body_email = oxfordshire_contact($row->latitude, $row->longitude) if $body->areas->{2237} && $body_email eq 'SPECIAL';
unless ($confirmed) {
$all_confirmed = 0;
- $note = 'Council ' . $row->council . ' deleted'
+ $note = 'Body ' . $row->bodies_str . ' deleted'
unless $note;
- $council_email = 'N/A' unless $council_email;
- $self->unconfirmed_counts->{$council_email}{$row->category}++;
- $self->unconfirmed_notes->{$council_email}{$row->category} = $note;
+ $body_email = 'N/A' unless $body_email;
+ $self->unconfirmed_counts->{$body_email}{$row->category}++;
+ $self->unconfirmed_notes->{$body_email}{$row->category} = $note;
}
- push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{info}->{name} ];
- $recips{$council_email} = 1;
+ my $body_name = $body->name;
+ # see something uses council areas but doesn't send to councils so just use a
+ # generic name here to minimise confusion
+ if ( $row->cobrand eq 'seesomething' ) {
+ $body_name = 'See Something, Say Something';
+ }
+
+ my @emails;
+ # allow multiple emails per contact
+ if ( $body_email =~ /,/ ) {
+ @emails = split(/,/, $body_email);
+ } else {
+ @emails = ( $body_email );
+ }
+ for my $email ( @emails ) {
+ push @{ $self->to }, [ $email, $body_name ];
+ $recips{$email} = 1;
+ }
}
return () unless $all_confirmed;
@@ -45,7 +61,7 @@ sub get_template {
my ( $self, $row ) = @_;
my $template = 'submit.txt';
- $template = 'submit-brent.txt' if $row->council eq 2488 || $row->council eq 2237;
+ $template = 'submit-brent.txt' if $row->bodies_str eq 2488 || $row->bodies_str eq 2237;
my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $row->lang, $template )->stringify;
$template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify
unless -e $template_path;
@@ -55,15 +71,20 @@ sub get_template {
return $template;
}
+sub send_from {
+ my ( $self, $row ) = @_;
+ return [ $row->user->email, $row->name ];
+}
+
sub send {
my $self = shift;
my ( $row, $h ) = @_;
my @recips = $self->build_recipient_list( $row, $h );
- # on a staging server send emails to ourselves rather than the councils
- if (mySociety::Config::get('STAGING_SITE') && !FixMyStreet->test_mode) {
- @recips = ( mySociety::Config::get('CONTACT_EMAIL') );
+ # on a staging server send emails to ourselves rather than the bodies
+ if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING') && !FixMyStreet->test_mode) {
+ @recips = ( $row->user->email );
}
unless ( @recips ) {
@@ -77,7 +98,7 @@ sub send {
_template_ => $self->get_template( $row ),
_parameters_ => $h,
To => $self->to,
- From => [ $row->user->email, $row->name ],
+ From => $self->send_from( $row ),
},
mySociety::Config::get('CONTACT_EMAIL'),
\@recips,