diff options
author | Steven Day <steve@mysociety.org> | 2015-06-29 11:48:36 +0100 |
---|---|---|
committer | Steven Day <steve@mysociety.org> | 2015-06-29 12:43:02 +0100 |
commit | cc42066bf7867c454113e4ce25db9bd6df4e4491 (patch) | |
tree | 56aedc3ec7927b43a71c047ab6a5d3c021259d02 /perllib | |
parent | 4136e91ba45d075b316ac187cc46148a3d14637a (diff) |
Populate category filter with all available categories
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index dbba93df2..341e26cca 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -185,7 +185,7 @@ sub display_location : Private { # get the map features my ( $on_map_all, $on_map, $around_map, $distance ) = FixMyStreet::Map::map_features( $c, $latitude, $longitude, - $interval, $c->stash->{category}, $states ); + $interval, $c->stash->{filter_category}, $states ); # copy the found reports to the stash $c->stash->{on_map} = $on_map; @@ -249,15 +249,29 @@ Puts all the valid categories in filter_categories on the stash. sub check_and_stash_category : Private { my ( $self, $c ) = @_; + my $all_areas = $c->stash->{all_areas}; + my @bodies = $c->model('DB::Body')->search( + { 'body_areas.area_id' => [ keys %$all_areas ], deleted => 0 }, + { join => 'body_areas' } + )->all; + my %bodies = map { $_->id => $_ } @bodies; + + my @contacts = $c->model('DB::Contact')->not_deleted->search( + { + body_id => [ keys %bodies ], + }, + { + columns => [ 'category' ], + order_by => [ 'category' ], + distinct => 1 + } + )->all; + my @categories = map { $_->category } @contacts; + $c->stash->{filter_categories} = \@categories; + + my $category = $c->req->param('category'); if ( $category ) { - my $all_areas = $c->stash->{all_areas}; - my @bodies = $c->model('DB::Body')->search( - { 'body_areas.area_id' => [ keys %$all_areas ], deleted => 0 }, - { join => 'body_areas' } - )->all; - my %bodies = map { $_->id => $_ } @bodies; - my $count = $c->model('DB::Contact')->not_deleted->search( { body_id => [ keys %bodies ], @@ -265,7 +279,7 @@ sub check_and_stash_category : Private { } )->count; if ( $count ) { - $c->stash->{category} = $category; + $c->stash->{filter_category} = $category; } } } |