diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 92 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 98 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Questionnaire.pm | 2 |
4 files changed, 100 insertions, 94 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index fd9c1f1e7..8fd94dfba 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -77,40 +77,7 @@ sub load_problem_or_display_error : Private { my $problem # = $id =~ m{\D} # is id non-numeric? ? undef # ...don't even search - : $c->model('DB::Problem')->find( - { id => $id }, - { - select => [ - 'id', - 'latitude', - 'longitude', - 'council', - 'category', - 'title', 'detail', 'photo', - 'used_map', - 'name', - 'anonymous', - 'state', - 'service', - 'cobrand', - 'cobrand_data', - 'external_body', - { - extract => 'epoch from confirmed', - -as => 'time', - }, - { - extract => 'epoch from whensent-confirmed', - -as => 'whensent' - }, - { - extract => 'epoch from ms_current_timestamp()-lastupdate', - -as => 'duration' - } - - ] - } - ); + : $c->model('DB::Problem')->find( { id => $id } ); # check that the problem is suitable to show. if ( !$problem || $problem->state eq 'unconfirmed' ) { @@ -189,7 +156,6 @@ sub format_problem_for_display : Private { } $c->forward('generate_map_tags'); - $c->forward('generate_problem_meta'); return 1; } @@ -226,62 +192,6 @@ sub generate_map_tags : Private { return 1; } -sub generate_problem_meta : Private { - my ( $self, $c ) = @_; - - my $problem = $c->stash->{problem}; - my $date_time = - Page::prettify_epoch( $c->req, $problem->get_column('time') ); - my $meta = ''; - if ( $problem->anonymous ) { - if ( $problem->service - and $problem->category && $problem->category ne _('Other') ) - { - $meta = - sprintf( _('Reported by %s in the %s category anonymously at %s'), - $problem->service, $problem->category, $date_time ); - } - elsif ( $problem->service ) { - $meta = sprintf( _('Reported by %s anonymously at %s'), - $problem->service, $date_time ); - } - elsif ( $problem->category and $problem->category ne _('Other') ) { - $meta = sprintf( _('Reported in the %s category anonymously at %s'), - $problem->category, $date_time ); - } - else { - $meta = sprintf( _('Reported anonymously at %s'), $date_time ); - } - } - else { - if ( $problem->service - and $problem->category && $problem->category ne _('Other') ) - { - $meta = sprintf( - _('Reported by %s in the %s category by %s at %s'), - $problem->service, $problem->category, - $problem->name, $date_time - ); - } - elsif ( $problem->service ) { - $meta = sprintf( _('Reported by %s by %s at %s'), - $problem->service, $problem->name, $date_time ); - } - elsif ( $problem->category and $problem->category ne _('Other') ) { - $meta = sprintf( _('Reported in the %s category by %s at %s'), - $problem->category, $problem->name, $date_time ); - } - else { - $meta = - sprintf( _('Reported by %s at %s'), $problem->name, $date_time ); - } - } - - $c->stash->{meta} = $meta; - - return 1; -} - __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 552fba5db..839ad38f7 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -783,7 +783,7 @@ sub generate_problem_banner { my ( $self, $problem ) = @_; my $banner = {}; - if ($problem->state eq 'confirmed' && $problem->get_column('duration') > 8*7*24*60*60) { + if ($problem->state eq 'confirmed' && time() - $problem->lastupdate->epoch > 8*7*24*60*60) { $banner->{id} = 'unknown'; $banner->{text} = _('This problem is old and of unknown status.'); } diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 0dc673f23..cdfe5a390 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -8,7 +8,7 @@ use warnings; use base 'DBIx::Class::Core'; -__PACKAGE__->load_components("FilterColumn"); +__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime"); __PACKAGE__->table("problem"); __PACKAGE__->add_columns( "id", @@ -251,4 +251,100 @@ sub get_photo_params { return $photo; } +=head2 meta_line + +Returns a string to be used on a problem report page, describing some of the +meta data about the report. + +=cut + +sub meta_line { + my ( $problem, $c ) = @_; + + my $date_time = + Page::prettify_epoch( $c->req, $problem->confirmed->epoch ); + my $meta = ''; + + # FIXME Should be in cobrand + if ($c->cobrand->moniker eq 'emptyhomes') { + + my $category = _($problem->category); + utf8::decode($category); + if ($problem->anonymous) { + $meta = sprintf(_('%s, reported anonymously at %s'), $category, $date_time); + } else { + $meta = sprintf(_('%s, reported by %s at %s'), $category, $problem->name, $date_time); + } + + } else { + + if ( $problem->anonymous ) { + if ( $problem->service + and $problem->category && $problem->category ne _('Other') ) + { + $meta = + sprintf( _('Reported by %s in the %s category anonymously at %s'), + $problem->service, $problem->category, $date_time ); + } + elsif ( $problem->service ) { + $meta = sprintf( _('Reported by %s anonymously at %s'), + $problem->service, $date_time ); + } + elsif ( $problem->category and $problem->category ne _('Other') ) { + $meta = sprintf( _('Reported in the %s category anonymously at %s'), + $problem->category, $date_time ); + } + else { + $meta = sprintf( _('Reported anonymously at %s'), $date_time ); + } + } + else { + if ( $problem->service + and $problem->category && $problem->category ne _('Other') ) + { + $meta = sprintf( + _('Reported by %s in the %s category by %s at %s'), + $problem->service, $problem->category, + $problem->name, $date_time + ); + } + elsif ( $problem->service ) { + $meta = sprintf( _('Reported by %s by %s at %s'), + $problem->service, $problem->name, $date_time ); + } + elsif ( $problem->category and $problem->category ne _('Other') ) { + $meta = sprintf( _('Reported in the %s category by %s at %s'), + $problem->category, $problem->name, $date_time ); + } + else { + $meta = + sprintf( _('Reported by %s at %s'), $problem->name, $date_time ); + } + } + + } + + $meta .= $c->cobrand->extra_problem_meta_text($problem); + $meta .= '; ' . _('the map was not used so pin location may be inaccurate') + unless $problem->used_map; + + return $meta; +} + +sub duration_string { + my $problem = shift; + my $body; + if ($problem->external_body) { + $body = $problem->external_body; + } else { + (my $council = $problem->council) =~ s/\|.*//g; + my @councils = split /,/, $council; + my $areas_info = mySociety::MaPit::call('areas', \@councils); + $body = join(' and ', map { $areas_info->{$_}->{name} } @councils); + } + return sprintf(_('Sent to %s %s later'), $body, + Page::prettify_duration($problem->whensent->epoch - $problem->confirmed->epoch, 'minute') + ); +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index db569e838..e01fc15e7 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -8,7 +8,7 @@ use warnings; use base 'DBIx::Class::Core'; -__PACKAGE__->load_components("FilterColumn"); +__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime"); __PACKAGE__->table("questionnaire"); __PACKAGE__->add_columns( "id", |