diff options
author | Dave Arter <davea@mysociety.org> | 2015-02-27 12:51:29 +0000 |
---|---|---|
committer | Steven Day <steve@mysociety.org> | 2015-06-29 12:43:00 +0100 |
commit | 09f94956ecd20a7aa861d0f7254189fd9373b813 (patch) | |
tree | 5e6077d201184446fa7676d8e5651e929a2827bb /perllib | |
parent | 8f3d63ae2c35d27b1ff8fe875b9fb6affadb0b57 (diff) |
Add category filtering support to /ajax via 'category' GET param
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 19 |
3 files changed, 14 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index 91c44d5f4..06aca26db 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -5,7 +5,7 @@ use strict; use warnings; sub nearby { - my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval ) = @_; + my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $category ) = @_; my $params = { non_public => 0, @@ -19,6 +19,7 @@ sub nearby { %{ $c->cobrand->problems_clause }, %$params } if $c->cobrand->problems_clause; + $params->{category} = $category if $category; my $attrs = { prefetch => 'problem', diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 7a50a3146..affc6b177 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -131,7 +131,7 @@ sub _recent { # Problems around a location sub around_map { - my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit ) = @_; + my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $category ) = @_; my $attr = { order_by => { -desc => 'created' }, }; @@ -145,6 +145,7 @@ sub around_map { }; $q->{'current_timestamp - lastupdate'} = { '<', \"'$interval'::interval" } if $interval; + $q->{category} = $category if $category; my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->all }; return \@problems; diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 7d490fde3..2bc37ad0a 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -55,7 +55,7 @@ sub display_map { } sub map_features { - my ( $c, $lat, $lon, $interval ) = @_; + my ( $c, $lat, $lon, $interval, $category ) = @_; # TODO - be smarter about calculating the surrounding square # use deltas that are roughly 500m in the UK - so we get a 1 sq km search box @@ -65,12 +65,12 @@ sub map_features { $c, $lat, $lon, $lon - $lon_delta, $lat - $lat_delta, $lon + $lon_delta, $lat + $lat_delta, - $interval + $interval, $category ); } sub map_features_bounds { - my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_; + my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category ) = @_; my $lat = ( $max_lat + $min_lat ) / 2; my $lon = ( $max_lon + $min_lon ) / 2; @@ -78,20 +78,20 @@ sub map_features_bounds { $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, - $interval + $interval, $category ); } sub _map_features { - my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_; + my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category ) = @_; # list of problems around map can be limited, but should show all pins my $around_limit = $c->cobrand->on_map_list_limit || undef; my @around_args = ( $min_lat, $max_lat, $min_lon, $max_lon, $interval ); - my $around_map = $c->cobrand->problems->around_map( @around_args, undef ); + my $around_map = $c->cobrand->problems->around_map( @around_args, undef, $category ); my $around_map_list = $around_limit - ? $c->cobrand->problems->around_map( @around_args, $around_limit ) + ? $c->cobrand->problems->around_map( @around_args, $around_limit, $category ) : $around_map; my $dist; @@ -105,7 +105,7 @@ sub _map_features { my $limit = 20; my @ids = map { $_->id } @$around_map_list; my $nearby = $c->model('DB::Nearby')->nearby( - $c, $dist, \@ids, $limit, $lat, $lon, $interval + $c, $dist, \@ids, $limit, $lat, $lon, $interval, $category ); return ( $around_map, $around_map_list, $nearby, $dist ); @@ -116,9 +116,10 @@ sub map_pins { my $bbox = $c->req->param('bbox'); my ( $min_lon, $min_lat, $max_lon, $max_lat ) = split /,/, $bbox; + my $category = $c->req->param('category'); my ( $around_map, $around_map_list, $nearby, $dist ) = - FixMyStreet::Map::map_features_bounds( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval ); + FixMyStreet::Map::map_features_bounds( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category ); # create a list of all the pins my @pins = map { |