aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/SendReport/Email/Highways.pm
blob: 3ace07b6a53553bb2a194d762367693fa88aeb9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package FixMyStreet::SendReport::Email::Highways;

use Moo;
extends 'FixMyStreet::SendReport::Email';

sub build_recipient_list {
    my ( $self, $row, $h ) = @_;

    return unless @{$self->bodies} == 1;
    my $body = $self->bodies->[0];

    my $contact = $self->fetch_category($body, $row) or return;
    my $email = $contact->email;
    my $area_name = $row->get_extra_field_value('area_name') || '';

    # config is read-only, so must step through one-by-one to prevent
    # vivification
    my $area_email = FixMyStreet->config('COBRAND_FEATURES') || {};
    $area_email = $area_email->{open311_email} || {};
    $area_email = $area_email->{highwaysengland} || {};
    $area_email = $area_email->{$area_name};
    $email = $area_email if $area_email;

    @{$self->to} = map { [ $_, $body->name ] } split /,/, $email;
    return 1;
}

1;