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

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

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

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

    # We don't care what the category was, look up the Traffic lights contact
    my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find({
        body_id => $body->id,
        category => 'Traffic lights',
    });
    return unless $contact;

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

1;