aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/SendReport/NI.pm
blob: 0783a385b943f52d5ad70c9e264bb67b7d2b0b9e (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
29
30
31
32
33
34
35
36
37
38
39
40
package FixMyStreet::SendReport::NI;

use Moose;

BEGIN { extends 'FixMyStreet::SendReport::Email'; }

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

    my $all_confirmed = 1;
    foreach my $council ( keys %{ $self->councils } ) {
        my $contact = FixMyStreet::App->model("DB::Contact")->find( {
            deleted => 0,
            area_id => $council,
            category => $row->category
        } );

        my ($email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );

        unless ($confirmed) {
            $all_confirmed = 0;
            $email = 'N/A' unless $email;
        }

        my $name = $self->councils->{$council}->{name};
        if ( $email =~ /^roads.([^@]*)\@drdni/ ) {
            $name = "Roads Service (\u$1)";
            $h->{councils_name} = $name;
            $row->external_body( 'Roads Service' );
        }
        push @{ $self->to }, [ $email, $name ];
        $recips{$email} = 1;
    }

    return () unless $all_confirmed;
    return keys %recips;
}

1;