diff options
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Zurich.pm | 53 |
2 files changed, 59 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index b7c15a643..2a580c0d5 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -55,6 +55,11 @@ 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 ) = @_; @@ -77,7 +82,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, diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm new file mode 100644 index 000000000..7bf6fe1a3 --- /dev/null +++ b/perllib/FixMyStreet/SendReport/Zurich.pm @@ -0,0 +1,53 @@ +package FixMyStreet::SendReport::Zurich; + +use Moose; + +BEGIN { extends 'FixMyStreet::SendReport::Email'; } + +sub build_recipient_list { + my ( $self, $row, $h ) = @_; + + # Only one body ever, most of the time with an email endpoint + my $body = @{ $self->bodies }[0]; + my $body_email = $body->endpoint; + + my @bodies = $body->bodies; + if ($body->parent && @bodies) { + # Division, might have an individual contact email address + my $contact = FixMyStreet::App->model("DB::Contact")->find( { + body_id => $body->id, + category => $row->category + } ); + $body_email = $contact->email if $contact->email; + } + + push @{ $self->to }, [ $body_email, $body->name ]; + return $body_email; +} + +sub get_template { + my ( $self, $row ) = @_; + + my $template; + if ( $row->state eq 'unconfirmed' || $row->state eq 'confirmed' ) { + $template = 'submit.txt'; + } elsif ( $row->state eq 'in progress' ) { + $template = 'submit-in-progress.txt'; + } elsif ( $row->state eq 'planned' ) { + $template = 'submit-feedback-pending.txt'; + } elsif ( $row->state eq 'closed' ) { + $template = 'submit-external.txt'; + } + + my $template_path = FixMyStreet->path_to( "templates", "email", "zurich", $template )->stringify; + $template = Utils::read_file( $template_path ); + return $template; +} + +# Zurich emails come from the site itself +sub send_from { + my ( $self, $row ) = @_; + return [ FixMyStreet->config('CONTACT_EMAIL'), FixMyStreet->config('CONTACT_NAME') ]; +} + +1; |