|
| 1 | +package FixMyStreet::Cobrand::Enfield; |
| 2 | +use parent 'FixMyStreet::Cobrand::UKCouncils'; |
| 3 | + |
| 4 | +sub council_area_id { 2495 } |
| 5 | +sub council_area { 'Enfield'; } |
| 6 | +sub council_name { return 'Enfield Council'; } |
| 7 | +sub council_url { return 'enfield'; } |
| 8 | +sub base_url { return FixMyStreet->config('BASE_URL'); } |
| 9 | + |
| 10 | +sub open311_config { |
| 11 | + my ($self, $row, $h, $params, $contact) = @_; |
| 12 | + |
| 13 | + $params->{multi_photos} = 1; |
| 14 | + $params->{upload_files} = 1; |
| 15 | +} |
| 16 | + |
| 17 | +sub open311_update_missing_data { |
| 18 | + my ($self, $row, $h, $contact) = @_; |
| 19 | + |
| 20 | + if ($row->get_extra_field_value('pac')) { |
| 21 | + if (my $result = $self->_lookup_os('uprn', $row)) { |
| 22 | + if (my $uprn = $result->{LPI}{UPRN}) { |
| 23 | + $row->update_extra_field({ name => 'uprn', description => 'UPRN', value => $uprn }); |
| 24 | + } |
| 25 | + } |
| 26 | + } else { |
| 27 | + if (my $result = $self->_lookup_os('usrn', $row)) { |
| 28 | + if (my $usrn = $result->{LPI}{USRN}) { |
| 29 | + $row->update_extra_field({ name => 'usrn', description => 'USRN', value => $usrn }); |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +sub open311_extra_data_include { |
| 36 | + my ($self, $row, $h) = @_; |
| 37 | + |
| 38 | + my $open311_only = [ |
| 39 | + { name => 'report_url', |
| 40 | + value => $h->{url} }, |
| 41 | + { name => 'title', |
| 42 | + value => $row->title }, |
| 43 | + { name => 'description', |
| 44 | + value => $row->detail }, |
| 45 | + ]; |
| 46 | + |
| 47 | + return $open311_only; |
| 48 | +} |
| 49 | + |
| 50 | +my $BASE = 'https://api.os.uk/search/places/v1/nearest?dataset=LPI&srs=WGS84&radius=1000'; |
| 51 | +my $CODES = 'fq=CLASSIFICATION_CODE:LP01+CLASSIFICATION_CODE:LP03+CLASSIFICATION_CODE:LL+CLASSIFICATION_CODE:CC06'; |
| 52 | + |
| 53 | +sub _lookup_os { |
| 54 | + my ($self, $type, $row) = @_; |
| 55 | + if (my $key = $self->feature('os_places_api_key')) { |
| 56 | + my $url = "$BASE&key=$key&point=" . $row->latitude . ',' . $row->longitude; |
| 57 | + if ($type eq 'uprn') { |
| 58 | + $url .= "&$CODES"; |
| 59 | + } |
| 60 | + my $j = FixMyStreet::Geocode::cache('osplaces', $url); |
| 61 | + return $j ? $j->{results}[0] : undef; |
| 62 | + } |
| 63 | + return undef; |
| 64 | +} |
| 65 | + |
| 66 | +sub open311_post_send { |
| 67 | + my ($self, $row, $h, $sender) = @_; |
| 68 | + |
| 69 | + # Check Open311 was successful |
| 70 | + return unless $row->external_id; |
| 71 | + return if $row->get_extra_metadata('extra_email_sent'); |
| 72 | + |
| 73 | + my $email = $self->feature('open311_email') || return; |
| 74 | + |
| 75 | + $row->push_extra_fields({ name => 'fixmystreet_id', description => 'FMS reference', value => $row->id }); |
| 76 | + |
| 77 | + my $sender = FixMyStreet::SendReport::Email->new( |
| 78 | + use_verp => 0, |
| 79 | + use_replyto => 1, |
| 80 | + to => [ [ $email, 'FixMyStreet' ] ], |
| 81 | + ); |
| 82 | + |
| 83 | + $sender->send($row, $h); |
| 84 | + if ($sender->success) { |
| 85 | + $row->set_extra_metadata(extra_email_sent => 1); |
| 86 | + } |
| 87 | + |
| 88 | + $row->remove_extra_field('fixmystreet_id'); |
| 89 | +} |
| 90 | + |
| 91 | +1; |
0 commit comments