diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-03-05 15:48:31 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-03-05 15:48:31 +0000 |
commit | 9923c8f971657a0843f33dbc085e0aa6baf0d3b2 (patch) | |
tree | a53550bde2aac947b8824fb51f8031ea9e55b8d5 /perllib/FixMyStreet/App/Controller/Reports.pm | |
parent | d0791d911fa970035fe5114d904d07688f11c518 (diff) |
Just one list of problems on council pages.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 815debe14..5d70ae113 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -101,7 +101,6 @@ sub ward : Path : Args(2) { $c->forward( 'load_parent' ); $c->forward( 'check_canonical_url', [ $council ] ); $c->forward( 'load_and_group_problems' ); - $c->forward( 'sort_problems' ); my $council_short = $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} ); $c->stash->{rss_url} = '/rss/reports/' . $council_short; @@ -353,7 +352,7 @@ sub load_and_group_problems : Private { $c->stash->{pager} = $problems->pager; $problems = $problems->cursor; # Raw DB cursor for speed - my ( %fixed, %open, @pins ); + my ( %problems, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'duration', 'age', 'confirmed', 'photo' ); while ( my @problem = $problems->next ) { @@ -363,7 +362,7 @@ sub load_and_group_problems : Private { # Problem was not sent to any council, add to possible councils $problem{councils} = 0; while ($problem{areas} =~ /,($re_councils)(?=,)/g) { - add_row( \%problem, $1, \%fixed, \%open, \@pins ); + add_row( \%problem, $1, \%problems, \@pins ); } } else { # Add to councils it was sent to @@ -372,37 +371,19 @@ sub load_and_group_problems : Private { $problem{councils} = scalar @council; foreach ( @council ) { next if $c->stash->{council} && $_ != $c->stash->{council}->{id}; - add_row( \%problem, $_, \%fixed, \%open, \@pins ); + add_row( \%problem, $_, \%problems, \@pins ); } } } $c->stash( - fixed => \%fixed, - open => \%open, + problems => \%problems, pins => \@pins, ); return 1; } -sub sort_problems : Private { - my ( $self, $c ) = @_; - - my $id = $c->stash->{council}->{id}; - my $fixed = $c->stash->{fixed}; - my $open = $c->stash->{open}; - - foreach (qw/new old/) { - $c->stash->{fixed}{$id}{$_} = [ sort { $a->{duration} <=> $b->{duration} } @{$fixed->{$id}{$_}} ] - if $fixed->{$id}{$_}; - } - foreach (qw/new older unknown/) { - $c->stash->{open}{$id}{$_} = [ sort { $a->{age} <=> $b->{age} } @{$open->{$id}{$_}} ] - if $open->{$id}{$_}; - } -} - sub redirect_index : Private { my ( $self, $c ) = @_; my $url = '/reports'; @@ -420,20 +401,9 @@ sub redirect_area : Private { $c->res->redirect( $c->uri_for($url) ); } -my $fourweeks = 4*7*24*60*60; sub add_row { - my ( $problem, $council, $fixed, $open, $pins ) = @_; - my $duration_str = ( $problem->{duration} > 2 * $fourweeks ) ? 'old' : 'new'; - my $type = ( $problem->{duration} > 2 * $fourweeks ) - ? 'unknown' - : ($problem->{age} > $fourweeks ? 'older' : 'new'); - # Fixed problems are either old or new - push @{$fixed->{$council}{$duration_str}}, $problem if - exists FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}}; - # Open problems are either unknown, older, or new - push @{$open->{$council}{$type}}, $problem if - exists FixMyStreet::DB::Result::Problem->open_states->{$problem->{state}}; - + my ( $problem, $council, $problems, $pins ) = @_; + push @{$problems->{$council}}, $problem; push @$pins, { latitude => $problem->{latitude}, longitude => $problem->{longitude}, |