diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Westminster.pm | 30 |
2 files changed, 26 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index c245ef1c6..b59c8990b 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -273,10 +273,9 @@ see Buckinghamshire or Lincolnshire for an example. sub lookup_site_code { my $self = shift; my $row = shift; - my $buffer = shift; + my $field = shift; - my $cfg = $self->lookup_site_code_config; - $cfg->{buffer} = $buffer if $buffer; + my $cfg = $self->lookup_site_code_config($field); my ($x, $y) = $row->local_coords; my $features = $self->_fetch_features($cfg, $x, $y); diff --git a/perllib/FixMyStreet/Cobrand/Westminster.pm b/perllib/FixMyStreet/Cobrand/Westminster.pm index 76788d031..3d99e59c4 100644 --- a/perllib/FixMyStreet/Cobrand/Westminster.pm +++ b/perllib/FixMyStreet/Cobrand/Westminster.pm @@ -90,24 +90,42 @@ sub open311_config { # display the road layer. Instead we'll look up the closest asset from the # asset service at the point we're sending the report over Open311. if (!$row->get_extra_field_value('USRN')) { - if (my $ref = $self->lookup_site_code($row)) { + if (my $ref = $self->lookup_site_code($row, 'USRN')) { push @$extra, { name => 'USRN', value => $ref }; } } + # Some categories require a UPRN to be set, so if the field is present + # but empty then look it up. + my $fields = $row->get_extra_fields; + my ($uprn_field) = grep { $_->{name} eq 'UPRN' } @$fields; + if ( $uprn_field && !$uprn_field->{value} ) { + if (my $ref = $self->lookup_site_code($row, 'UPRN')) { + push @$extra, { name => 'UPRN', value => $ref }; + } + } + $row->set_extra_fields(@$extra); } sub lookup_site_code_config { + my ( $self, $field ) = @_; # uncoverable subroutine # uncoverable statement - { + my $layer = $field eq 'USRN' ? '40' : '25'; # 25 is UPRN + + my %cfg = ( buffer => 1000, # metres proxy_url => "https://tilma.staging.mysociety.org/resource-proxy/proxy.php", - url => "https://westminster.assets/40/query", - property => "USRN", - accept_feature => sub { 1 } - } + url => "https://westminster.assets/$layer/query", + property => $field, + accept_feature => sub { 1 }, + + # UPRNs are Point geometries, so make sure they're allowed by + # _nearest_feature. + ( $field eq 'UPRN' ) ? (accept_types => { Point => 1 }) : (), + ); + return \%cfg; } sub _fetch_features_url { |