diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-04-12 15:13:59 +0100 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-04-12 15:13:59 +0100 |
commit | 7f6e0a5fef9d072135cb08b710e9dc6d06d6cac7 (patch) | |
tree | e825f20f0a8f5ba198458af6adc4fffa4944143b /perllib/FixMyStreet/App/Controller/Around.pm | |
parent | a38d76783ee9a44b9e237a87d086549677d3282e (diff) |
Create Around controller and implement the easy bits
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Around.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm new file mode 100644 index 000000000..8df7b880f --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -0,0 +1,53 @@ +package FixMyStreet::App::Controller::Around; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller'; } + +use FixMyStreet::Map; +use List::MoreUtils qw(any); + +=head1 NAME + +FixMyStreet::App::Controller::Around - Catalyst Controller + +=head1 DESCRIPTION + +Allow the user to search for reports around a particular location. + +=head1 METHODS + +=head2 around + +Find the location search and display nearby reports (for pc or lat,lon). + +For x,y searches convert to lat,lon and 301 redirect to them. + +If no search redirect back to the homepage. + +=cut + +sub around_index : Path : Args(0) { + my ( $self, $c ) = @_; + + # check for x,y requests and redirect them to lat,lon + my $x = $c->req->param('x'); + my $y = $c->req->param('y'); + if ( $x || $y ) { + my ( $lat, $lon ) = FixMyStreet::Map::tile_xy_to_wgs84( $x, $y ); + my $ll_uri = $c->uri_for( '/around', { lat => $lat, lon => $lon } ); + $c->res->redirect( $ll_uri, 301 ); + return; + } + + # if there was no search then redirect to the homepage + if ( !any { $c->req->param($_) } qw(pc lat lon) ) { + return $c->res->redirect( $c->uri_for('/') ); + } + + +} + +__PACKAGE__->meta->make_immutable; + +1; |