diff options
author | Struan Donald <struan@exo.org.uk> | 2012-02-27 13:07:09 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-02-27 13:07:09 +0000 |
commit | 5c81b97ba891837b45fe1ec7b43566543918eeef (patch) | |
tree | bfd5fd46593c7e5fe046a1b30f1ff6f12e46f03b /perllib/FixMyStreet/SendReport | |
parent | 2274cabb4308ad5bf4ba2a50f97d4a1e810292fb (diff) |
reduce duplicated code
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 84 |
2 files changed, 2 insertions, 87 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 94cd94767..ab9d7edcc 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -2,7 +2,6 @@ package FixMyStreet::SendReport::Email; use Moose; use namespace::autoclean; -use Data::Printer; BEGIN { extends 'FixMyStreet::SendReport'; } @@ -64,7 +63,7 @@ sub build_recipient_list { sub send { my $self = shift; - my ( $row, $h, $to, $template, $recips, $nomail ) = @_; + my ( $row, $h, $to, $template, $recips, $nomail, $areas_info ) = @_; my @recips; @@ -72,7 +71,7 @@ sub send { if (mySociety::Config::get('STAGING_SITE')) { @recips = ( mySociety::Config::get('CONTACT_EMAIL') ); } else { - @recips = $self->build_recipient_list( $row ); + @recips = $self->build_recipient_list( $row, $areas_info ); } return unless @recips; diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index d7ff81193..9453b4ca5 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -2,31 +2,9 @@ package FixMyStreet::SendReport::EmptyHomes; use Moose; use namespace::autoclean; -use Data::Printer; BEGIN { extends 'FixMyStreet::SendReport::Email'; } -has 'councils' => (is => 'rw', isa => 'HashRef', default => sub { {} } ); -has 'to' => (is => 'rw', isa => 'ArrayRef', default => sub { [] } ); - -my %councils = (); -my @to; - -sub reset { - my $self = shift; - - $self->councils( {} ); - $self->to( [] ); -} - -sub add_council { - my $self = shift; - my $council = shift; - my $name = shift; - - $self->councils->{ $council } = $name; -} - sub build_recipient_list { my $self = shift; my $row = shift; @@ -70,66 +48,4 @@ sub build_recipient_list { return keys %recips; } -sub send { - my $self = shift; - my ( $row, $h, $to, $template, $recips, $nomail, $areas_info ) = @_; - - my @recips; - - # on a staging server send emails to ourselves rather than the councils - if (mySociety::Config::get('STAGING_SITE')) { - @recips = ( mySociety::Config::get('CONTACT_EMAIL') ); - } else { - @recips = $self->build_recipient_list( $row, $areas_info ); - } - - - return unless @recips; - - my $result = FixMyStreet::App->send_email_cron( - { - _template_ => $template, - _parameters_ => $h, - To => $self->to, - From => [ $row->user->email, $row->name ], - }, - mySociety::Config::get('CONTACT_EMAIL'), - \@recips, - $nomail - ); - - return $result; -} - -# Essex has different contact addresses depending upon the district -# Might be easier if we start storing in the db all areas covered by a point -# Will do for now :) -sub essex_contact { - my $district = _get_district_for_contact(@_); - my $email; - $email = 'eastarea' if $district == 2315 || $district == 2312; - $email = 'midarea' if $district == 2317 || $district == 2314 || $district == 2316; - $email = 'southarea' if $district == 2319 || $district == 2320 || $district == 2310; - $email = 'westarea' if $district == 2309 || $district == 2311 || $district == 2318 || $district == 2313; - die "Returned district $district which is not in Essex!" unless $email; - return "highways.$email\@essexcc.gov.uk"; -} - -# Oxfordshire has different contact addresses depending upon the district -sub oxfordshire_contact { - my $district = _get_district_for_contact(@_); - my $email; - $email = 'northernarea' if $district == 2419 || $district == 2420 || $district == 2421; - $email = 'southernarea' if $district == 2417 || $district == 2418; - die "Returned district $district which is not in Oxfordshire!" unless $email; - return "$email\@oxfordshire.gov.uk"; -} - -sub _get_district_for_contact { - my ( $lat, $lon ) = @_; - my $district = - mySociety::MaPit::call( 'point', "4326/$lon,$lat", type => 'DIS' ); - ($district) = keys %$district; - return $district; -} 1; |