diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 49 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 16 |
3 files changed, 31 insertions, 46 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index f4093ef21..85a6e7c4d 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -372,53 +372,32 @@ sub load_and_group_problems : Private { my $problems = $c->cobrand->problems->search( $where, { - columns => [ - 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', - #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, - #{ age => { extract => "epoch from current_timestamp-confirmed" } }, - { created => { extract => 'epoch from created' } }, - { confirmed => { extract => 'epoch from confirmed' } }, - { whensent => { extract => 'epoch from whensent' } }, - { lastupdate => { extract => 'epoch from lastupdate' } }, - 'photo', 'extra', - ], order_by => { -desc => 'lastupdate' }, rows => $c->cobrand->reports_per_page, } )->page( $page ); $c->stash->{pager} = $problems->pager; - $problems = $problems->cursor; # Raw DB cursor for speed my ( %problems, @pins ); - my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'created', 'confirmed', 'whensent', 'lastupdate', 'photo', 'extra' ); - while ( my @problem = $problems->next ) { - my %problem = zip @cols, @problem; - $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; - if ($problem{extra} && $c->cobrand->moniker eq 'zurich') { # Inflate - utf8::encode($problem{extra}) if utf8::is_utf8($problem{extra}); - $problem{extra} = RABX::unserialise($problem{extra}); - } - $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); + while ( my $problem = $problems->next ) { + $c->log->debug( $problem->cobrand . ', cobrand is ' . $c->cobrand->moniker ); if ( !$c->stash->{body}->id ) { # An external_body entry - add_row( \%problem, 0, \%problems, \@pins ); + add_row( $problem, 0, \%problems, \@pins ); next; } - if ( !$problem{bodies_str} ) { + if ( !$problem->bodies_str ) { # Problem was not sent to any body, add to all possible areas XXX - $problem{bodies} = 0; - while ($problem{areas} =~ /,(\d+)(?=,)/g) { - add_row( \%problem, $1, \%problems, \@pins ); + while ($problem->areas =~ /,(\d+)(?=,)/g) { + add_row( $problem, $1, \%problems, \@pins ); } } else { # Add to bodies it was sent to # XXX Assumes body ID matches "council ID" - (my $bodies = $problem{bodies_str}) =~ s/\|.*$//; - my @bodies = split( /,/, $bodies ); - $problem{bodies} = scalar @bodies; - foreach ( @bodies ) { + my $bodies = $problem->bodies_str_ids; + foreach ( @$bodies ) { next if $_ != $c->stash->{body}->id; - add_row( \%problem, $_, \%problems, \@pins ); + add_row( $problem, $_, \%problems, \@pins ); } } } @@ -452,11 +431,11 @@ sub add_row { my ( $problem, $body, $problems, $pins ) = @_; push @{$problems->{$body}}, $problem; push @$pins, { - latitude => $problem->{latitude}, - longitude => $problem->{longitude}, - colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red', - id => $problem->{id}, - title => $problem->{title}, + latitude => $problem->latitude, + longitude => $problem->longitude, + colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->state} ? 'green' : 'red', + id => $problem->id, + title => $problem->title, }; } diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 42878be37..febeaf3c1 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -18,7 +18,7 @@ __PACKAGE__->config( ENCODING => 'utf8', render_die => 1, expose_methods => [ - 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_epoch', + 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_dt', 'add_links', 'version', ], FILTERS => { @@ -92,20 +92,20 @@ sub display_crosssell_advert { return CrossSell::display_advert( $c, $email, $name, %data ); } -=head2 Utils::prettify_epoch +=head2 Utils::prettify_dt - [% pretty = prettify_epoch( $epoch, $short_bool ) %] + [% pretty = prettify_dt( $dt, $short_bool ) %] -Return a pretty version of the epoch. +Return a pretty version of the DateTime object. $short_bool = 1; # 16:02, 29 Mar 2011 $short_bool = 0; # 16:02, Tuesday 29 March 2011 =cut -sub prettify_epoch { +sub prettify_dt { my ( $self, $c, $epoch, $short_bool ) = @_; - return Utils::prettify_epoch( $epoch, $short_bool ); + return Utils::prettify_dt( $epoch, $short_bool ); } =head2 add_links diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 38326bfc7..ea6a0f231 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -397,6 +397,14 @@ sub confirm { return 1; } +sub bodies_str_ids { + my $self = shift; + return unless $self->bodies_str; + (my $bodies = $self->bodies_str) =~ s/\|.*$//; + my @bodies = split( /,/, $bodies ); + return \@bodies; +} + =head2 bodies Returns an arrayref of bodies to which a report was sent. @@ -406,9 +414,8 @@ Returns an arrayref of bodies to which a report was sent. sub bodies($) { my $self = shift; return {} unless $self->bodies_str; - (my $bodies = $self->bodies_str) =~ s/\|.*$//; - my @bodies = split( /,/, $bodies ); - @bodies = FixMyStreet::App->model('DB::Body')->search({ id => \@bodies })->all; + my $bodies = $self->bodies_str_ids; + my @bodies = FixMyStreet::App->model('DB::Body')->search({ id => $bodies })->all; return { map { $_->id => $_ } @bodies }; } @@ -493,8 +500,7 @@ meta data about the report. sub meta_line { my ( $problem, $c ) = @_; - my $date_time = - Utils::prettify_epoch( $problem->confirmed_local->epoch ); + my $date_time = Utils::prettify_dt( $problem->confirmed_local ); my $meta = ''; # FIXME Should be in cobrand |