diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/My.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 34 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 5 |
7 files changed, 63 insertions, 22 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index cd96c3b5d..b4f94bb35 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -176,13 +176,16 @@ sub display_location : Private { # Check the category to filter by, if any, is valid $c->forward('check_and_stash_category'); + $c->forward( '/reports/stash_report_sort', [ 'created-desc' ]); # get the map features my ( $on_map_all, $on_map, $nearby, $distance ) = FixMyStreet::Map::map_features( $c, latitude => $latitude, longitude => $longitude, interval => $interval, categories => $c->stash->{filter_category}, - states => $c->stash->{filter_problem_states} ); + states => $c->stash->{filter_problem_states}, + order => $c->stash->{sort_order}, + ); # copy the found reports to the stash $c->stash->{on_map} = $on_map; @@ -293,13 +296,16 @@ sub ajax : Path('/ajax') { my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; $c->forward( '/reports/stash_report_filter_status' ); + $c->forward( '/reports/stash_report_sort', [ 'created-desc' ]); # extract the data from the map my ( $on_map_all, $on_map_list, $nearby, $dist ) = FixMyStreet::Map::map_features($c, bbox => $bbox, interval => $interval, categories => [ $c->get_param_list('filter_category', 1) ], - states => $c->stash->{filter_problem_states} ); + states => $c->stash->{filter_problem_states}, + order => $c->stash->{sort_order}, + ); # create a list of all the pins my @pins = map { diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index b6f425ead..51f1687ee 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -57,6 +57,7 @@ sub get_problems : Private { my $p_page = $c->get_param('p') || 1; $c->forward( '/reports/stash_report_filter_status' ); + $c->forward('/reports/stash_report_sort', [ 'created-desc' ]); my $pins = []; my $problems = []; @@ -73,9 +74,9 @@ sub get_problems : Private { } my $rs = $c->stash->{problems_rs}->search( $params, { - order_by => { -desc => 'confirmed' }, + order_by => $c->stash->{sort_order}, rows => 50 - } )->page( $p_page ); + } )->include_comment_counts->page( $p_page ); while ( my $problem = $rs->next ) { $c->stash->{has_content}++; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index f05096525..813c2052d 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -365,6 +365,8 @@ sub check_canonical_url : Private { sub load_and_group_problems : Private { my ( $self, $c ) = @_; + $c->forward('stash_report_sort', [ $c->cobrand->reports_ordering ]); + my $page = $c->get_param('p') || 1; # NB: If 't' is specified, it will override 'status'. my $type = $c->get_param('t') || 'all'; @@ -411,10 +413,10 @@ sub load_and_group_problems : Private { $problems = $problems->search( $where, { - order_by => $c->cobrand->reports_ordering, + order_by => $c->stash->{sort_order}, rows => $c->cobrand->reports_per_page, } - )->page( $page ); + )->include_comment_counts->page( $page ); $c->stash->{pager} = $problems->pager; my ( %problems, @pins ); @@ -502,6 +504,27 @@ sub stash_report_filter_status : Private { return 1; } +sub stash_report_sort : Private { + my ( $self, $c, $default ) = @_; + + my %types = ( + updated => 'lastupdate', + created => 'confirmed', + comments => 'comment_count', + ); + + my $sort = $c->get_param('sort') || $default; + $sort = $default unless $sort =~ /^((updated|created)-(desc|asc)|comments-desc)$/; + $sort =~ /^(updated|created|comments)-(desc|asc)$/; + my $order_by = $types{$1} || $1; + my $dir = $2; + $order_by = { -desc => $order_by } if $dir eq 'desc'; + + $c->stash->{sort_key} = $sort; + $c->stash->{sort_order} = $order_by; + return 1; +} + sub add_row { my ( $c, $problem, $body, $problems, $pins ) = @_; push @{$problems->{$body}}, $problem; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index b63999b2f..13d5cb8f1 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -432,7 +432,7 @@ The order_by clause to use for reports on all reports page =cut sub reports_ordering { - return { -desc => 'lastupdate' }; + return 'updated-desc'; } =head2 on_map_list_limit diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 989d6f622..a476b5e9b 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -100,7 +100,7 @@ sub problem_response_days { } sub reports_ordering { - return { -desc => 'confirmed' }; + return 'created-desc'; } sub pin_colour { diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 723a6e7c2..f1ed50721 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -140,27 +140,27 @@ sub _recent { # Problems around a location sub around_map { - my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $categories, $states ) = @_; + my ( $rs, $limit, %p) = @_; my $attr = { - order_by => { -desc => 'created' }, + order_by => $p{order}, }; $attr->{rows} = $limit if $limit; - unless ( $states ) { - $states = FixMyStreet::DB::Result::Problem->visible_states(); + unless ( $p{states} ) { + $p{states} = FixMyStreet::DB::Result::Problem->visible_states(); } my $q = { non_public => 0, - state => [ keys %$states ], - latitude => { '>=', $min_lat, '<', $max_lat }, - longitude => { '>=', $min_lon, '<', $max_lon }, + state => [ keys %{$p{states}} ], + latitude => { '>=', $p{min_lat}, '<', $p{max_lat} }, + longitude => { '>=', $p{min_lon}, '<', $p{max_lon} }, }; - $q->{'current_timestamp - lastupdate'} = { '<', \"'$interval'::interval" } - if $interval; - $q->{category} = $categories if $categories && @$categories; + $q->{'current_timestamp - lastupdate'} = { '<', \"'$p{interval}'::interval" } + if $p{interval}; + $q->{category} = $p{categories} if $p{categories} && @{$p{categories}}; - my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->all }; + my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->include_comment_counts->all }; return \@problems; } @@ -238,4 +238,16 @@ sub send_reports { return FixMyStreet::Script::Reports::send($site_override); } +sub include_comment_counts { + my $rs = shift; + my $order_by = $rs->{attrs}{order_by}; + return $rs unless ref $order_by eq 'HASH' && $order_by->{-desc} eq 'comment_count'; + $rs->search({}, { + '+select' => [ { + "" => \'(select count(*) from comment where problem_id=me.id and state=\'confirmed\')', + -as => 'comment_count' + } ] + }); +} + 1; diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index f7caf51d7..b6b618efb 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -91,10 +91,9 @@ sub map_features { # 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 = @p{"min_lat", "max_lat", "min_lon", "max_lon", "interval"}; - my $on_map_all = $c->cobrand->problems_on_map->around_map( @around_args, undef, $p{categories}, $p{states} ); + my $on_map_all = $c->cobrand->problems_on_map->around_map( undef, %p ); my $on_map_list = $around_limit - ? $c->cobrand->problems_on_map->around_map( @around_args, $around_limit, $p{categories}, $p{states} ) + ? $c->cobrand->problems_on_map->around_map( $around_limit, %p ) : $on_map_all; my $dist = FixMyStreet::Gaze::get_radius_containing_population( $p{latitude}, $p{longitude} ); |