diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 4 |
3 files changed, 38 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 82a7a9e76..c4feca8b6 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -38,6 +38,11 @@ sub index : Path : Args(0) { # Check if we have a partial report my $partial_report = $c->forward('load_partial'); + # Check if the user is searching for a report by ID + if ( $c->get_param('pc') && $c->get_param('pc') =~ $c->cobrand->lookup_by_ref_regex ) { + $c->go('lookup_by_ref', [ $1 ]); + } + # Try to create a location for whatever we have my $ret = $c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc'); @@ -385,6 +390,24 @@ sub _geocode : Private { } +sub lookup_by_ref : Private { + my ( $self, $c, $ref ) = @_; + + my $problems = $c->cobrand->problems->search([ + id => $ref, + external_id => $ref + ]); + + if ( $problems->count == 0) { + $c->detach( '/page_error_404_not_found', [] ); + } elsif ( $problems->count == 1 ) { + $c->res->redirect( $c->uri_for( '/report', $problems->first->id ) ); + } else { + $c->stash->{ref} = $ref; + $c->stash->{matching_reports} = [ $problems->all ]; + } +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 043d0b8e6..ee110a18b 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1135,4 +1135,15 @@ sub contact_details_data { return () } +=head2 lookup_by_ref_regex + +Returns a regex to match postcode form input against to determine if a lookup +by id should be done. + +=cut + +sub lookup_by_ref_regex { + return qr/^\s*ref:\s*(\d+)\s*$/; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index e60b673b4..206f4bb1e 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -392,5 +392,9 @@ sub link_to_council_cobrand { } } +sub lookup_by_ref_regex { + return qr/^\s*(\d+)\s*$/; +} + 1; |