diff options
author | Steven Day <steve@mysociety.org> | 2015-08-12 17:42:41 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-02 13:34:54 +0100 |
commit | a344b99a0bf37134079afda51c6f963e1163904b (patch) | |
tree | 920bfa86c19113f9a2c99d401da885cea5e9f078 /perllib | |
parent | b002374a885736b7436fc1c3132e50b6a1f8bdf9 (diff) |
Allow cobrands to give extra parameters for pins.
So that you can build functionality to add extra limitations on
to the map pins displayed. Useful for Collideoscope initially
to filter out (or in) reports from the Department of Transport's
Stats19 Data.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 2 |
5 files changed, 15 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index ae7d83f55..bdf381294 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -257,12 +257,16 @@ sub map_features : Private { return if $c->get_param('js'); # JS will request the same (or more) data client side + # Allow the cobrand to add in any additional query parameters + my $extra_params = $c->cobrand->call_hook('display_location_extra_params'); + my ( $on_map, $nearby, $distance ) = FixMyStreet::Map::map_features( $c, %$extra, categories => [ keys %{$c->stash->{filter_category}} ], states => $c->stash->{filter_problem_states}, order => $c->stash->{sort_order}, + extra => $extra_params, ); my @pins; diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index e36085d05..3f79a99f7 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -553,8 +553,10 @@ sub nearby_json : Private { # This is for the list template, this is a list on that page. $c->stash->{page} = 'report'; + my $extra_params = $c->cobrand->call_hook('display_location_extra_params'); + my $nearby = $c->model('DB::Nearby')->nearby( - $c, $dist, [ $p->id ], 5, $p->latitude, $p->longitude, [ $p->category ], undef + $c, $dist, [ $p->id ], 5, $p->latitude, $p->longitude, [ $p->category ], undef, $extra_params ); # Want to treat these as if they were on map $nearby = [ map { $_->problem } @$nearby ]; diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index ab554eb9d..b075e3664 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -10,7 +10,7 @@ sub to_body { } sub nearby { - my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $categories, $states ) = @_; + my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $categories, $states, $extra_params ) = @_; unless ( $states ) { $states = FixMyStreet::DB::Result::Problem->visible_states(); @@ -27,6 +27,9 @@ sub nearby { $rs = $c->cobrand->problems_restriction($rs); + # Add in any optional extra query parameters + $params = { %$params, %$extra_params } if $extra_params; + my $attrs = { prefetch => 'problem', bind => [ $mid_lat, $mid_lon, $dist ], diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index e262cb63e..ef078ed08 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -176,6 +176,9 @@ sub around_map { $rs->non_public_if_possible($q, $c); + # Add in any optional extra query parameters + $q = { %$q, %{$p{extra}} } if $p{extra}; + my $problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->include_comment_counts->page($p{page}); }; diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 91c198913..f5d4c1db6 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -104,7 +104,7 @@ sub map_features { my $limit = 20; my @ids = map { $_->id } @$on_map; $nearby = $c->model('DB::Nearby')->nearby( - $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "categories", "states"} + $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "categories", "states", "extra"} ); } |