diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.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 | 17 |
6 files changed, 31 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 8fed5c3aa..cc6f8387c 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -253,6 +253,7 @@ sub map_features : Private { $c->forward( '/reports/stash_report_filter_status' ); $c->forward( '/reports/stash_report_sort', [ 'created-desc' ]); + $c->stash->{show_old_reports} = $c->get_param('show_old_reports'); return if $c->get_param('js'); # JS will request the same (or more) data client side diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index dc9e2c913..05776a94f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -758,10 +758,13 @@ sub stash_report_sort : Private { $sort =~ /^(updated|created|comments)-(desc|asc)$/; my $order_by = $types{$1} || $1; + # field to use for report age cutoff + $c->stash->{report_age_field} = $order_by eq 'comment_count' ? 'lastupdate' : $order_by; my $dir = $2; $order_by = { -desc => $order_by } if $dir eq 'desc'; $c->stash->{sort_order} = $order_by; + return 1; } diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 816c5e315..836b6af58 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -445,6 +445,10 @@ sub reports_per_page { return FixMyStreet->config('ALL_REPORTS_PER_PAGE') || 100; } +sub report_age { + return '6 months'; +} + =item reports_ordering The order_by clause to use for reports on all reports page diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index b075e3664..3d8f87b9f 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, $extra_params ) = @_; + my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $categories, $states, $extra_params, $report_age ) = @_; unless ( $states ) { $states = FixMyStreet::DB::Result::Problem->visible_states(); @@ -23,6 +23,9 @@ sub nearby { if $ids; $params->{category} = $categories if $categories && @$categories; + $params->{$c->stash->{report_age_field}} = { '>=', \"current_timestamp-'$report_age'::interval" } + if $report_age; + FixMyStreet::DB::ResultSet::Problem->non_public_if_possible($params, $c); $rs = $c->cobrand->problems_restriction($rs); diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 967c90af5..cc28e4c33 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -172,6 +172,9 @@ sub around_map { latitude => { '>=', $p{min_lat}, '<', $p{max_lat} }, longitude => { '>=', $p{min_lon}, '<', $p{max_lon} }, }; + + $q->{$c->stash->{report_age_field}} = { '>=', \"current_timestamp-'$p{report_age}'::interval" } if + $p{report_age}; $q->{category} = $p{categories} if $p{categories} && @{$p{categories}}; $rs->non_public_if_possible($q, $c); diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index f5d4c1db6..8ed0c4b37 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -92,19 +92,34 @@ sub map_features { $p{latitude} = Utils::truncate_coordinate(($p{max_lat} + $p{min_lat} ) / 2); } + my $report_age = $c->stash->{show_old_reports} ? undef : $c->cobrand->report_age; + $p{report_age} = $report_age; + $p{page} = $c->get_param('p') || 1; my $on_map = $c->cobrand->problems_on_map->around_map( $c, %p ); my $pager = $c->stash->{pager} = $on_map->pager; $on_map = [ $on_map->all ]; + if ( $c->{stash}->{show_old_reports} ) { + # if show_old_reports is on then there must be old reports + $c->stash->{num_old_reports} = 1; + } else { + $p{report_age} = undef; + $p{page} = 1; + my $older = $c->cobrand->problems_on_map->around_map( $c, %p ); + $c->stash->{num_old_reports} = $older->pager->total_entries - $pager->total_entries; + } + my $dist = FixMyStreet::Gaze::get_radius_containing_population( $p{latitude}, $p{longitude} ); + # if there are fewer entries than our paging limit on the map then + # also return nearby entries for display my $nearby; if (@$on_map < $pager->entries_per_page && $pager->current_page == 1) { my $limit = 20; my @ids = map { $_->id } @$on_map; $nearby = $c->model('DB::Nearby')->nearby( - $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "categories", "states", "extra"} + $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "categories", "states", "extra"}, $report_age ); } |